Netfilter fixes for net
Subsystems (3)
Pablo Neira Ayuso
maintainercover Netfilter fixes for net
Hi David,
The following patchset contains Netfilter fixes for your net tree, they are:
1) Fix crash when TEE target is used with no --oif, from Eric Dumazet.
2) Oneliner to fix a crash on the redirect traffic to localhost infrastructure when interface has not yet an address, from Munehisa Kamata.
3) Oneliner not to request module all the time from nfnetlink due to wrong type value, from Florian Westphal.
I'll make sure these patches 1 and 2 hit -stable.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 104eb270e665f4fcd8cb8c8ab4c4d4538c604e92:
net: sun4i-emac: Properly free resources on probe failure and remove (2015-10-21 19:47:45 -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 dbc3617f4c1f9fcbe63612048cb9583fea1e11ab:
netfilter: nfnetlink: don't probe module if it exists (2015-10-28 03:40:50 +0100)
----------------------------------------------------------------
Eric Dumazet (1):
netfilter: xt_TEE: fix NULL dereference
Florian Westphal (1):
netfilter: nfnetlink: don't probe module if it exists
Munehisa Kamata (1):
netfilter: nf_nat_redirect: add missing NULL pointer check
net/netfilter/nf_nat_redirect.c | 2 +- net/netfilter/nfnetlink.c | 2 +- net/netfilter/xt_TEE.c | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: xt_TEE: fix NULL dereference
From: Eric Dumazet <[email protected]>
iptables -I INPUT ... -j TEE --gateway 10.1.2.3
<crash> because --oif was not specified
tee_tg_check() sets ->priv pointer to NULL in this case.
--- net/netfilter/xt_TEE.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/netfilter/xt_TEE.c +4 -2
@@ -31,8 +31,9 @@ static unsigned int tee_tg4(struct sk_buff *skb, const struct xt_action_param *par) { const struct xt_tee_tginfo *info = par->targinfo; +int oif = info->priv ? info->priv->oif :0 ; -nf_dup_ipv4 (skb, par->hooknum, &info->gw.in, info->priv->oif); +nf_dup_ipv4 (skb, par->hooknum, &info->gw.in, oif);return XT_CONTINUE ; }
@@ -42,8 +43,9 @@ static unsigned int tee_tg6(struct sk_buff *skb, const struct xt_action_param *par) { const struct xt_tee_tginfo *info = par->targinfo; +int oif = info->priv ? info->priv->oif :0 ; -nf_dup_ipv6 (skb, par->hooknum, &info->gw.in6, info->priv->oif); +nf_dup_ipv6 (skb, par->hooknum, &info->gw.in6, oif);return XT_CONTINUE ; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nf_nat_redirect: add missing NULL pointer check
In reply to Pablo Neira AyusoFrom: Munehisa Kamata <[email protected]>
Commit 8b13eddfdf04cbfa561725cfc42d6868fe896f56 ("netfilter: refactor NAT redirect IPv4 to use it from nf_tables") has introduced a trivial logic change which can result in the following crash.
BUG: unable to handle kernel NULL pointer dereference at 0000000000000030 IP: [<ffffffffa033002d>] nf_nat_redirect_ipv4+0x2d/0xa0 [nf_nat_redirect] PGD 3ba662067 PUD 3ba661067 PMD 0 Oops: 0000 [#1] SMP Modules linked in: ipv6(E) xt_REDIRECT(E) nf_nat_redirect(E) xt_tcpudp(E) iptable_nat(E) nf_conntrack_ipv4(E) nf_defrag_ipv4(E) nf_nat_ipv4(E) nf_nat(E) nf_conntrack(E) ip_tables(E) x_tables(E) binfmt_misc(E) xfs(E) libcrc32c(E) evbug(E) evdev(E) psmouse(E) i2c_piix4(E) i2c_core(E) acpi_cpufreq(E) button(E) ext4(E) crc16(E) jbd2(E) mbcache(E) dm_mirror(E) dm_region_hash(E) dm_log(E) dm_mod(E) CPU: 0 PID: 2536 Comm: ip Tainted: G E 4.1.7-15.23.amzn1.x86_64 #1 Hardware name: Xen HVM domU, BIOS 4.2.amazon 05/06/2015 task: ffff8800eb438000 ti: ffff8803ba664000 task.ti: ffff8803ba664000 [...] Call Trace: <IRQ> [<ffffffffa0334065>] redirect_tg4+0x15/0x20 [xt_REDIRECT] [<ffffffffa02e2e99>] ipt_do_table+0x2b9/0x5e1 [ip_tables] [<ffffffffa0328045>] iptable_nat_do_chain+0x25/0x30 [iptable_nat] [<ffffffffa031777d>] nf_nat_ipv4_fn+0x13d/0x1f0 [nf_nat_ipv4] [<ffffffffa0328020>] ? iptable_nat_ipv4_fn+0x20/0x20 [iptable_nat] [<ffffffffa031785e>] nf_nat_ipv4_in+0x2e/0x90 [nf_nat_ipv4] [<ffffffffa03280a5>] iptable_nat_ipv4_in+0x15/0x20 [iptable_nat] [<ffffffff81449137>] nf_iterate+0x57/0x80 [<ffffffff814491f7>] nf_hook_slow+0x97/0x100 [<ffffffff814504d4>] ip_rcv+0x314/0x400
unsigned int
nf_nat_redirect_ipv4(struct sk_buff *skb,
...
{
...
rcu_read_lock();
indev = __in_dev_get_rcu(skb->dev);
if (indev != NULL) {
ifa = indev->ifa_list;
newdst = ifa->ifa_local; <---
}
rcu_read_unlock();...
}
Before the commit, 'ifa' had been always checked before access. After the commit, however, it could be accessed even if it's NULL. Interestingly, this was once fixed in 2003.
http://marc.info/?l=netfilter-devel&m=106668497403047&w=2
In addition to the original one, we have seen the crash when packets that need to be redirected somehow arrive on an interface which hasn't been yet fully configured.
This change just reverts the logic to the old behavior to avoid the crash.
--- net/netfilter/nf_nat_redirect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_nat_redirect.c +1 -1
@@ -55,7 +55,7 @@ nf_nat_redirect_ipv4(struct sk_buff *skb,rcu_read_lock (); indev =__in_dev_get_rcu (skb->dev); -if (indev !=NULL ) { +if (indev && indev->ifa_list) { ifa = indev->ifa_list; newdst = ifa->ifa_local; }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: nfnetlink: don't probe module if it exists
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
nfnetlink_bind request_module()s all the time as nfnetlink_get_subsys() shifts the argument by 8 to obtain the subsys id.
So using type instead of type << 8 always returns NULL.
--- net/netfilter/nfnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink.c +1 -1
@@ -492,7 +492,7 @@ static int nfnetlink_bind(struct net *net, int group) type = nfnl_group2type[group];rcu_read_lock (); - ss =nfnetlink_get_subsys (type); + ss =nfnetlink_get_subsys (type <<8 );rcu_read_unlock ();if (!ss)request_module ("nfnetlink-subsys-%d" , type);
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 4 Nov 2015 15:00:35 +0100
Quoted 5 lines
The following patchset contains Netfilter fixes for your net tree, they are:
1) Fix crash when TEE target is used with no --oif, from Eric Dumazet.
Quoted 8 lines
2) Oneliner to fix a crash on the redirect traffic to localhost infrastructure when interface has not yet an address, from Munehisa Kamata.
3) Oneliner not to request module all the time from nfnetlink due to wrong type value, from Florian Westphal.
I'll make sure these patches 1 and 2 hit -stable.
Pulled.
Since net-next got merged, and I fast-forwarded net to Linus's tree, there were some minor conflicts.
Please double check my work.
Thanks.