2023-06-02 18:36:12

by Ben Hutchings

[permalink] [raw]
Subject: [PATCH net] lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release()

irq_cpu_rmap_release() calls cpu_rmap_put(), which may free the rmap.
So we need to clear the pointer to our glue structure in rmap before
doing that, not after.

Fixes: 4e0473f1060a ("lib: cpu_rmap: Avoid use after free on rmap->obj ...")
Signed-off-by: Ben Hutchings <[email protected]>
---
I noticed this issue when reviewing stable changes. I haven't tested
the change.

Ben.

lib/cpu_rmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c
index 73c1636b927b..4c348670da31 100644
--- a/lib/cpu_rmap.c
+++ b/lib/cpu_rmap.c
@@ -280,8 +280,8 @@ static void irq_cpu_rmap_release(struct kref *ref)
struct irq_glue *glue =
container_of(ref, struct irq_glue, notify.kref);

- cpu_rmap_put(glue->rmap);
glue->rmap->obj[glue->index] = NULL;
+ cpu_rmap_put(glue->rmap);
kfree(glue);
}


Attachments:
(No filename) (877.00 B)
signature.asc (849.00 B)
Download all attachments

2023-06-06 09:06:11

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH net] lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release()

On Fri, Jun 02, 2023 at 08:28:15PM +0200, Ben Hutchings wrote:
> irq_cpu_rmap_release() calls cpu_rmap_put(), which may free the rmap.
> So we need to clear the pointer to our glue structure in rmap before
> doing that, not after.
>
> Fixes: 4e0473f1060a ("lib: cpu_rmap: Avoid use after free on rmap->obj ...")
> Signed-off-by: Ben Hutchings <[email protected]>

Reviewed-by: Simon Horman <[email protected]>



2023-06-06 11:13:58

by Paolo Abeni

[permalink] [raw]
Subject: Re: [PATCH net] lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release()

Hi,

On Fri, 2023-06-02 at 20:28 +0200, Ben Hutchings wrote:
> irq_cpu_rmap_release() calls cpu_rmap_put(), which may free the rmap.
> So we need to clear the pointer to our glue structure in rmap before
> doing that, not after.
>
> Fixes: 4e0473f1060a ("lib: cpu_rmap: Avoid use after free on rmap->obj ...")
> Signed-off-by: Ben Hutchings <[email protected]>

The patch LGTM, but please include the full blamed commit title into
the fixes tag. A new version will be needed.

Also add Jacob and Saeed to the cc-list

Thanks,

Paolo


2023-06-08 04:59:14

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net] lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release()

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

On Fri, 2 Jun 2023 20:28:15 +0200 you wrote:
> irq_cpu_rmap_release() calls cpu_rmap_put(), which may free the rmap.
> So we need to clear the pointer to our glue structure in rmap before
> doing that, not after.
>
> Fixes: 4e0473f1060a ("lib: cpu_rmap: Avoid use after free on rmap->obj ...")
> Signed-off-by: Ben Hutchings <[email protected]>
>
> [...]

Here is the summary with links:
- [net] lib: cpu_rmap: Fix potential use-after-free in irq_cpu_rmap_release()
https://git.kernel.org/netdev/net/c/7c5d4801ecf0

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html