netfilter: nf_tables: Fix for duplicate device in netdev hooks
Subsystems (2)
Phil Sutter
reviewerPATCH 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.
--- 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
@@ -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
@@ -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
Quoted 10 lines · Phil Sutter
When handling
NETDEV_REGISTERnotification, duplicate device registration must be avoided since the device may have been added bynft_netdev_hook_alloc()already when creating the hook.Cc Helen Koike <[email protected]>Suggested-by Florian Westphal <[email protected]>Reported-by [email protected]Fixes a331b78a5525 ("netfilter: nf_tables: Respect NETDEV_REGISTER events")Signed-off-by Phil Sutter <[email protected]>
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@@ -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@@ -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,
Phil Sutter
reviewerQuoted 12 lines · Helen Koike
Quoted 10 lines · Phil Sutter
When handling
NETDEV_REGISTERnotification, duplicate device registration must be avoided since the device may have been added bynft_netdev_hook_alloc()already when creating the hook.Cc Helen Koike <[email protected]>Suggested-by Florian Westphal <[email protected]>Reported-by [email protected]Fixes a331b78a5525 ("netfilter: nf_tables: Respect NETDEV_REGISTER events")Signed-off-by Phil Sutter <[email protected]>
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.
Tested-by Helen Koike <[email protected]>
Thanks for testing, Helen!