Netfilter fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi David,
The following batch contains netfilter fixes for your net tree, they are:
1) Fix use after free in nfnetlink when sending a batch for some unsupported subsystem, from Denys Fedoryshchenko.
2) Skip autoload of the nat module if no binding is specified via ctnetlink, from Florian Westphal.
3) Set local_df after netfilter defragmentation to avoid a bogus ICMP fragmentation needed in the forwarding path, also from Florian.
4) Fix potential user after free in ip6_route_me_harder() when returning the error code to the upper layers, from Sergey Popovich.
5) Skip possible bogus ICMP time exceeded emitted from the router (not valid according to RFC) if conntrack zones are used, from Vasily Averin.
6) Fix fragment handling when nf_defrag_ipv4 is loaded but nf_conntrack is not present, also from Vasily.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 014f1b20108dc2c0bb0777d8383654a089c790f8:
net: bonding: Fix format string mismatch in bond_sysfs.c (2014-04-28 14:48:16 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
for you to fetch changes up to a8951d5814e1373807a94f79f7ccec7041325470:
netfilter: Fix potential use after free in ip6_route_me_harder() (2014-05-09 02:36:39 +0200)
----------------------------------------------------------------
Denys Fedoryshchenko (1):
netfilter: nfnetlink: Fix use after free when it fails to process batch
Florian Westphal (2):
netfilter: ctnetlink: don't add null bindings if no nat requested
netfilter: ipv4: defrag: set local_df flag on defragmented skb
Sergey Popovich (1):
netfilter: Fix potential use after free in ip6_route_me_harder()
Vasily Averin (2):
ipv4: fix "conntrack zones" support for defrag user check in ip_expire
bridge: superfluous skb->nfct check in br_nf_dev_queue_xmit
net/bridge/br_netfilter.c | 4 ++-- net/ipv4/ip_fragment.c | 5 +++-- net/ipv4/netfilter/nf_defrag_ipv4.c | 5 +++-- net/ipv6/netfilter.c | 6 ++++-- net/netfilter/nf_conntrack_netlink.c | 3 +++ net/netfilter/nfnetlink.c | 8 ++++---- 6 files changed, 19 insertions(+), 12 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/6 netfilter: ctnetlink: don't add null bindings if no nat requested
From: Florian Westphal <[email protected]>
commit 0eba801b64cc8284d9024c7ece30415a2b981a72 tried to fix a race where nat initialisation can happen after ctnetlink-created conntrack has been created.
However, it causes the nat module(s) to be loaded needlessly on systems that are not using NAT.
Fortunately, we do not have to create null bindings in that case.
conntracks injected via ctnetlink always have the CONFIRMED bit set, which prevents addition of the nat extension in nf_nat_ipv4/6_fn().
We only need to make sure that either no nat extension is added or that we've created both src and dst manips.
--- net/netfilter/nf_conntrack_netlink.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nf_conntrack_netlink.c +3 -0
@@ -1336,6 +1336,9 @@ ctnetlink_setup_nat(struct nf_conn *ct, const struct nlattr * const cda[])#ifdef CONFIG_NF_NAT_NEEDED int ret; +if (!cda[CTA_NAT_DST ] && !cda[CTA_NAT_SRC ]) +return 0 ; + ret =ctnetlink_parse_nat_setup (ct,NF_NAT_MANIP_DST , cda[CTA_NAT_DST ]);if (ret <0 )
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/6 netfilter: ipv4: defrag: set local_df flag on defragmented skb
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
else we may fail to forward skb even if original fragments do fit outgoing link mtu:
1. remote sends 2k packets in two 1000 byte frags, DF set
2. we want to forward but only see '2k > mtu and DF set'
3. we then send icmp error saying that outgoing link is 1500
But original sender never sent a packet that would not fit the outgoing link.
Setting local_df makes outgoing path test size vs. IPCB(skb)->frag_max_size, so we will still send the correct error in case the largest original size did not fit outgoing link mtu.
--- net/ipv4/netfilter/nf_defrag_ipv4.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/netfilter/nf_defrag_ipv4.c +3 -2
@@ -22,7 +22,6 @@#endif #include <net/netfilter/nf_conntrack_zones.h> -/* Returns new sk_buff, or NULL */ static int nf_ct_ipv4_gather_frags (struct sk_buff *skb,u_int32_t user) {int err;
@@ -33,8 +32,10 @@ static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user) err =ip_defrag (skb, user);local_bh_enable (); -if (!err) +if (!err) {ip_send_check (ip_hdr (skb)); + skb->local_df =1 ; + }return err; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/6 netfilter: nfnetlink: Fix use after free when it fails to process batch
In reply to Pablo Neira AyusoFrom: Denys Fedoryshchenko <[email protected]>
This bug manifests when calling the nft command line tool without nf_tables kernel support.
kernel message:
[ 44.071555] Netfilter messages via NETLINK v0.30. [ 44.072253] BUG: unable to handle kernel NULL pointer dereference at 0000000000000119 [ 44.072264] IP: [<ffffffff8171db1f>] netlink_getsockbyportid+0xf/0x70 [ 44.072272] PGD 7f2b74067 PUD 7f2b73067 PMD 0 [ 44.072277] Oops: 0000 [#1] SMP [...] [ 44.072369] Call Trace: [ 44.072373] [<ffffffff8171fd81>] netlink_unicast+0x91/0x200 [ 44.072377] [<ffffffff817206c9>] netlink_ack+0x99/0x110 [ 44.072381] [<ffffffffa004b951>] nfnetlink_rcv+0x3c1/0x408 [nfnetlink] [ 44.072385] [<ffffffff8171fde3>] netlink_unicast+0xf3/0x200 [ 44.072389] [<ffffffff817201ef>] netlink_sendmsg+0x2ff/0x740 [ 44.072394] [<ffffffff81044752>] ? __mmdrop+0x62/0x90 [ 44.072398] [<ffffffff816dafdb>] sock_sendmsg+0x8b/0xc0 [ 44.072403] [<ffffffff812f1af5>] ? copy_user_enhanced_fast_string+0x5/0x10 [ 44.072406] [<ffffffff816dbb6c>] ? move_addr_to_kernel+0x2c/0x50 [ 44.072410] [<ffffffff816db423>] ___sys_sendmsg+0x3c3/0x3d0 [ 44.072415] [<ffffffff811301ba>] ? handle_mm_fault+0xa9a/0xc60 [ 44.072420] [<ffffffff811362d6>] ? mmap_region+0x166/0x5a0 [ 44.072424] [<ffffffff817da84c>] ? __do_page_fault+0x1dc/0x510 [ 44.072428] [<ffffffff812b8b2c>] ? apparmor_capable+0x1c/0x60 [ 44.072435] [<ffffffff817d6e9a>] ? _raw_spin_unlock_bh+0x1a/0x20 [ 44.072439] [<ffffffff816dfc86>] ? release_sock+0x106/0x150 [ 44.072443] [<ffffffff816dc212>] __sys_sendmsg+0x42/0x80 [ 44.072446] [<ffffffff816dc262>] SyS_sendmsg+0x12/0x20 [ 44.072450] [<ffffffff817df616>] system_call_fastpath+0x1a/0x1f
--- net/netfilter/nfnetlink.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/netfilter/nfnetlink.c +4 -4
@@ -256,15 +256,15 @@ replay:#endif {nfnl_unlock (subsys_id); -kfree_skb (nskb); -return netlink_ack (skb, nlh, -EOPNOTSUPP ); +netlink_ack (skb, nlh, -EOPNOTSUPP ); +return kfree_skb (nskb); } }if (!ss->commit || !ss->abort) {nfnl_unlock (subsys_id); -kfree_skb (nskb); -return netlink_ack (skb, nlh, -EOPNOTSUPP ); +netlink_ack (skb, nlh, -EOPNOTSUPP ); +return kfree_skb (skb); }while (skb->len >=nlmsg_total_size (0 )) {
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/6 ipv4: fix "conntrack zones" support for defrag user check in ip_expire
In reply to Pablo Neira AyusoFrom: Vasily Averin <[email protected]>
Defrag user check in ip_expire was not updated after adding support for "conntrack zones".
This bug manifests as a RFC violation, since the router will send the icmp time exceeeded message when using conntrack zones.
--- net/ipv4/ip_fragment.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/ip_fragment.c +3 -2
@@ -232,8 +232,9 @@ static void ip_expire(unsigned long arg)* "Fragment Reassembly Timeout" message, per RFC792. */ if (qp->user ==IP_DEFRAG_AF_PACKET || - (qp->user ==IP_DEFRAG_CONNTRACK_IN && -skb_rtable (head)->rt_type !=RTN_LOCAL )) + ((qp->user >=IP_DEFRAG_CONNTRACK_IN ) && + (qp->user <= __IP_DEFRAG_CONNTRACK_IN_END) && + (skb_rtable (head)->rt_type !=RTN_LOCAL ))) goto out_rcu_unlock;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 5/6 bridge: superfluous skb->nfct check in br_nf_dev_queue_xmit
In reply to Pablo Neira AyusoFrom: Vasily Averin <[email protected]>
Currently bridge can silently drop ipv4 fragments.
If node have loaded nf_defrag_ipv4 module but have no nf_conntrack_ipv4, br_nf_pre_routing defragments incoming ipv4 fragments
but nfct check in br_nf_dev_queue_xmit does not allow re-fragment combined packet back, and therefore it is dropped in br_dev_queue_push_xmit without incrementing of any failcounters
It seems the only way to hit the ip_fragment code in the bridge xmit path is to have a fragment list whose reassembled fragments go over the mtu. This only happens if nf_defrag is enabled. Thanks to Florian Westphal for providing feedback to clarify this.
Defragmentation ipv4 is required not only in conntracks but at least in TPROXY target and socket match, therefore #ifdef is changed from NF_CONNTRACK_IPV4 to NF_DEFRAG_IPV4
--- net/bridge/br_netfilter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bridge/br_netfilter.c +2 -2
@@ -859,12 +859,12 @@ static unsigned int br_nf_forward_arp(const struct nf_hook_ops *ops,return NF_STOLEN ; } -#if IS_ENABLED (CONFIG_NF_CONNTRACK_IPV4 ) +#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV4 )static int br_nf_dev_queue_xmit (struct sk_buff *skb) {int ret; -if (skb->nfct !=NULL && skb->protocol ==htons (ETH_P_IP ) && +if (skb->protocol ==htons (ETH_P_IP ) && skb->len +nf_bridge_mtu_reduction (skb) > skb->dev->mtu && !skb_is_gso (skb)) {if (br_parse_ip_options (skb))
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 6/6 netfilter: Fix potential use after free in ip6_route_me_harder()
In reply to Pablo Neira AyusoFrom: Sergey Popovich <[email protected]>
Dst is released one line before we access it again with dst->error.
ip6_route_me_harder()
--- net/ipv6/netfilter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv6/netfilter.c +4 -2
@@ -30,13 +30,15 @@ int ip6_route_me_harder(struct sk_buff *skb) .daddr = iph->daddr, .saddr = iph->saddr, }; +int err; dst =ip6_route_output (net, skb->sk, &fl6); -if (dst->error) { + err = dst->error; +if (err) {IP6_INC_STATS (net,ip6_dst_idev (dst),IPSTATS_MIB_OUTNOROUTES );LIMIT_NETDEBUG (KERN_DEBUG "ip6_route_me_harder: No more route.\n" );dst_release (dst); -return dst->error; +return err; }/* Drop old route. */
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Fri, 9 May 2014 12:56:01 +0200
Quoted 11 lines
The following batch contains netfilter fixes for your net tree, they are:
1) Fix use after free in nfnetlink when sending a batch for some unsupported subsystem, from Denys Fedoryshchenko.
2) Skip autoload of the nat module if no binding is specified via ctnetlink, from Florian Westphal.
3) Set
local_dfafter netfilter defragmentation to avoid a bogus ICMP fragmentation needed in the forwarding path, also from Florian.
Quoted 8 lines
4) Fix potential user after free in
ip6_route_me_harder()when returning the error code to the upper layers, from Sergey Popovich.5) Skip possible bogus ICMP time exceeded emitted from the router (not valid according to RFC) if conntrack zones are used, from Vasily Averin.
6) Fix fragment handling when
nf_defrag_ipv4is loaded butnf_conntrackis not present, also from Vasily.
Pulled, thanks a lot Pablo.