Skip to contentSkip to conversation

netfilter: nf_tables: Fix for duplicate device in netdev hooks

PATCH In review Phil Sutter 2 participants 3 messages Mar 5

Subsystems (2)
lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: Fix for duplicate device in netdev hooks

When handling NETDEV_REGISTER notification, duplicate device registration must be avoided since the device may have been added by nft_netdev_hook_alloc() already when creating the hook.

Cc Helen Koike <[email protected]>
Reported-by [email protected]
Fixes a331b78a5525 ("netfilter: nf_tables: Respect NETDEV_REGISTER events")
---
 net/netfilter/nf_tables_api.c    | 2 +-
 net/netfilter/nft_chain_filter.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +1 -1
index 0c5a4855b97d..29f54998a637 100644
@@ -9679,7 +9679,7 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,
 			break;
 		case NETDEV_REGISTER:
 			/* NOP if not matching or already registered */
-			if (!match || (changename && ops))
+			if (!match || ops)
 				continue;
 
 			ops = kzalloc(sizeof(struct nf_hook_ops),
net/netfilter/nft_chain_filter.c +1 -1
index b16185e9a6dd..041426e3bdbf 100644
@@ -344,7 +344,7 @@ static int nft_netdev_event(unsigned long event, struct net_device *dev,
 			break;
 		case NETDEV_REGISTER:
 			/* NOP if not matching or already registered */
-			if (!match || (changename && ops))
+			if (!match || ops)
 				continue;
 
 			ops = kmemdup(&basechain->ops,
Signature · 1 line
2.51.0
Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Phil Sutter

When handling NETDEV_REGISTER notification, duplicate device registration must be avoided since the device may have been added by nft_netdev_hook_alloc() already when creating the hook.

Cc Helen Koike <[email protected]>
Reported-by [email protected]
Fixes a331b78a5525 ("netfilter: nf_tables: Respect NETDEV_REGISTER events")

I tested and validated this fixes the use-after-free as reported by syzbot.

Tested locally with Qemu using the disk image and reproducer from syzbot.

Thanks,
Helen

Quoted 31 lines
---
  net/netfilter/nf_tables_api.c    | 2 +-
  net/netfilter/nft_chain_filter.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +1 -1
index 0c5a4855b97d..29f54998a637 100644
@@ -9679,7 +9679,7 @@ static int nft_flowtable_event(unsigned long event, struct net_device *dev,
  			break;
  		case NETDEV_REGISTER:
  			/* NOP if not matching or already registered */
-			if (!match || (changename && ops))
+			if (!match || ops)
  				continue;
 
  			ops = kzalloc(sizeof(struct nf_hook_ops),
net/netfilter/nft_chain_filter.c +1 -1
index b16185e9a6dd..041426e3bdbf 100644
@@ -344,7 +344,7 @@ static int nft_netdev_event(unsigned long event, struct net_device *dev,
  			break;
  		case NETDEV_REGISTER:
  			/* NOP if not matching or already registered */
-			if (!match || (changename && ops))
+			if (!match || ops)
  				continue;
 
  			ops = kmemdup(&basechain->ops,
author reviewer
#2 lore raw
Quoted 12 lines · Helen Koike
Quoted 10 lines · Phil Sutter

When handling NETDEV_REGISTER notification, duplicate device registration must be avoided since the device may have been added by nft_netdev_hook_alloc() already when creating the hook.

Cc Helen Koike <[email protected]>
Reported-by [email protected]
Fixes a331b78a5525 ("netfilter: nf_tables: Respect NETDEV_REGISTER events")
Quoted 5 lines

I tested and validated this fixes the use-after-free as reported by syzbot.

Tested locally with Qemu using the disk image and reproducer from syzbot.

Thanks for testing, Helen!