From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-10-21 10:08:29
Hi,
The following patchset contains Netfilter fixes for net:
1) Crash due to missing initialization of timer data in
xt_IDLETIMER, from Juhee Kang.
2) NF_CONNTRACK_SECMARK should be bool in Kconfig, from Vegard Nossum.
3) Skip netdev events on netns removal, from Florian Westphal.
4) Add testcase to show port shadowing via UDP, also from Florian.
5) Remove pr_debug() code in ip6t_rt, this fixes a crash due to
unsafe access to non-linear skbuff, from Xin Long.
6) Make net/ipv4/vs/debug_level read-only from non-init netns,
from Antoine Tenart.
7) Remove bogus invocation to bash in selftests/netfilter/nft_flowtable.sh
also from Florian.
There will be a relatively simple conflict between net-next and net
after this pull-request, as reported by Stephen Rothwell.
diff --cc net/netfilter/ipvs/ip_vs_ctl.c
index 29ec3ef63edc,cbea5a68afb5..000000000000
@@@ -4090,11 -4096,8 +4096,13 @@@ static int __net_init ip_vs_control_net
tbl[idx++].data = &ipvs->sysctl_conn_reuse_mode;
tbl[idx++].data = &ipvs->sysctl_schedule_icmp;
tbl[idx++].data = &ipvs->sysctl_ignore_tunneled;
+ ipvs->sysctl_run_estimation = 1;
+ tbl[idx++].data = &ipvs->sysctl_run_estimation;
+#ifdef CONFIG_IP_VS_DEBUG
+ /* Global sysctls must be ro in non-init netns */
+ if (!net_eq(net, &init_net))
+ tbl[idx++].mode = 0444;
+#endif
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks.
----------------------------------------------------------------
The following changes since commit 8d6c414cd2fb74aa6812e9bfec6178f8246c4f3a:
net: prefer socket bound to interface when not in VRF (2021-10-07 07:27:55 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD
for you to fetch changes up to d9aaaf223297f6146d9d7f36caca927c92ab855a:
netfilter: ebtables: allocate chainstack on CPU local nodes (2021-10-18 00:23:57 +0200)
----------------------------------------------------------------
Antoine Tenart (1):
netfilter: ipvs: make global sysctl readonly in non-init netns
Davidlohr Bueso (1):
netfilter: ebtables: allocate chainstack on CPU local nodes
Florian Westphal (3):
netfilter: nf_tables: skip netdev events generated on netns removal
selftests: nft_nat: add udp hole punch test case
selftests: netfilter: remove stray bash debug line
Juhee Kang (1):
netfilter: xt_IDLETIMER: fix panic that occurs when timer_type has garbage value
Vegard Nossum (1):
netfilter: Kconfig: use 'default y' instead of 'm' for bool config option
Xin Long (1):
netfilter: ip6t_rt: fix rt0_hdr parsing in rt_mt6
net/bridge/netfilter/ebtables.c | 4 +-
net/ipv6/netfilter/ip6t_rt.c | 48 +------
net/netfilter/Kconfig | 2 +-
net/netfilter/ipvs/ip_vs_ctl.c | 5 +
net/netfilter/nft_chain_filter.c | 9 +-
net/netfilter/xt_IDLETIMER.c | 2 +-
tools/testing/selftests/netfilter/nft_flowtable.sh | 1 -
tools/testing/selftests/netfilter/nft_nat.sh | 145 +++++++++++++++++++++
8 files changed, 164 insertions(+), 52 deletions(-)
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-10-21 10:08:31
From: Vegard Nossum <redacted>
This option, NF_CONNTRACK_SECMARK, is a bool, so it can never be 'm'.
Fixes: 33b8e77605620 ("[NETFILTER]: Add CONFIG_NETFILTER_ADVANCED option")
Signed-off-by: Vegard Nossum <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-10-21 10:08:34
From: Florian Westphal <fw@strlen.de>
syzbot reported following (harmless) WARN:
WARNING: CPU: 1 PID: 2648 at net/netfilter/core.c:468
nft_netdev_unregister_hooks net/netfilter/nf_tables_api.c:230 [inline]
nf_tables_unregister_hook include/net/netfilter/nf_tables.h:1090 [inline]
__nft_release_basechain+0x138/0x640 net/netfilter/nf_tables_api.c:9524
nft_netdev_event net/netfilter/nft_chain_filter.c:351 [inline]
nf_tables_netdev_event+0x521/0x8a0 net/netfilter/nft_chain_filter.c:382
reproducer:
unshare -n bash -c 'ip link add br0 type bridge; nft add table netdev t ; \
nft add chain netdev t ingress \{ type filter hook ingress device "br0" \
priority 0\; policy drop\; \}'
Problem is that when netns device exit hooks create the UNREGISTER
event, the .pre_exit hook for nf_tables core has already removed the
base hook. Notifier attempts to do this again.
The need to do base hook unregister unconditionally was needed in the past,
because notifier was last stage where reg->dev dereference was safe.
Now that nf_tables does the hook removal in .pre_exit, this isn't
needed anymore.
Reported-and-tested-by: syzbot+154bd5be532a63aa778b@syzkaller.appspotmail.com
Fixes: 767d1216bff825 ("netfilter: nftables: fix possible UAF over chains from packet path in netns")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nft_chain_filter.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
@@ -342,12 +342,6 @@ static void nft_netdev_event(unsigned long event, struct net_device *dev,return;}-/* UNREGISTER events are also happening on netns exit.-*-*Althoughnf_tablescorereleasesalltables/chains,onlythisevent-*handlerprovidesguaranteethathook->ops.devisstillaccessible,-*sowecannotskipexitingnetnamespaces.-*/__nft_release_basechain(ctx);}
@@ -366,6 +360,9 @@ static int nf_tables_netdev_event(struct notifier_block *this,event!=NETDEV_CHANGENAME)returnNOTIFY_DONE;+if(!check_net(ctx.net))+returnNOTIFY_DONE;+nft_net=nft_pernet(ctx.net);mutex_lock(&nft_net->commit_mutex);list_for_each_entry(table,&nft_net->tables,list){
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-10-21 10:08:36
From: Florian Westphal <fw@strlen.de>
Add a test case that demonstrates port shadowing via UDP.
ns2 sends packet to ns1, from source port used by a udp service on the
router, ns0. Then, ns1 sends packet to ns0:service, but that ends up getting
forwarded to ns2.
Also add three test cases that demonstrate mitigations:
1. disable use of $port as source from 'unstrusted' origin
2. make the service untracked. This prevents masquerade entries
from having any effects.
3. add forced PAT via 'random' mode to translate the "wrong" sport
into an acceptable range.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tools/testing/selftests/netfilter/nft_nat.sh | 145 +++++++++++++++++++
1 file changed, 145 insertions(+)
@@ -741,6 +741,149 @@ EOFreturn$lret}+# test port shadowing.+# create two listening services, one on router (ns0), one+# on client (ns2), which is masqueraded from ns1 point of view.+# ns2 sends udp packet coming from service port to ns1, on a highport.+# Later, if n1 uses same highport to connect to ns0:service, packet+# might be port-forwarded to ns2 instead.++# second argument tells if we expect the 'fake-entry' to take effect+# (CLIENT) or not (ROUTER).+test_port_shadow()+{+localtest=$1+localexpect=$2+localdaddrc="10.0.1.99"+localdaddrs="10.0.1.1"+localresult=""+locallogmsg=""++echoROUTER|ipnetnsexec"$ns0"nc-w5-u-l-p1405>/dev/null2>&1&+nc_r=$!++echoCLIENT|ipnetnsexec"$ns2"nc-w5-u-l-p1405>/dev/null2>&1&+nc_c=$!++# make shadow entry, from client (ns2), going to (ns1), port 41404, sport 1405.+echo"fake-entry"|ipnetnsexec"$ns2"nc-w1-p1405-u"$daddrc"41404>/dev/null++# ns1 tries to connect to ns0:1405. With default settings this should connect+# to client, it matches the conntrack entry created above.++result=$(echo""|ipnetnsexec"$ns1"nc-w1-p41404-u"$daddrs"1405)++if["$result"="$expect"];then+echo"PASS: portshadow test $test: got reply from ${expect}${logmsg}"+else+echo"ERROR: portshadow test $test: got reply from \"$result\", not $expect as intended"+ret=1+fi++kill$nc_r$nc_c2>/dev/null++# flush udp entries for next test round, if any+ipnetnsexec"$ns0"conntrack-F>/dev/null2>&1+}++# This prevents port shadow of router service via packet filter,+# packets claiming to originate from service port from internal+# network are dropped.+test_port_shadow_filter()+{+localfamily=$1++ipnetnsexec"$ns0"nft-f/dev/stdin<<EOF+table$familyfilter{+chainforward{+typefilterhookforwardpriority0;policyaccept;+metaiifveth1udpsport1405drop+}+}+EOF+test_port_shadow"port-filter""ROUTER"++ipnetnsexec"$ns0"nftdeletetable$familyfilter+}++# This prevents port shadow of router service via notrack.+test_port_shadow_notrack()+{+localfamily=$1++ipnetnsexec"$ns0"nft-f/dev/stdin<<EOF+table$familyraw{+chainprerouting{+typefilterhookpreroutingpriority-300;policyaccept;+metaiifveth0udpdport1405notrack+udpdport1405notrack+}+chainoutput{+typefilterhookoutputpriority-300;policyaccept;+udpsport1405notrack+}+}+EOF+test_port_shadow"port-notrack""ROUTER"++ipnetnsexec"$ns0"nftdeletetable$familyraw+}++# This prevents port shadow of router service via sport remap.+test_port_shadow_pat()+{+localfamily=$1++ipnetnsexec"$ns0"nft-f/dev/stdin<<EOF+table$familypat{+chainpostrouting{+typenathookpostroutingpriority-1;policyaccept;+metaiifveth1udpsport<=1405masqueradeto:1406-65535random+}+}+EOF+test_port_shadow"pat""ROUTER"++ipnetnsexec"$ns0"nftdeletetable$familypat+}++test_port_shadowing()+{+localfamily="ip"++ipnetnsexec"$ns0"sysctlnet.ipv4.conf.veth0.forwarding=1>/dev/null+ipnetnsexec"$ns0"sysctlnet.ipv4.conf.veth1.forwarding=1>/dev/null++ipnetnsexec"$ns0"nft-f/dev/stdin<<EOF+table$familynat{+chainpostrouting{+typenathookpostroutingpriority0;policyaccept;+metaoifveth0masquerade+}+}+EOF+if[$?-ne0];then+echo"SKIP: Could not add add $family masquerade hook"+return$ksft_skip+fi++# test default behaviour. Packet from ns1 to ns0 is redirected to ns2.+test_port_shadow"default""CLIENT"++# test packet filter based mitigation: prevent forwarding of+# packets claiming to come from the service port.+test_port_shadow_filter"$family"++# test conntrack based mitigation: connections going or coming+# from router:service bypass connection tracking.+test_port_shadow_notrack"$family"++# test nat based mitigation: fowarded packets coming from service port+# are masqueraded with random highport.+test_port_shadow_pat"$family"++ipnetnsexec"$ns0"nftdeletetable$familynat+}# ip netns exec "$ns0" ping -c 1 -q 10.0.$i.99foriin012;do
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-10-21 10:08:37
From: Antoine Tenart <atenart@kernel.org>
Because the data pointer of net/ipv4/vs/debug_level is not updated per
netns, it must be marked as read-only in non-init netns.
Fixes: c6d2d445d8de ("IPVS: netns, final patch enabling network name space.")
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/ipvs/ip_vs_ctl.c | 5 +++++
1 file changed, 5 insertions(+)
@@ -4090,6 +4090,11 @@ static int __net_init ip_vs_control_net_init_sysctl(struct netns_ipvs *ipvs)tbl[idx++].data=&ipvs->sysctl_conn_reuse_mode;tbl[idx++].data=&ipvs->sysctl_schedule_icmp;tbl[idx++].data=&ipvs->sysctl_ignore_tunneled;+#ifdef CONFIG_IP_VS_DEBUG+/* Global sysctls must be ro in non-init netns */+if(!net_eq(net,&init_net))+tbl[idx++].mode=0444;+#endifipvs->sysctl_hdr=register_net_sysctl(net,"net/ipv4/vs",tbl);if(ipvs->sysctl_hdr==NULL){
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-10-21 10:08:37
From: Xin Long <lucien.xin@gmail.com>
In rt_mt6(), when it's a nonlinear skb, the 1st skb_header_pointer()
only copies sizeof(struct ipv6_rt_hdr) to _route that rh points to.
The access by ((const struct rt0_hdr *)rh)->reserved will overflow
the buffer. So this access should be moved below the 2nd call to
skb_header_pointer().
Besides, after the 2nd skb_header_pointer(), its return value should
also be checked, othersize, *rp may cause null-pointer-ref.
v1->v2:
- clean up some old debugging log.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Dan Carpenter <redacted>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/ipv6/netfilter/ip6t_rt.c | 48 +++++-------------------------------
1 file changed, 6 insertions(+), 42 deletions(-)
Hello:
This series was applied to netdev/net.git (master)
by Pablo Neira Ayuso [off-list ref]:
On Thu, 21 Oct 2021 12:08:14 +0200 you wrote:
From: Juhee Kang <redacted>
Currently, when the rule related to IDLETIMER is added, idletimer_tg timer
structure is initialized by kmalloc on executing idletimer_tg_create
function. However, in this process timer->timer_type is not defined to
a specific value. Thus, timer->timer_type has garbage value and it occurs
kernel panic. So, this commit fixes the panic by initializing
timer->timer_type using kzalloc instead of kmalloc.
[...]