All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow
@ 2022-07-02 17:59 Hugues ANGUELKOV
  2022-07-02 18:57 ` Pablo Neira Ayuso
  2022-07-02 18:59 ` Jakub Kicinski
  0 siblings, 2 replies; 6+ messages in thread
From: Hugues ANGUELKOV @ 2022-07-02 17:59 UTC (permalink / raw)
  To: netdev; +Cc: security, pablo, kadlec, fw, davy, amongodin, kuba, torvalds

From d91007a18140e02a1f12c9627058a019fe55b8e6 Mon Sep 17 00:00:00 2001
From: Arthur Mongodin <amongodin@randorisec.fr>
Date: Sat, 2 Jul 2022 17:11:48 +0200
Subject: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer
 overflow

The length used for the memcpy in nft_set_elem_init may exceed the bound
of the allocated object due to a weak check in nft_setelem_parse_data.
As a user can add an element with a data type NFT_DATA_VERDICT to a set
with a data type different of NFT_DATA_VERDICT, then the comparison on the
data type of the element allows to avoid the comparaison on the data length
This fix forces the length comparison in nft_setelem_parse_data by removing
the check for NFT_DATA_VERDICT type.

====

BUG: KASAN: slab-out-of-bounds in nft_set_elem_init+0x158/0x1f0
Write of size 64 at addr ffff888007f717b0 by task poc/264

Call Trace:
 <TASK>
 dump_stack_lvl+0x3a/0x4c
 print_report.cold+0x5e/0x5e7
 ? nft_set_elem_init+0x158/0x1f0
 kasan_report+0xaa/0x120
 ? nft_set_elem_init+0x158/0x1f0
 kasan_check_range+0x160/0x1c0
 memcpy+0x3b/0x60
 nft_set_elem_init+0x158/0x1f0
 ...

Allocated by task 264:
 kasan_save_stack+0x26/0x50
 __kasan_kmalloc+0x95/0xc0
 __kmalloc+0x29a/0x4d0
 nft_set_elem_init+0x68/0x1f0
 ...

Fixes: fdb9c405e35b ("netfilter: nf_tables: allow up to 64 bytes in the set element data area")
Signed-off-by: Arthur Mongodin <amongodin@randorisec.fr>
---
 net/netfilter/nf_tables_api.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 51144fc66889..07845f211f3e 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -5219,7 +5219,7 @@ static int nft_setelem_parse_data(struct nft_ctx *ctx, struct nft_set *set,
 	if (err < 0)
 		return err;
 
-	if (desc->type != NFT_DATA_VERDICT && desc->len != set->dlen) {
+	if (desc->len != set->dlen) {
 		nft_data_release(data, desc->type);
 		return -EINVAL;
 	}
-- 
2.36.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow
  2022-07-02 17:59 [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow Hugues ANGUELKOV
@ 2022-07-02 18:57 ` Pablo Neira Ayuso
  2022-07-02 19:11   ` Pablo Neira Ayuso
  2022-07-02 18:59 ` Jakub Kicinski
  1 sibling, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2022-07-02 18:57 UTC (permalink / raw)
  To: Hugues ANGUELKOV
  Cc: netdev, security, kadlec, fw, davy, amongodin, kuba, torvalds,
	netfilter-devel

On Sat, Jul 02, 2022 at 07:59:11PM +0200, Hugues ANGUELKOV wrote:
> From d91007a18140e02a1f12c9627058a019fe55b8e6 Mon Sep 17 00:00:00 2001
> From: Arthur Mongodin <amongodin@randorisec.fr>
> Date: Sat, 2 Jul 2022 17:11:48 +0200
> Subject: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer
>  overflow
> 
> The length used for the memcpy in nft_set_elem_init may exceed the bound
> of the allocated object due to a weak check in nft_setelem_parse_data.
> As a user can add an element with a data type NFT_DATA_VERDICT to a set
> with a data type different of NFT_DATA_VERDICT, then the comparison on the
> data type of the element allows to avoid the comparaison on the data length
> This fix forces the length comparison in nft_setelem_parse_data by removing
> the check for NFT_DATA_VERDICT type.

https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702021631.796822-1-pablo@netfilter.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow
  2022-07-02 17:59 [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow Hugues ANGUELKOV
  2022-07-02 18:57 ` Pablo Neira Ayuso
@ 2022-07-02 18:59 ` Jakub Kicinski
  2022-07-02 19:02   ` Pablo Neira Ayuso
  1 sibling, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2022-07-02 18:59 UTC (permalink / raw)
  To: Hugues ANGUELKOV
  Cc: netdev, security, pablo, kadlec, fw, davy, amongodin, torvalds

On Sat, 2 Jul 2022 19:59:11 +0200 Hugues ANGUELKOV wrote:
> From d91007a18140e02a1f12c9627058a019fe55b8e6 Mon Sep 17 00:00:00 2001
> From: Arthur Mongodin <amongodin@randorisec.fr>
> Date: Sat, 2 Jul 2022 17:11:48 +0200
> Subject: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer
>  overflow

You have the headers twice, you may want to trim them or use git
send-email if v2 is needed.

> The length used for the memcpy in nft_set_elem_init may exceed the bound
> of the allocated object due to a weak check in nft_setelem_parse_data.
> As a user can add an element with a data type NFT_DATA_VERDICT to a set
> with a data type different of NFT_DATA_VERDICT, then the comparison on the
> data type of the element allows to avoid the comparaison on the data length
> This fix forces the length comparison in nft_setelem_parse_data by removing
> the check for NFT_DATA_VERDICT type.

> Fixes: fdb9c405e35b ("netfilter: nf_tables: allow up to 64 bytes in the set element data area")
> Signed-off-by: Arthur Mongodin <amongodin@randorisec.fr>
> ---
>  net/netfilter/nf_tables_api.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index 51144fc66889..07845f211f3e 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -5219,7 +5219,7 @@ static int nft_setelem_parse_data(struct nft_ctx *ctx, struct nft_set *set,
>  	if (err < 0)
>  		return err;
>  
> -	if (desc->type != NFT_DATA_VERDICT && desc->len != set->dlen) {
> +	if (desc->len != set->dlen) {

Looking at the commit under fixes it seems like it changes the check
from desc->type != ... to set->type != ...

Seems like either the bug is even older or the fix should be to go back
to checking set->type. Prolly the former?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow
  2022-07-02 18:59 ` Jakub Kicinski
@ 2022-07-02 19:02   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2022-07-02 19:02 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Hugues ANGUELKOV, netdev, security, kadlec, fw, davy, amongodin,
	torvalds

On Sat, Jul 02, 2022 at 11:59:48AM -0700, Jakub Kicinski wrote:
> On Sat, 2 Jul 2022 19:59:11 +0200 Hugues ANGUELKOV wrote:
> > From d91007a18140e02a1f12c9627058a019fe55b8e6 Mon Sep 17 00:00:00 2001
> > From: Arthur Mongodin <amongodin@randorisec.fr>
> > Date: Sat, 2 Jul 2022 17:11:48 +0200
> > Subject: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer
> >  overflow
> 
> You have the headers twice, you may want to trim them or use git
> send-email if v2 is needed.
> 
> > The length used for the memcpy in nft_set_elem_init may exceed the bound
> > of the allocated object due to a weak check in nft_setelem_parse_data.
> > As a user can add an element with a data type NFT_DATA_VERDICT to a set
> > with a data type different of NFT_DATA_VERDICT, then the comparison on the
> > data type of the element allows to avoid the comparaison on the data length
> > This fix forces the length comparison in nft_setelem_parse_data by removing
> > the check for NFT_DATA_VERDICT type.
> 
> > Fixes: fdb9c405e35b ("netfilter: nf_tables: allow up to 64 bytes in the set element data area")
> > Signed-off-by: Arthur Mongodin <amongodin@randorisec.fr>
> > ---
> >  net/netfilter/nf_tables_api.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> > index 51144fc66889..07845f211f3e 100644
> > --- a/net/netfilter/nf_tables_api.c
> > +++ b/net/netfilter/nf_tables_api.c
> > @@ -5219,7 +5219,7 @@ static int nft_setelem_parse_data(struct nft_ctx *ctx, struct nft_set *set,
> >  	if (err < 0)
> >  		return err;
> >  
> > -	if (desc->type != NFT_DATA_VERDICT && desc->len != set->dlen) {
> > +	if (desc->len != set->dlen) {
> 
> Looking at the commit under fixes it seems like it changes the check
> from desc->type != ... to set->type != ...
> 
> Seems like either the bug is even older or the fix should be to go back
> to checking set->type. Prolly the former?

Hold on with this, please.

There is a patch coming in a pull request from nf.git

Thanks for reviewing.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow
  2022-07-02 18:57 ` Pablo Neira Ayuso
@ 2022-07-02 19:11   ` Pablo Neira Ayuso
  2022-07-02 19:23     ` Hugues ANGUELKOV
  0 siblings, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2022-07-02 19:11 UTC (permalink / raw)
  To: Hugues ANGUELKOV
  Cc: netdev, security, kadlec, fw, davy, amongodin, kuba, torvalds,
	netfilter-devel

On Sat, Jul 02, 2022 at 08:57:14PM +0200, Pablo Neira Ayuso wrote:
> On Sat, Jul 02, 2022 at 07:59:11PM +0200, Hugues ANGUELKOV wrote:
> > From d91007a18140e02a1f12c9627058a019fe55b8e6 Mon Sep 17 00:00:00 2001
> > From: Arthur Mongodin <amongodin@randorisec.fr>
> > Date: Sat, 2 Jul 2022 17:11:48 +0200
> > Subject: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer
> >  overflow
> > 
> > The length used for the memcpy in nft_set_elem_init may exceed the bound
> > of the allocated object due to a weak check in nft_setelem_parse_data.
> > As a user can add an element with a data type NFT_DATA_VERDICT to a set
> > with a data type different of NFT_DATA_VERDICT, then the comparison on the
> > data type of the element allows to avoid the comparaison on the data length
> > This fix forces the length comparison in nft_setelem_parse_data by removing
> > the check for NFT_DATA_VERDICT type.
> 
> https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702021631.796822-1-pablo@netfilter.org/

For the record, pull request is already available with pending fixes
for net.

https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702191029.238563-1-pablo@netfilter.org/
https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702191029.238563-2-pablo@netfilter.org/
https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702191029.238563-3-pablo@netfilter.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow
  2022-07-02 19:11   ` Pablo Neira Ayuso
@ 2022-07-02 19:23     ` Hugues ANGUELKOV
  0 siblings, 0 replies; 6+ messages in thread
From: Hugues ANGUELKOV @ 2022-07-02 19:23 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: netdev, security, kadlec, fw, davy, amongodin, kuba,
	Linus Torvalds, netfilter-devel

On 7/2/22 21:11, Pablo Neira Ayuso wrote:
> On Sat, Jul 02, 2022 at 08:57:14PM +0200, Pablo Neira Ayuso wrote:
>> On Sat, Jul 02, 2022 at 07:59:11PM +0200, Hugues ANGUELKOV wrote:
>>> From d91007a18140e02a1f12c9627058a019fe55b8e6 Mon Sep 17 00:00:00 2001
>>> From: Arthur Mongodin <amongodin@randorisec.fr>
>>> Date: Sat, 2 Jul 2022 17:11:48 +0200
>>> Subject: [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer
>>>  overflow
>>>
>>> The length used for the memcpy in nft_set_elem_init may exceed the bound
>>> of the allocated object due to a weak check in nft_setelem_parse_data.
>>> As a user can add an element with a data type NFT_DATA_VERDICT to a set
>>> with a data type different of NFT_DATA_VERDICT, then the comparison on the
>>> data type of the element allows to avoid the comparaison on the data length
>>> This fix forces the length comparison in nft_setelem_parse_data by removing
>>> the check for NFT_DATA_VERDICT type.
>>
>> https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702021631.796822-1-pablo@netfilter.org/
> 
> For the record, pull request is already available with pending fixes
> for net.
> 
> https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702191029.238563-1-pablo@netfilter.org/
> https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702191029.238563-2-pablo@netfilter.org/
> https://patchwork.ozlabs.org/project/netfilter-devel/patch/20220702191029.238563-3-pablo@netfilter.org/

Arthur Mongodin which has found the vulnerability is currently testing the proposed fixes against his exploit.

He is also the original writer of the previously proposed fixes and should be credited as reporter.

I'm currently waiting for his various test results.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-02 19:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-02 17:59 [PATCH v1] netfilter: nf_tables: fix nft_set_elem_init heap buffer overflow Hugues ANGUELKOV
2022-07-02 18:57 ` Pablo Neira Ayuso
2022-07-02 19:11   ` Pablo Neira Ayuso
2022-07-02 19:23     ` Hugues ANGUELKOV
2022-07-02 18:59 ` Jakub Kicinski
2022-07-02 19:02   ` Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.