Netfilter fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
Patch #1 fixes the suspicious RCU usage warning that resulted from the
recent fix for the race between namespace cleanup and gc in ipset left out checking the pernet exit phase when calling rcu_dereference_protected(), from Jozsef Kadlecsik.
Patch #2 fixes incorrect input and output netdevice in SRv6 prerouting
hooks, from Jianguo Wu.
Patch #3 moves nf_hooks_lwtunnel sysctl toggle to the netfilter core.
The connection tracking system is loaded on-demand, this ensures availability of this knob regardless.
Patch #4-#5 adds selftests for SRv6 netfilter hooks also from Jianguo Wu.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-24-06-19
Thanks.
----------------------------------------------------------------
The following changes since commit a8763466669d21b570b26160d0a5e0a2ee529d22:
selftests: openvswitch: Set value to nla flags. (2024-06-19 13:10:53 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git tags/nf-24-06-19
for you to fetch changes up to 221200ffeb065c6bbd196760c168b42305961655:
selftests: add selftest for the SRv6 End.DX6 behavior with netfilter (2024-06-19 18:42:10 +0200)
----------------------------------------------------------------
netfilter pull request 24-06-19
----------------------------------------------------------------
Jianguo Wu (4):
seg6: fix parameter passing when calling NF_HOOK() in End.DX4 and End.DX6 behaviors
netfilter: move the sysctl nf_hooks_lwtunnel into the netfilter core
selftests: add selftest for the SRv6 End.DX4 behavior with netfilter
selftests: add selftest for the SRv6 End.DX6 behavior with netfilter
Jozsef Kadlecsik (1):
netfilter: ipset: Fix suspicious rcu_dereference_protected()
include/net/netns/netfilter.h | 3 + net/ipv6/seg6_local.c | 8 +- net/netfilter/core.c | 13 +- net/netfilter/ipset/ip_set_core.c | 11 +- net/netfilter/nf_conntrack_standalone.c | 15 - net/netfilter/nf_hooks_lwtunnel.c | 67 ++++ net/netfilter/nf_internals.h | 6 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/config | 2 + .../selftests/net/srv6_end_dx4_netfilter_test.sh | 335 ++++++++++++++++++++ .../selftests/net/srv6_end_dx6_netfilter_test.sh | 340 +++++++++++++++++++++ 11 files changed, 776 insertions(+), 26 deletions(-) create mode 100755 tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh create mode 100755 tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh
Pablo Neira Ayuso
maintainerPATCH 1/5 netfilter: ipset: Fix suspicious rcu_dereference_protected()
From: Jozsef Kadlecsik <[email protected]>
When destroying all sets, we are either in pernet exit phase or are executing a "destroy all sets command" from userspace. The latter was taken into account in ip_set_dereference() (nfnetlink mutex is held), but the former was not. The patch adds the required check to rcu_dereference_protected() in ip_set_dereference().
--- net/netfilter/ipset/ip_set_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/netfilter/ipset/ip_set_core.c +6 -5
@@ -53,12 +53,13 @@ MODULE_DESCRIPTION("core IP set support");MODULE_ALIAS_NFNL_SUBSYS (NFNL_SUBSYS_IPSET );/* When the nfnl mutex or ip_set_ref_lock is held: */ -#define ip_set_dereference (p) \ - rcu_dereference_protected(p, \ +#define ip_set_dereference (inst) \ + rcu_dereference_protected((inst)->ip_set_list, \ lockdep_nfnl_is_held(NFNL_SUBSYS_IPSET) || \ - lockdep_is_held(&ip_set_ref_lock)) + lockdep_is_held(&ip_set_ref_lock) || \ + (inst)->is_deleted)#define ip_set (inst, id) \ - ip_set_dereference((inst)->ip_set_list)[id] + ip_set_dereference(inst)[id]#define ip_set_ref_netlink (inst,id) \ rcu_dereference_raw((inst)->ip_set_list)[id]#define ip_set_dereference_nfnl (p) \
@@ -1133,7 +1134,7 @@ static int ip_set_create(struct sk_buff *skb, const struct nfnl_info *info,if (!list) goto cleanup;/* nfnl mutex is held, both lists are valid */ - tmp =ip_set_dereference (inst->ip_set_list); + tmp =ip_set_dereference (inst);memcpy (list, tmp,sizeof (struct ip_set *) * inst->ip_set_max);rcu_assign_pointer (inst->ip_set_list, list);/* Make sure all current packets have passed through */
Signature · 1 line
2.30.2
Re: [PATCH net 1/5] netfilter: ipset: Fix suspicious rcu_dereference_protected()
This series was applied to netdev/net.git (main) by Pablo Neira Ayuso <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <[email protected]>:
Quoted 9 lines · On Wed, 19 Jun 2024 19:05:33 +0200 you wrote:
From: Jozsef Kadlecsik <[email protected]>
When destroying all sets, we are either in pernet exit phase or are executing a "destroy all sets command" from userspace. The latter was taken into account in
ip_set_dereference()(nfnetlink mutex is held), but the former was not. The patch adds the required check torcu_dereference_protected()inip_set_dereference().[...]
Here is the summary with links:
- [net,1/5] netfilter: ipset: Fix suspicious rcu_dereference_protected()
https://git.kernel.org/netdev/net/c/8ecd06277a76 - [net,2/5] seg6: fix parameter passing when calling NF_HOOK() in End.DX4 and End.DX6 behaviors https://git.kernel.org/netdev/net/c/9a3bc8d16e0a - [net,3/5] netfilter: move the sysctl nf_hooks_lwtunnel into the netfilter core https://git.kernel.org/netdev/net/c/a2225e0250c5 - [net,4/5] selftests: add selftest for the SRv6 End.DX4 behavior with netfilter https://git.kernel.org/netdev/net/c/72e50ef99431 - [net,5/5] selftests: add selftest for the SRv6 End.DX6 behavior with netfilter https://git.kernel.org/netdev/net/c/221200ffeb06
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Pablo Neira Ayuso
maintainerPATCH 2/5 seg6: fix parameter passing when calling NF_HOOK() in End.DX4 and End.DX6 behaviors
In reply to Pablo Neira AyusoFrom: Jianguo Wu <[email protected]>
input_action_end_dx4() and input_action_end_dx6() are called NF_HOOK() for PREROUTING hook, in PREROUTING hook, we should passing a valid indev, and a NULL outdev to NF_HOOK(), otherwise may trigger a NULL pointer dereference, as below:
[74830.647293] BUG: kernel NULL pointer dereference, address: 0000000000000090
[74830.655633] #PF: supervisor read access in kernel mode
[74830.657888] #PF: error_code(0x0000) - not-present page
[74830.659500] PGD 0 P4D 0
[74830.660450] Oops: 0000 [#1] PREEMPT SMP PTI
...
[74830.664953] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
[74830.666569] RIP: 0010:rpfilter_mt+0x44/0x15e [ipt_rpfilter]
...
[74830.689725] Call Trace:
[74830.690402] <IRQ>
[74830.690953] ? show_trace_log_lvl+0x1c4/0x2df
[74830.692020] ? show_trace_log_lvl+0x1c4/0x2df
[74830.693095] ? ipt_do_table+0x286/0x710 [ip_tables]
[74830.694275] ? __die_body.cold+0x8/0xd
[74830.695205] ? page_fault_oops+0xac/0x140
[74830.696244] ? exc_page_fault+0x62/0x150
[74830.697225] ? asm_exc_page_fault+0x22/0x30
[74830.698344] ? rpfilter_mt+0x44/0x15e [ipt_rpfilter]
[74830.699540] ipt_do_table+0x286/0x710 [ip_tables]
[74830.700758] ? ip6_route_input+0x19d/0x240
[74830.701752] nf_hook_slow+0x3f/0xb0
[74830.702678] input_action_end_dx4+0x19b/0x1e0
[74830.703735] ? input_action_end_t+0xe0/0xe0
[74830.704734] seg6_local_input_core+0x2d/0x60
[74830.705782] lwtunnel_input+0x5b/0xb0
[74830.706690] __netif_receive_skb_one_core+0x63/0xa0
[74830.707825] process_backlog+0x99/0x140
[74830.709538] __napi_poll+0x2c/0x160
[74830.710673] net_rx_action+0x296/0x350
[74830.711860] __do_softirq+0xcb/0x2ac
[74830.713049] do_softirq+0x63/0x90input_action_end_dx4() passing a NULL indev to NF_HOOK(), and finally trigger a NULL dereference in rpfilter_mt()->rpfilter_is_loopback():
static bool
rpfilter_is_loopback(const struct sk_buff *skb,
const struct net_device *in)
{
// in is NULL
return skb->pkt_type == PACKET_LOOPBACK ||
in->flags & IFF_LOOPBACK;
}--- net/ipv6/seg6_local.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv6/seg6_local.c +4 -4
@@ -941,8 +941,8 @@ static int input_action_end_dx6(struct sk_buff *skb,if (static_branch_unlikely (&nf_hooks_lwtunnel_enabled))return NF_HOOK (NFPROTO_IPV6 ,NF_INET_PRE_ROUTING , -dev_net (skb->dev),NULL , skb,NULL , -skb_dst (skb)->dev, input_action_end_dx6_finish); +dev_net (skb->dev),NULL , skb, skb->dev, +NULL , input_action_end_dx6_finish);return input_action_end_dx6_finish (dev_net (skb->dev),NULL , skb); drop:
@@ -991,8 +991,8 @@ static int input_action_end_dx4(struct sk_buff *skb,if (static_branch_unlikely (&nf_hooks_lwtunnel_enabled))return NF_HOOK (NFPROTO_IPV4 ,NF_INET_PRE_ROUTING , -dev_net (skb->dev),NULL , skb,NULL , -skb_dst (skb)->dev, input_action_end_dx4_finish); +dev_net (skb->dev),NULL , skb, skb->dev, +NULL , input_action_end_dx4_finish);return input_action_end_dx4_finish (dev_net (skb->dev),NULL , skb); drop:
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/5 netfilter: move the sysctl nf_hooks_lwtunnel into the netfilter core
In reply to Pablo Neira AyusoFrom: Jianguo Wu <[email protected]>
Currently, the sysctl net.netfilter.nf_hooks_lwtunnel depends on the nf_conntrack module, but the nf_conntrack module is not always loaded. Therefore, accessing net.netfilter.nf_hooks_lwtunnel may have an error.
Move sysctl nf_hooks_lwtunnel into the netfilter core.
--- include/net/netns/netfilter.h | 3 ++ net/netfilter/core.c | 13 ++++- net/netfilter/nf_conntrack_standalone.c | 15 ------ net/netfilter/nf_hooks_lwtunnel.c | 67 +++++++++++++++++++++++++ net/netfilter/nf_internals.h | 6 +++ 5 files changed, 87 insertions(+), 17 deletions(-)
include/net/netns/netfilter.h +3 -0
@@ -15,6 +15,9 @@ struct netns_nf {const struct nf_logger __rcu *nf_loggers[NFPROTO_NUMPROTO ];#ifdef CONFIG_SYSCTL struct ctl_table_header *nf_log_dir_header; +#ifdef CONFIG_LWTUNNEL +struct ctl_table_header *nf_lwtnl_dir_header; +#endif #endif struct nf_hook_entries __rcu *hooks_ipv4[NF_INET_NUMHOOKS ];struct nf_hook_entries __rcu *hooks_ipv6[NF_INET_NUMHOOKS ];
net/netfilter/core.c +11 -2
@@ -815,12 +815,21 @@ int __init netfilter_init(void)if (ret <0 ) goto err; +#ifdef CONFIG_LWTUNNEL + ret =netfilter_lwtunnel_init (); +if (ret <0 ) + goto err_lwtunnel_pernet; +#endif ret =netfilter_log_init ();if (ret <0 ) - goto err_pernet; + goto err_log_pernet;return 0 ; -err_pernet: +err_log_pernet: +#ifdef CONFIG_LWTUNNEL +netfilter_lwtunnel_fini (); +err_lwtunnel_pernet: +#endifunregister_pernet_subsys (&netfilter_net_ops); err:return ret;
net/netfilter/nf_conntrack_standalone.c +0 -15
@@ -22,9 +22,6 @@#include <net/netfilter/nf_conntrack_acct.h> #include <net/netfilter/nf_conntrack_zones.h> #include <net/netfilter/nf_conntrack_timestamp.h> -#ifdef CONFIG_LWTUNNEL -#include <net/netfilter/nf_hooks_lwtunnel.h> -#endif #include <linux/rculist_nulls.h> static bool enable_hooks__read_mostly ;
@@ -612,9 +609,6 @@ enum nf_ct_sysctl_index {NF_SYSCTL_CT_PROTO_TIMEOUT_GRE ,NF_SYSCTL_CT_PROTO_TIMEOUT_GRE_STREAM , #endif -#ifdef CONFIG_LWTUNNEL -NF_SYSCTL_CT_LWTUNNEL , -#endif NF_SYSCTL_CT_LAST_SYSCTL, };
@@ -946,15 +940,6 @@ static struct ctl_table nf_ct_sysctl_table[] = { .proc_handler = proc_dointvec_jiffies, },#endif -#ifdef CONFIG_LWTUNNEL - [NF_SYSCTL_CT_LWTUNNEL] = { - .procname = "nf_hooks_lwtunnel", - .data = NULL, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = nf_hooks_lwtunnel_sysctl_handler, - }, -#endif }; static struct ctl_table nf_ct_netfilter_table[] = {
net/netfilter/nf_hooks_lwtunnel.c +67 -0
77 lines not on this page · raw message
net/netfilter/nf_internals.h +6 -0
@@ -29,6 +29,12 @@ void nf_queue_nf_hook_drop(struct net *net);/* nf_log.c */ int __init netfilter_log_init (void ); +#ifdef CONFIG_LWTUNNEL +/* nf_hooks_lwtunnel.c */ +int __init netfilter_lwtunnel_init (void ); +void netfilter_lwtunnel_fini (void ); +#endif +/* core.c */ void nf_hook_entries_delete_raw (struct nf_hook_entries __rcu **pp,const struct nf_hook_ops *reg);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/5 selftests: add selftest for the SRv6 End.DX4 behavior with netfilter
In reply to Pablo Neira AyusoFrom: Jianguo Wu <[email protected]>
this selftest is designed for evaluating the SRv6 End.DX4 behavior used with netfilter(rpfilter), in this example, for implementing IPv4 L3 VPN use cases.
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + .../net/srv6_end_dx4_netfilter_test.sh | 335 ++++++++++++++++++ 3 files changed, 337 insertions(+) create mode 100755 tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -43,6 +43,7 @@ TEST_PROGS += srv6_hl2encap_red_l2vpn_test.sh TEST_PROGS += srv6_end_next_csid_l3vpn_test.sh TEST_PROGS += srv6_end_x_next_csid_l3vpn_test.sh TEST_PROGS += srv6_end_flavors_test.sh +TEST_PROGS += srv6_end_dx4_netfilter_test.sh TEST_PROGS += vrf_strict_mode_test.sh TEST_PROGS += arp_ndisc_evict_nocarrier.sh TEST_PROGS += ndisc_unsolicited_na_test.sh
tools/testing/selftests/net/config +1 -0
@@ -101,3 +101,4 @@ CONFIG_NETFILTER_XT_MATCH_POLICY=m CONFIG_CRYPTO_ARIA=y CONFIG_XFRM_INTERFACE=m CONFIG_XFRM_USER=m +CONFIG_IP_NF_MATCH_RPFILTER=m
tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh new file +335 -0
335 lines not on this page · raw message
Signature · 1 line
2.30.2
Paolo Abeni
maintainerRe: [PATCH net 4/5] selftests: add selftest for the SRv6 End.DX4 behavior with netfilter
tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh line 217
Quoted 11 lines · Pablo Neira Ayuso
tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh new file +11
-0+setup_hs() +{ + local hs=$1 + local rt=$2 + local tid=$3 + local hsname=hs-${hs} + local rtname=rt-${rt} + local rtveth=veth-t${tid} + + # set the networking for the host + ip netns add ${hsname}
Side note for a possible follow-up (_not_ intended to block this PR!!!):
If you leverage setup_ns() from lib.sh, you can reduce a bit the code duplication, and the script will avoid any possible netns name conflict.
The same for the following test.
Cheers,
Paolo
Pablo Neira Ayuso
maintainerPATCH 5/5 selftests: add selftest for the SRv6 End.DX6 behavior with netfilter
In reply to Pablo Neira AyusoFrom: Jianguo Wu <[email protected]>
this selftest is designed for evaluating the SRv6 End.DX6 behavior used with netfilter(rpfilter), in this example, for implementing IPv6 L3 VPN use cases.
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 1 + .../net/srv6_end_dx6_netfilter_test.sh | 340 ++++++++++++++++++ 3 files changed, 342 insertions(+) create mode 100755 tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -44,6 +44,7 @@ TEST_PROGS += srv6_end_next_csid_l3vpn_test.sh TEST_PROGS += srv6_end_x_next_csid_l3vpn_test.sh TEST_PROGS += srv6_end_flavors_test.sh TEST_PROGS += srv6_end_dx4_netfilter_test.sh +TEST_PROGS += srv6_end_dx6_netfilter_test.sh TEST_PROGS += vrf_strict_mode_test.sh TEST_PROGS += arp_ndisc_evict_nocarrier.sh TEST_PROGS += ndisc_unsolicited_na_test.sh
tools/testing/selftests/net/config +1 -0
@@ -102,3 +102,4 @@ CONFIG_CRYPTO_ARIA=y CONFIG_XFRM_INTERFACE=m CONFIG_XFRM_USER=m CONFIG_IP_NF_MATCH_RPFILTER=m +CONFIG_IP6_NF_MATCH_RPFILTER=m
tools/testing/selftests/net/srv6_end_dx6_netfilter_test.sh new file +340 -0
340 lines not on this page · raw message
Signature · 1 line
2.30.2