<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/net/ipv4/netfilter, branch v4.8</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v4.8</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v4.8'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2016-09-06T16:02:37Z</updated>
<entry>
<title>netfilter: nft_chain_route: re-route before skb is queued to userspace</title>
<updated>2016-09-06T16:02:37Z</updated>
<author>
<name>Liping Zhang</name>
<email>liping.zhang@spreadtrum.com</email>
</author>
<published>2016-09-06T14:31:02Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d1a6cba576fc7c43e476538fe5aa72fe04bd80e1'/>
<id>urn:sha1:d1a6cba576fc7c43e476538fe5aa72fe04bd80e1</id>
<content type='text'>
Imagine such situation, user add the following nft rules, and queue
the packets to userspace for further check:
  # ip rule add fwmark 0x0/0x1 lookup eth0
  # ip rule add fwmark 0x1/0x1 lookup eth1
  # nft add table filter
  # nft add chain filter output {type route hook output priority 0 \;}
  # nft add rule filter output mark set 0x1
  # nft add rule filter output queue num 0

But after we reinject the skbuff, the packet will be sent via the
wrong route, i.e. in this case, the packet will be routed via eth0
table, not eth1 table. Because we skip to do re-route when verdict
is NF_QUEUE, even if the mark was changed.

Acctually, we should not touch sk_buff if verdict is NF_DROP or
NF_STOLEN, and when re-route fails, return NF_DROP with error code.
This is consistent with the mangle table in iptables.

Signed-off-by: Liping Zhang &lt;liping.zhang@spreadtrum.com&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: nft_reject: restrict to INPUT/FORWARD/OUTPUT</title>
<updated>2016-08-25T10:55:34Z</updated>
<author>
<name>Liping Zhang</name>
<email>liping.zhang@spreadtrum.com</email>
</author>
<published>2016-08-21T17:02:18Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=89e1f6d2b956649fbe0704d543a90b8e0cf872b0'/>
<id>urn:sha1:89e1f6d2b956649fbe0704d543a90b8e0cf872b0</id>
<content type='text'>
After I add the nft rule "nft add rule filter prerouting reject
with tcp reset", kernel panic happened on my system:
  NULL pointer dereference at ...
  IP: [&lt;ffffffff81b9db2f&gt;] nf_send_reset+0xaf/0x400
  Call Trace:
  [&lt;ffffffff81b9da80&gt;] ? nf_reject_ip_tcphdr_get+0x160/0x160
  [&lt;ffffffffa0928061&gt;] nft_reject_ipv4_eval+0x61/0xb0 [nft_reject_ipv4]
  [&lt;ffffffffa08e836a&gt;] nft_do_chain+0x1fa/0x890 [nf_tables]
  [&lt;ffffffffa08e8170&gt;] ? __nft_trace_packet+0x170/0x170 [nf_tables]
  [&lt;ffffffffa06e0900&gt;] ? nf_ct_invert_tuple+0xb0/0xc0 [nf_conntrack]
  [&lt;ffffffffa07224d4&gt;] ? nf_nat_setup_info+0x5d4/0x650 [nf_nat]
  [...]

Because in the PREROUTING chain, routing information is not exist,
then we will dereference the NULL pointer and oops happen.

So we restrict reject expression to INPUT, FORWARD and OUTPUT chain.
This is consistent with iptables REJECT target.

Signed-off-by: Liping Zhang &lt;liping.zhang@spreadtrum.com&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: x_tables: speed up jump target validation</title>
<updated>2016-07-18T19:35:23Z</updated>
<author>
<name>Florian Westphal</name>
<email>fw@strlen.de</email>
</author>
<published>2016-07-14T15:51:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f4dc77713f8016d2e8a3295e1c9c53a21f296def'/>
<id>urn:sha1:f4dc77713f8016d2e8a3295e1c9c53a21f296def</id>
<content type='text'>
The dummy ruleset I used to test the original validation change was broken,
most rules were unreachable and were not tested by mark_source_chains().

In some cases rulesets that used to load in a few seconds now require
several minutes.

sample ruleset that shows the behaviour:

echo "*filter"
for i in $(seq 0 100000);do
        printf ":chain_%06x - [0:0]\n" $i
done
for i in $(seq 0 100000);do
   printf -- "-A INPUT -j chain_%06x\n" $i
   printf -- "-A INPUT -j chain_%06x\n" $i
   printf -- "-A INPUT -j chain_%06x\n" $i
done
echo COMMIT

[ pipe result into iptables-restore ]

This ruleset will be about 74mbyte in size, with ~500k searches
though all 500k[1] rule entries. iptables-restore will take forever
(gave up after 10 minutes)

Instead of always searching the entire blob for a match, fill an
array with the start offsets of every single ipt_entry struct,
then do a binary search to check if the jump target is present or not.

After this change ruleset restore times get again close to what one
gets when reverting 36472341017529e (~3 seconds on my workstation).

[1] every user-defined rule gets an implicit RETURN, so we get
300k jumps + 100k userchains + 100k returns -&gt; 500k rule entries

Fixes: 36472341017529e ("netfilter: x_tables: validate targets of jumps")
Reported-by: Jeff Wu &lt;wujiafu@gmail.com&gt;
Tested-by: Jeff Wu &lt;wujiafu@gmail.com&gt;
Signed-off-by: Florian Westphal &lt;fw@strlen.de&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: conntrack: fix race between nf_conntrack proc read and hash resize</title>
<updated>2016-07-11T09:38:57Z</updated>
<author>
<name>Liping Zhang</name>
<email>liping.zhang@spreadtrum.com</email>
</author>
<published>2016-07-03T05:18:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=64b87639c9cbeb03e26bc65528416c961b1dde96'/>
<id>urn:sha1:64b87639c9cbeb03e26bc65528416c961b1dde96</id>
<content type='text'>
When we do "cat /proc/net/nf_conntrack", and meanwhile resize the conntrack
hash table via /sys/module/nf_conntrack/parameters/hashsize, race will
happen, because reader can observe a newly allocated hash but the old size
(or vice versa). So oops will happen like follows：

  BUG: unable to handle kernel NULL pointer dereference at 0000000000000017
  IP: [&lt;ffffffffa0418e21&gt;] seq_print_acct+0x11/0x50 [nf_conntrack]
  Call Trace:
  [&lt;ffffffffa0412f4e&gt;] ? ct_seq_show+0x14e/0x340 [nf_conntrack]
  [&lt;ffffffff81261a1c&gt;] seq_read+0x2cc/0x390
  [&lt;ffffffff812a8d62&gt;] proc_reg_read+0x42/0x70
  [&lt;ffffffff8123bee7&gt;] __vfs_read+0x37/0x130
  [&lt;ffffffff81347980&gt;] ? security_file_permission+0xa0/0xc0
  [&lt;ffffffff8123cf75&gt;] vfs_read+0x95/0x140
  [&lt;ffffffff8123e475&gt;] SyS_read+0x55/0xc0
  [&lt;ffffffff817c2572&gt;] entry_SYSCALL_64_fastpath+0x1a/0xa4

It is very easy to reproduce this kernel crash.
1. open one shell and input the following cmds:
  while : ; do
    echo $RANDOM &gt; /sys/module/nf_conntrack/parameters/hashsize
  done
2. open more shells and input the following cmds:
  while : ; do
    cat /proc/net/nf_conntrack
  done
3. just wait a monent, oops will happen soon.

The solution in this patch is based on Florian's Commit 5e3c61f98175
("netfilter: conntrack: fix lookup race during hash resize"). And
add a wrapper function nf_conntrack_get_ht to get hash and hsize
suggested by Florian Westphal.

Signed-off-by: Liping Zhang &lt;liping.zhang@spreadtrum.com&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: Convert FWINV&lt;[foo]&gt; macros and uses to NF_INVF</title>
<updated>2016-07-03T08:55:07Z</updated>
<author>
<name>Joe Perches</name>
<email>joe@perches.com</email>
</author>
<published>2016-06-24T20:25:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c37a2dfa67f7920b14ea77dc9f9f9660f7a1f6dd'/>
<id>urn:sha1:c37a2dfa67f7920b14ea77dc9f9f9660f7a1f6dd</id>
<content type='text'>
netfilter uses multiple FWINV #defines with identical form that hide a
specific structure variable and dereference it with a invflags member.

$ git grep "#define FWINV"
include/linux/netfilter_bridge/ebtables.h:#define FWINV(bool,invflg) ((bool) ^ !!(info-&gt;invflags &amp; invflg))
net/bridge/netfilter/ebtables.c:#define FWINV2(bool, invflg) ((bool) ^ !!(e-&gt;invflags &amp; invflg))
net/ipv4/netfilter/arp_tables.c:#define FWINV(bool, invflg) ((bool) ^ !!(arpinfo-&gt;invflags &amp; (invflg)))
net/ipv4/netfilter/ip_tables.c:#define FWINV(bool, invflg) ((bool) ^ !!(ipinfo-&gt;invflags &amp; (invflg)))
net/ipv6/netfilter/ip6_tables.c:#define FWINV(bool, invflg) ((bool) ^ !!(ip6info-&gt;invflags &amp; (invflg)))
net/netfilter/xt_tcpudp.c:#define FWINVTCP(bool, invflg) ((bool) ^ !!(tcpinfo-&gt;invflags &amp; (invflg)))

Consolidate these macros into a single NF_INVF macro.

Miscellanea:

o Neaten the alignment around these uses
o A few lines are &gt; 80 columns for intelligibility

Signed-off-by: Joe Perches &lt;joe@perches.com&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: x_tables: simplify ip{6}table_mangle_hook()</title>
<updated>2016-07-01T14:37:02Z</updated>
<author>
<name>Pablo Neira Ayuso</name>
<email>pablo@netfilter.org</email>
</author>
<published>2016-06-24T17:48:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=468b021b944922e8fe0a30b6b6e0532bb95e4edc'/>
<id>urn:sha1:468b021b944922e8fe0a30b6b6e0532bb95e4edc</id>
<content type='text'>
No need for a special case to handle NF_INET_POST_ROUTING, this is
basically the same handling as for prerouting, input, forward.

Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP</title>
<updated>2016-06-24T09:03:22Z</updated>
<author>
<name>Liping Zhang</name>
<email>liping.zhang@spreadtrum.com</email>
</author>
<published>2016-06-20T13:26:28Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=e1dbbc5907b53d8d53c009b3cb3dd2a0366ce45c'/>
<id>urn:sha1:e1dbbc5907b53d8d53c009b3cb3dd2a0366ce45c</id>
<content type='text'>
In iptables, if the user add a rule to send tcp RST and specify the
non-TCP protocol, such as UDP, kernel will reject this request. But
in nftables, this validity check only occurs in nft tool, i.e. only
in userspace.

This means that user can add such a rule like follows via nfnetlink:
  "nft add rule filter forward ip protocol udp reject with tcp reset"

This will generate some confusing tcp RST packets. So we should send
tcp RST only when it is TCP packet.

Signed-off-by: Liping Zhang &lt;liping.zhang@spreadtrum.com&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: conntrack: use a single expectation table for all namespaces</title>
<updated>2016-05-06T09:50:01Z</updated>
<author>
<name>Florian Westphal</name>
<email>fw@strlen.de</email>
</author>
<published>2016-05-05T22:51:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0a93aaedc46af2c5feecfb1066d98bfb491ec0b8'/>
<id>urn:sha1:0a93aaedc46af2c5feecfb1066d98bfb491ec0b8</id>
<content type='text'>
We already include netns address in the hash and compare the netns pointers
during lookup, so even if namespaces have overlapping addresses entries
will be spread across the expectation table.

Signed-off-by: Florian Westphal &lt;fw@strlen.de&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: conntrack: check netns when walking expect hash</title>
<updated>2016-05-06T09:50:01Z</updated>
<author>
<name>Florian Westphal</name>
<email>fw@strlen.de</email>
</author>
<published>2016-05-05T22:51:47Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=03d7dc5cdfe6fd4e5bd04cfc2be7ae259f956428'/>
<id>urn:sha1:03d7dc5cdfe6fd4e5bd04cfc2be7ae259f956428</id>
<content type='text'>
Signed-off-by: Florian Westphal &lt;fw@strlen.de&gt;
Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
<entry>
<title>netfilter: x_tables: get rid of old and inconsistent debugging</title>
<updated>2016-05-05T14:39:51Z</updated>
<author>
<name>Pablo Neira Ayuso</name>
<email>pablo@netfilter.org</email>
</author>
<published>2016-05-03T11:54:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d7cdf81657776ca1aa8377fd84d02fd8774db483'/>
<id>urn:sha1:d7cdf81657776ca1aa8377fd84d02fd8774db483</id>
<content type='text'>
The dprintf() and duprintf() functions are enabled at compile time,
these days we have better runtime debugging through pr_debug() and
static keys.

On top of this, this debugging is so old that I don't expect anyone
using this anymore, so let's get rid of this.

IP_NF_ASSERT() is still left in place, although this needs that
NETFILTER_DEBUG is enabled, I think these assertions provide useful
context information when reading the code.

Note that ARP_NF_ASSERT() has been removed as there is no user of
this.

Kill also DEBUG_ALLOW_ALL and a couple of pr_error() and pr_debug()
spots that are inconsistently placed in the code.

Signed-off-by: Pablo Neira Ayuso &lt;pablo@netfilter.org&gt;
</content>
</entry>
</feed>
