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) Conntrack SCTP CRC32c checksum mangling may operate on non-linear skbuff, patch from Davide Caratti.
2) nf_tables rb-tree set backend does not handle element re-addition after deletion in the same transaction, leading to infinite loop.
3) Atomically unclear the IPS_SRC_NAT_DONE_BIT on nat module removal, from Liping Zhang.
4) Conntrack hashtable resizing while ctnetlink dump is progress leads to a dead reference to released objects in the lists, also from Liping.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks!
----------------------------------------------------------------
The following changes since commit 6d18c732b95c0a9d35e9f978b4438bba15412284:
bridge: start hello_timer when enabling KERNEL_STP in br_stp_start (2017-05-21 13:33:28 -0400)
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 fefa92679dbe0c613e62b6c27235dcfbe9640ad1:
netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize (2017-05-24 11:26:01 +0200)
----------------------------------------------------------------
Davide Caratti (1):
netfilter: conntrack: fix false CRC32c mismatch using paged skb
Liping Zhang (2):
netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT
netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize
Pablo Neira Ayuso (1):
netfilter: nft_set_rbtree: handle element re-addition after deletion
net/netfilter/nf_conntrack_netlink.c | 7 ++++++- net/netfilter/nf_conntrack_proto_sctp.c | 9 ++++++--- net/netfilter/nf_nat_core.c | 2 +- net/netfilter/nft_set_rbtree.c | 22 +++++++++++----------- 4 files changed, 24 insertions(+), 16 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/4 netfilter: conntrack: fix false CRC32c mismatch using paged skb
From: Davide Caratti <[email protected]>
sctp_compute_cksum() implementation assumes that at least the SCTP header is in the linear part of skb: modify conntrack error callback to avoid false CRC32c mismatch, if the transport header is partially/entirely paged.
--- net/netfilter/nf_conntrack_proto_sctp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +6 -3
@@ -512,16 +512,19 @@ static int sctp_error(struct net *net, struct nf_conn *tpl, struct sk_buff *skb, u8 pf, unsigned int hooknum) {const struct sctphdr *sh; -struct sctphdr _sctph;const char *logmsg; - sh =skb_header_pointer (skb, dataoff,sizeof (_sctph), &_sctph); -if (!sh) { +if (skb->len < dataoff +sizeof (struct sctphdr )) { logmsg ="nf_ct_sctp: short packet " ; goto out_invalid; }if (net->ct.sysctl_checksum && hooknum ==NF_INET_PRE_ROUTING && skb->ip_summed ==CHECKSUM_NONE ) { +if (!skb_make_writable (skb, dataoff +sizeof (struct sctphdr ))) { + logmsg ="nf_ct_sctp: failed to read header " ; + goto out_invalid; + } + sh = (const struct sctphdr *)(skb->data + dataoff);if (sh->checksum !=sctp_compute_cksum (skb, dataoff)) { logmsg ="nf_ct_sctp: bad CRC " ; goto out_invalid;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 2/4 netfilter: nft_set_rbtree: handle element re-addition after deletion
In reply to Pablo Neira AyusoThe existing code selects no next branch to be inspected when re-inserting an inactive element into the rb-tree, looping endlessly. This patch restricts the check for active elements to the EEXIST case only.
--- net/netfilter/nft_set_rbtree.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
net/netfilter/nft_set_rbtree.c +11 -11
@@ -116,17 +116,17 @@ static int __nft_rbtree_insert(const struct net *net, const struct nft_set *set,else if (d >0 ) p = &parent->rb_right;else { -if (nft_set_elem_active (&rbe->ext, genmask)) { -if (nft_rbtree_interval_end (rbe) && - !nft_rbtree_interval_end (new)) - p = &parent->rb_left; -else if (!nft_rbtree_interval_end (rbe) && -nft_rbtree_interval_end (new)) - p = &parent->rb_right; -else { - *ext = &rbe->ext; -return -EEXIST ; - } +if (nft_rbtree_interval_end (rbe) && + !nft_rbtree_interval_end (new)) { + p = &parent->rb_left; + }else if (!nft_rbtree_interval_end (rbe) && +nft_rbtree_interval_end (new)) { + p = &parent->rb_right; + }else if (nft_set_elem_active (&rbe->ext, genmask)) { + *ext = &rbe->ext; +return -EEXIST ; + }else { + p = &parent->rb_left; } } }
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 3/4 netfilter: nat: use atomic bit op to clear the _SRC_NAT_DONE_BIT
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
We need to clear the IPS_SRC_NAT_DONE_BIT to indicate that the ct has been removed from nat_bysource table. But unfortunately, we use the non-atomic bit operation: "ct->status &= ~IPS_NAT_DONE_MASK". So there's a race condition that we may clear the _DYING_BIT set by another CPU unexpectedly.
Since we don't care about the IPS_DST_NAT_DONE_BIT, so just using clear_bit to clear the IPS_SRC_NAT_DONE_BIT is enough.
Also note, this is the last user which use the non-atomic bit operation to update the confirmed ct->status.
--- net/netfilter/nf_nat_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_nat_core.c +1 -1
@@ -566,7 +566,7 @@ static int nf_nat_proto_clean(struct nf_conn *ct, void *data)* Else, when the conntrack is destoyed, nf_nat_cleanup_conntrack() * will delete entry from already-freed table. */ - ct->status &= ~IPS_NAT_DONE_MASK ; +clear_bit (IPS_SRC_NAT_DONE_BIT , &ct->status);rhltable_remove (&nf_nat_bysource_table, &ct->nat_bysource, nf_nat_bysource_params);
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerPATCH 4/4 netfilter: ctnetlink: fix incorrect nf_ct_put during hash resize
In reply to Pablo Neira AyusoFrom: Liping Zhang <[email protected]>
If nf_conntrack_htable_size was adjusted by the user during the ct dump operation, we may invoke nf_ct_put twice for the same ct, i.e. the "last" ct. This will cause the ct will be freed but still linked in hash buckets.
It's very easy to reproduce the problem by the following commands:
# while : ; do echo $RANDOM > /proc/sys/net/netfilter/nf_conntrack_buckets done # while : ; do conntrack -L done # iperf -s 127.0.0.1 & # iperf -c 127.0.0.1 -P 60 -t 36000
After a while, the system will hang like this:
NMI watchdog: BUG: soft lockup - CPU#1 stuck for 22s! [bash:20184] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [iperf:20382]
...
So at last if we find cb->args[1] is equal to "last", this means hash resize happened, then we can set cb->args[1] to 0 to fix the above issue.
--- net/netfilter/nf_conntrack_netlink.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +6 -1
@@ -890,8 +890,13 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) } out:local_bh_enable (); -if (last) +if (last) { +/* nf ct hash resize happened, now clear the leftover. */ +if ((struct nf_conn *)cb->args[1 ] == last) + cb->args[1 ] =0 ; +nf_ct_put (last); + }while (i) { i--;
Signature · 1 line
2.1.4
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 29 May 2017 13:34:28 +0200
Quoted 14 lines
Hi David,
The following patchset contains Netfilter fixes for your net tree, they are:
1) Conntrack SCTP CRC32c checksum mangling may operate on non-linear skbuff, patch from Davide Caratti.
2)
nf_tablesrb-tree set backend does not handle element re-addition after deletion in the same transaction, leading to infinite loop.3) Atomically unclear the
IPS_SRC_NAT_DONE_BITon nat module removal, from Liping Zhang.
Quoted 7 lines
4) Conntrack hashtable resizing while ctnetlink dump is progress leads to a dead reference to released objects in the lists, also from Liping.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Pulled, thanks a lot Pablo.