2022-08-10 08:06:35

by Jialiang Wang

[permalink] [raw]
Subject: [PATCH v3] nfp: fix use-after-free in area_cache_get()

area_cache_get() is used to distribute cache->area and set cache->id,
and if cache->id is not 0 and cache->area->kref refcount is 0, it will
release the cache->area by nfp_cpp_area_release(). area_cache_get()
set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().

But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
is already set but the refcount is not increased as expected. At this
time, calling the nfp_cpp_area_release() will cause use-after-free.

To avoid the use-after-free, set cache->id after area_init() and
nfp_cpp_area_acquire() complete successfully.

Note: This vulnerability is triggerable by providing emulated device
equipped with specified configuration.

BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
/x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1

Call Trace:
<TASK>
nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)

Allocated by task 1:
nfp_cpp_area_alloc_with_name (/home/user/Kernel/v5.19/x86_64/src/drivers
/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
nfp_cpp_area_cache_add (/home/user/Kernel/v5.19/x86_64/src/drivers/net
/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
/netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
nfp_cpp_from_operations (/home/user/Kernel/v5.19/x86_64/src/drivers/net
/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
/netronome/nfp/nfp_main.c:744)

Freed by task 1:
kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
/netronome/nfp/nfpcore/nfp_cppcore.c:924 /home/user/Kernel/v5.19/x86_64
/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
/netronome/nfp/nfpcore/nfp_cpplib.c:48)

Signed-off-by: Jialiang Wang <[email protected]>
---
drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
index 34c0d2ddf9ef..a8286d0032d1 100644
--- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
+++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
@@ -874,7 +874,6 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
}

/* Adjust the start address to be cache size aligned */
- cache->id = id;
cache->addr = addr & ~(u64)(cache->size - 1);

/* Re-init to the new ID and address */
@@ -894,6 +893,8 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
return NULL;
}

+ cache->id = id;
+
exit:
/* Adjust offset */
*offset = addr - cache->addr;
--
2.17.1


2022-08-11 04:42:16

by Yinjun Zhang

[permalink] [raw]
Subject: RE: [PATCH v3] nfp: fix use-after-free in area_cache_get()

On Wed, 10 Aug 2022 15:30:57 +0800 Jialiang Wang wrote:
> area_cache_get() is used to distribute cache->area and set cache->id,
> and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> release the cache->area by nfp_cpp_area_release(). area_cache_get()
> set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
>
> But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> is already set but the refcount is not increased as expected. At this
> time, calling the nfp_cpp_area_release() will cause use-after-free.
>
> To avoid the use-after-free, set cache->id after area_init() and
> nfp_cpp_area_acquire() complete successfully.
>
> Note: This vulnerability is triggerable by providing emulated device
> equipped with specified configuration.
>
> BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:7
> 60)
> Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
>
> Call Trace:
> <TASK>
> nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
>
> Allocated by task 1:
> nfp_cpp_area_alloc_with_name
> (/home/user/Kernel/v5.19/x86_64/src/drivers
> /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> nfp_cpp_area_cache_add
> (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> nfp_cpp_from_operations
> (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfp_main.c:744)
>
> Freed by task 1:
> kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfpcore/nfp_cppcore.c:924
> /home/user/Kernel/v5.19/x86_64
> /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfpcore/nfp_cpplib.c:48)
>
> Signed-off-by: Jialiang Wang <[email protected]>

Thanks.
Reviewed-by: Yinjun Zhang <[email protected]>

2022-08-11 09:27:09

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

On Thu, Aug 11, 2022 at 05:10:44AM +0100, Yinjun Zhang wrote:
> On Wed, 10 Aug 2022 15:30:57 +0800 Jialiang Wang wrote:
> > area_cache_get() is used to distribute cache->area and set cache->id,
> > and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> > release the cache->area by nfp_cpp_area_release(). area_cache_get()
> > set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
> >
> > But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> > is already set but the refcount is not increased as expected. At this
> > time, calling the nfp_cpp_area_release() will cause use-after-free.
> >
> > To avoid the use-after-free, set cache->id after area_init() and
> > nfp_cpp_area_acquire() complete successfully.
> >
> > Note: This vulnerability is triggerable by providing emulated device
> > equipped with specified configuration.
> >
> > BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> > /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:7
> > 60)
> > Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
> >
> > Call Trace:
> > <TASK>
> > nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
> >
> > Allocated by task 1:
> > nfp_cpp_area_alloc_with_name
> > (/home/user/Kernel/v5.19/x86_64/src/drivers
> > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> > nfp_cpp_area_cache_add
> > (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> > nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> > nfp_cpp_from_operations
> > (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> > nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfp_main.c:744)
> >
> > Freed by task 1:
> > kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> > nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfpcore/nfp_cppcore.c:924
> > /home/user/Kernel/v5.19/x86_64
> > /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> > nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfpcore/nfp_cpplib.c:48)
> >
> > Signed-off-by: Jialiang Wang <[email protected]>
>
> Thanks.
> Reviewed-by: Yinjun Zhang <[email protected]>

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

2022-08-11 16:55:53

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

Hello:

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

On Wed, 10 Aug 2022 15:30:57 +0800 you wrote:
> area_cache_get() is used to distribute cache->area and set cache->id,
> and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> release the cache->area by nfp_cpp_area_release(). area_cache_get()
> set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
>
> But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> is already set but the refcount is not increased as expected. At this
> time, calling the nfp_cpp_area_release() will cause use-after-free.
>
> [...]

Here is the summary with links:
- [v3] nfp: fix use-after-free in area_cache_get()
https://git.kernel.org/netdev/net/c/02e1a114fdb7

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


2022-12-07 12:34:28

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

On Wed, 10 Aug 2022, Jialiang Wang wrote:

> area_cache_get() is used to distribute cache->area and set cache->id,
> and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> release the cache->area by nfp_cpp_area_release(). area_cache_get()
> set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
>
> But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> is already set but the refcount is not increased as expected. At this
> time, calling the nfp_cpp_area_release() will cause use-after-free.
>
> To avoid the use-after-free, set cache->id after area_init() and
> nfp_cpp_area_acquire() complete successfully.
>
> Note: This vulnerability is triggerable by providing emulated device
> equipped with specified configuration.
>
> BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
>
> Call Trace:
> <TASK>
> nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
>
> Allocated by task 1:
> nfp_cpp_area_alloc_with_name (/home/user/Kernel/v5.19/x86_64/src/drivers
> /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> nfp_cpp_area_cache_add (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> nfp_cpp_from_operations (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfp_main.c:744)
>
> Freed by task 1:
> kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfpcore/nfp_cppcore.c:924 /home/user/Kernel/v5.19/x86_64
> /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> /netronome/nfp/nfpcore/nfp_cpplib.c:48)
>
> Signed-off-by: Jialiang Wang <[email protected]>

Any reason why this doesn't have a Fixes: tag applied and/or didn't
get sent to Stable?

Looks as if this needs to go back as far as v4.19.

Fixes: 4cb584e0ee7df ("nfp: add CPP access core")

commit 02e1a114fdb71e59ee6770294166c30d437bf86a upstream.

> ---
> drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
> index 34c0d2ddf9ef..a8286d0032d1 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
> +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
> @@ -874,7 +874,6 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
> }
>
> /* Adjust the start address to be cache size aligned */
> - cache->id = id;
> cache->addr = addr & ~(u64)(cache->size - 1);
>
> /* Re-init to the new ID and address */
> @@ -894,6 +893,8 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
> return NULL;
> }
>
> + cache->id = id;
> +
> exit:
> /* Adjust offset */
> *offset = addr - cache->addr;

--
Lee Jones [李琼斯]

2022-12-08 14:41:24

by Simon Horman

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

On Wed, Dec 07, 2022 at 12:21:10PM +0000, Lee Jones wrote:
> [Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> On Wed, 10 Aug 2022, Jialiang Wang wrote:
>
> > area_cache_get() is used to distribute cache->area and set cache->id,
> > and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> > release the cache->area by nfp_cpp_area_release(). area_cache_get()
> > set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
> >
> > But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> > is already set but the refcount is not increased as expected. At this
> > time, calling the nfp_cpp_area_release() will cause use-after-free.
> >
> > To avoid the use-after-free, set cache->id after area_init() and
> > nfp_cpp_area_acquire() complete successfully.
> >
> > Note: This vulnerability is triggerable by providing emulated device
> > equipped with specified configuration.
> >
> > BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> > /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
> >
> > Call Trace:
> > <TASK>
> > nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
> >
> > Allocated by task 1:
> > nfp_cpp_area_alloc_with_name (/home/user/Kernel/v5.19/x86_64/src/drivers
> > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> > nfp_cpp_area_cache_add (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> > nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> > nfp_cpp_from_operations (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> > nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfp_main.c:744)
> >
> > Freed by task 1:
> > kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> > nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfpcore/nfp_cppcore.c:924 /home/user/Kernel/v5.19/x86_64
> > /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> > nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > /netronome/nfp/nfpcore/nfp_cpplib.c:48)
> >
> > Signed-off-by: Jialiang Wang <[email protected]>
>
> Any reason why this doesn't have a Fixes: tag applied and/or didn't
> get sent to Stable?
>
> Looks as if this needs to go back as far as v4.19.
>
> Fixes: 4cb584e0ee7df ("nfp: add CPP access core")
>
> commit 02e1a114fdb71e59ee6770294166c30d437bf86a upstream.

Hi Lee,

From my side this looks like an oversight.

> > ---
> > drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
> > index 34c0d2ddf9ef..a8286d0032d1 100644
> > --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
> > +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c
> > @@ -874,7 +874,6 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
> > }
> >
> > /* Adjust the start address to be cache size aligned */
> > - cache->id = id;
> > cache->addr = addr & ~(u64)(cache->size - 1);
> >
> > /* Re-init to the new ID and address */
> > @@ -894,6 +893,8 @@ area_cache_get(struct nfp_cpp *cpp, u32 id,
> > return NULL;
> > }
> >
> > + cache->id = id;
> > +
> > exit:
> > /* Adjust offset */
> > *offset = addr - cache->addr;
>
> --
> Lee Jones [李琼斯]

2022-12-14 10:35:50

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

Dear Stable,

On Thu, 08 Dec 2022, Simon Horman wrote:
> On Wed, Dec 07, 2022 at 12:21:10PM +0000, Lee Jones wrote:
> > [Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> >
> > On Wed, 10 Aug 2022, Jialiang Wang wrote:
> >
> > > area_cache_get() is used to distribute cache->area and set cache->id,
> > > and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> > > release the cache->area by nfp_cpp_area_release(). area_cache_get()
> > > set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
> > >
> > > But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> > > is already set but the refcount is not increased as expected. At this
> > > time, calling the nfp_cpp_area_release() will cause use-after-free.
> > >
> > > To avoid the use-after-free, set cache->id after area_init() and
> > > nfp_cpp_area_acquire() complete successfully.
> > >
> > > Note: This vulnerability is triggerable by providing emulated device
> > > equipped with specified configuration.
> > >
> > > BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> > > /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
> > >
> > > Call Trace:
> > > <TASK>
> > > nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
> > >
> > > Allocated by task 1:
> > > nfp_cpp_area_alloc_with_name (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> > > nfp_cpp_area_cache_add (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> > > nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> > > nfp_cpp_from_operations (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> > > nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfp_main.c:744)
> > >
> > > Freed by task 1:
> > > kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> > > nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfpcore/nfp_cppcore.c:924 /home/user/Kernel/v5.19/x86_64
> > > /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> > > nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfpcore/nfp_cpplib.c:48)
> > >
> > > Signed-off-by: Jialiang Wang <[email protected]>
> >
> > Any reason why this doesn't have a Fixes: tag applied and/or didn't
> > get sent to Stable?
> >
> > Looks as if this needs to go back as far as v4.19.
> >
> > Fixes: 4cb584e0ee7df ("nfp: add CPP access core")
> >
> > commit 02e1a114fdb71e59ee6770294166c30d437bf86a upstream.
>
> Hi Lee,
>
> From my side this looks like an oversight.

Understood, thank you Simon.

Stable Team, are you prepared to take this patch with the above info?

--
Lee Jones [李琼斯]

2022-12-15 10:00:14

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

Dear Stable,

[NB: Re-poking Stable with the correct contact address this time! :)]

> > > area_cache_get() is used to distribute cache->area and set cache->id,
> > > and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> > > release the cache->area by nfp_cpp_area_release(). area_cache_get()
> > > set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
> > >
> > > But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> > > is already set but the refcount is not increased as expected. At this
> > > time, calling the nfp_cpp_area_release() will cause use-after-free.
> > >
> > > To avoid the use-after-free, set cache->id after area_init() and
> > > nfp_cpp_area_acquire() complete successfully.
> > >
> > > Note: This vulnerability is triggerable by providing emulated device
> > > equipped with specified configuration.
> > >
> > > BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> > > /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
> > >
> > > Call Trace:
> > > <TASK>
> > > nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
> > >
> > > Allocated by task 1:
> > > nfp_cpp_area_alloc_with_name (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> > > nfp_cpp_area_cache_add (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> > > nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> > > nfp_cpp_from_operations (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> > > nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfp_main.c:744)
> > >
> > > Freed by task 1:
> > > kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> > > nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfpcore/nfp_cppcore.c:924 /home/user/Kernel/v5.19/x86_64
> > > /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> > > nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > /netronome/nfp/nfpcore/nfp_cpplib.c:48)
> > >
> > > Signed-off-by: Jialiang Wang <[email protected]>
> >
> > Any reason why this doesn't have a Fixes: tag applied and/or didn't
> > get sent to Stable?
> >
> > Looks as if this needs to go back as far as v4.19.
> >
> > Fixes: 4cb584e0ee7df ("nfp: add CPP access core")
> >
> > commit 02e1a114fdb71e59ee6770294166c30d437bf86a upstream.

Would you be able to take this with the information provided please?

--
Lee Jones [李琼斯]

2022-12-15 10:54:41

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

On Thu, Dec 15, 2022 at 09:25:23AM +0000, Lee Jones wrote:
> Dear Stable,
>
> [NB: Re-poking Stable with the correct contact address this time! :)]
>
> > > > area_cache_get() is used to distribute cache->area and set cache->id,
> > > > and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> > > > release the cache->area by nfp_cpp_area_release(). area_cache_get()
> > > > set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
> > > >
> > > > But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> > > > is already set but the refcount is not increased as expected. At this
> > > > time, calling the nfp_cpp_area_release() will cause use-after-free.
> > > >
> > > > To avoid the use-after-free, set cache->id after area_init() and
> > > > nfp_cpp_area_acquire() complete successfully.
> > > >
> > > > Note: This vulnerability is triggerable by providing emulated device
> > > > equipped with specified configuration.
> > > >
> > > > BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> > > > /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > > Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
> > > >
> > > > Call Trace:
> > > > <TASK>
> > > > nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > > /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
> > > >
> > > > Allocated by task 1:
> > > > nfp_cpp_area_alloc_with_name (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> > > > nfp_cpp_area_cache_add (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> > > > nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> > > > nfp_cpp_from_operations (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> > > > nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > /netronome/nfp/nfp_main.c:744)
> > > >
> > > > Freed by task 1:
> > > > kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> > > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> > > > nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > /netronome/nfp/nfpcore/nfp_cppcore.c:924 /home/user/Kernel/v5.19/x86_64
> > > > /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> > > > nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > /netronome/nfp/nfpcore/nfp_cpplib.c:48)
> > > >
> > > > Signed-off-by: Jialiang Wang <[email protected]>
> > >
> > > Any reason why this doesn't have a Fixes: tag applied and/or didn't
> > > get sent to Stable?
> > >
> > > Looks as if this needs to go back as far as v4.19.
> > >
> > > Fixes: 4cb584e0ee7df ("nfp: add CPP access core")
> > >
> > > commit 02e1a114fdb71e59ee6770294166c30d437bf86a upstream.
>
> Would you be able to take this with the information provided please?

You really want this back to 4.14.y, as 4cb584e0ee7df ("nfp: add CPP
access core") showed up in the 4.11 release, right?

if so, now queued up.

greg k-h

2022-12-15 10:54:52

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH v3] nfp: fix use-after-free in area_cache_get()

On Thu, 15 Dec 2022, Greg KH wrote:

> On Thu, Dec 15, 2022 at 09:25:23AM +0000, Lee Jones wrote:
> > Dear Stable,
> >
> > [NB: Re-poking Stable with the correct contact address this time! :)]
> >
> > > > > area_cache_get() is used to distribute cache->area and set cache->id,
> > > > > and if cache->id is not 0 and cache->area->kref refcount is 0, it will
> > > > > release the cache->area by nfp_cpp_area_release(). area_cache_get()
> > > > > set cache->id before cpp->op->area_init() and nfp_cpp_area_acquire().
> > > > >
> > > > > But if area_init() or nfp_cpp_area_acquire() fails, the cache->id is
> > > > > is already set but the refcount is not increased as expected. At this
> > > > > time, calling the nfp_cpp_area_release() will cause use-after-free.
> > > > >
> > > > > To avoid the use-after-free, set cache->id after area_init() and
> > > > > nfp_cpp_area_acquire() complete successfully.
> > > > >
> > > > > Note: This vulnerability is triggerable by providing emulated device
> > > > > equipped with specified configuration.
> > > > >
> > > > > BUG: KASAN: use-after-free in nfp6000_area_init (/home/user/Kernel/v5.19
> > > > > /x86_64/src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > > > Write of size 4 at addr ffff888005b7f4a0 by task swapper/0/1
> > > > >
> > > > > Call Trace:
> > > > > <TASK>
> > > > > nfp6000_area_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > > > /ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c:760)
> > > > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:884)
> > > > >
> > > > > Allocated by task 1:
> > > > > nfp_cpp_area_alloc_with_name (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:303)
> > > > > nfp_cpp_area_cache_add (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:802)
> > > > > nfp6000_init (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > > /netronome/nfp/nfpcore/nfp6000_pcie.c:1230)
> > > > > nfp_cpp_from_operations (/home/user/Kernel/v5.19/x86_64/src/drivers/net
> > > > > /ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:1215)
> > > > > nfp_pci_probe (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > > /netronome/nfp/nfp_main.c:744)
> > > > >
> > > > > Freed by task 1:
> > > > > kfree (/home/user/Kernel/v5.19/x86_64/src/mm/slub.c:4562)
> > > > > area_cache_get.constprop.8 (/home/user/Kernel/v5.19/x86_64/src/drivers
> > > > > /net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:873)
> > > > > nfp_cpp_read (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > > /netronome/nfp/nfpcore/nfp_cppcore.c:924 /home/user/Kernel/v5.19/x86_64
> > > > > /src/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c:973)
> > > > > nfp_cpp_readl (/home/user/Kernel/v5.19/x86_64/src/drivers/net/ethernet
> > > > > /netronome/nfp/nfpcore/nfp_cpplib.c:48)
> > > > >
> > > > > Signed-off-by: Jialiang Wang <[email protected]>
> > > >
> > > > Any reason why this doesn't have a Fixes: tag applied and/or didn't
> > > > get sent to Stable?
> > > >
> > > > Looks as if this needs to go back as far as v4.19.
> > > >
> > > > Fixes: 4cb584e0ee7df ("nfp: add CPP access core")
> > > >
> > > > commit 02e1a114fdb71e59ee6770294166c30d437bf86a upstream.
> >
> > Would you be able to take this with the information provided please?
>
> You really want this back to 4.14.y, as 4cb584e0ee7df ("nfp: add CPP
> access core") showed up in the 4.11 release, right?

Yes please. Brain said one thing, fingers typed another!

> if so, now queued up.

Thank you.

--
Lee Jones [李琼斯]