Skip to contentSkip to conversation

Netfilter fixes for net

PATCH In review Pablo Neira Ayuso 2 participants 6 messages Mar 3, 2017 – Mar 4, 2017

Subsystems (3)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover Netfilter fixes for net

Hi David,

The following patchset contains Netfilter fixes for your net tree, they are:

1) Missing check for full sock in ip_route_me_harder(), from Florian Westphal.

2) Incorrect sip helper structure initilization that breaks it when several ports are used, from Christophe Leroy.

3) Fix incorrect assumption when looking up for matching with adjacent intervals in the nft_set_rbtree.

4) Fix broken netlink event error reporting in nf_tables that results in misleading ESRCH errors propagated to userspace listeners.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git

Thanks!

----------------------------------------------------------------

The following changes since commit 2f44f75257d57f0d5668dba3a6ada0f4872132c9:

Merge branch 'qed-fixes' (2017-02-27 09:22:10 -0500)

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 25e94a997b324b5f167f56d56d7106d38b78c9de:

netfilter: nf_tables: don't call nfnetlink_set_err() if nfnetlink_send() fails (2017-03-03 13:48:34 +0100)

----------------------------------------------------------------
Christophe Leroy (1):
netfilter: nf_conntrack_sip: fix wrong memory initialisation

Florian Westphal (1):
netfilter: use skb_to_full_sk in ip_route_me_harder

Pablo Neira Ayuso (2):
netfilter: nft_set_rbtree: incorrect assumption on lower interval lookups
netfilter: nf_tables: don't call nfnetlink_set_err() if nfnetlink_send() fails

 include/net/netfilter/nf_tables.h |   6 +-
 net/ipv4/netfilter.c              |   7 +-
 net/netfilter/nf_conntrack_sip.c  |   2 -
 net/netfilter/nf_tables_api.c     | 133 ++++++++++++++++----------------------
 net/netfilter/nft_set_rbtree.c    |   9 ++-
 5 files changed, 66 insertions(+), 91 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 netfilter: use skb_to_full_sk in ip_route_me_harder

From: Florian Westphal <[email protected]>

inet_sk(skb->sk) is illegal in case skb is attached to request socket.

Fixes ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener")

Reported by: Daniel J Blueman <[email protected]>

---
 net/ipv4/netfilter.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/netfilter.c +4 -3
index b3cc1335adbc..c0cc6aa8cfaa 100644
@@ -23,7 +23,8 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
 	struct rtable *rt;
 	struct flowi4 fl4 = {};
 	__be32 saddr = iph->saddr;
-	__u8 flags = skb->sk ? inet_sk_flowi_flags(skb->sk) : 0;
+	const struct sock *sk = skb_to_full_sk(skb);
+	__u8 flags = sk ? inet_sk_flowi_flags(sk) : 0;
 	struct net_device *dev = skb_dst(skb)->dev;
 	unsigned int hh_len;
 
@@ -40,7 +41,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
 	fl4.daddr = iph->daddr;
 	fl4.saddr = saddr;
 	fl4.flowi4_tos = RT_TOS(iph->tos);
-	fl4.flowi4_oif = skb->sk ? skb->sk->sk_bound_dev_if : 0;
+	fl4.flowi4_oif = sk ? sk->sk_bound_dev_if : 0;
 	if (!fl4.flowi4_oif)
 		fl4.flowi4_oif = l3mdev_master_ifindex(dev);
 	fl4.flowi4_mark = skb->mark;
@@ -61,7 +62,7 @@ int ip_route_me_harder(struct net *net, struct sk_buff *skb, unsigned int addr_t
 	    xfrm_decode_session(skb, flowi4_to_flowi(&fl4), AF_INET) == 0) {
 		struct dst_entry *dst = skb_dst(skb);
 		skb_dst_set(skb, NULL);
-		dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), skb->sk, 0);
+		dst = xfrm_lookup(net, dst, flowi4_to_flowi(&fl4), sk, 0);
 		if (IS_ERR(dst))
 			return PTR_ERR(dst);
 		skb_dst_set(skb, dst);
Signature · 1 line
2.1.4
author maintainer
#2 lore raw

PATCH 2/4 netfilter: nf_conntrack_sip: fix wrong memory initialisation

In reply to Pablo Neira Ayuso

From: Christophe Leroy <[email protected]>

In commit 82de0be6862cd ("netfilter: Add helper array register/unregister functions"),
struct nf_conntrack_helper sip[MAX_PORTS][4] was changed to sip[MAX_PORTS * 4], so the memory init should have been changed to memset(&sip[4 * i], 0, 4 * sizeof(sip[i]));

But as the sip[] table is allocated in the BSS, it is already set to 0

Fixes 82de0be6862cd ("netfilter: Add helper array register/unregister functions")
---
 net/netfilter/nf_conntrack_sip.c | 2 --
 1 file changed, 2 deletions(-)
net/netfilter/nf_conntrack_sip.c +0 -2
index 24174c520239..0d17894798b5 100644
@@ -1628,8 +1628,6 @@ static int __init nf_conntrack_sip_init(void)
 		ports[ports_c++] = SIP_PORT;
 
 	for (i = 0; i < ports_c; i++) {
-		memset(&sip[i], 0, sizeof(sip[i]));
-
 		nf_ct_helper_init(&sip[4 * i], AF_INET, IPPROTO_UDP, "sip",
 				  SIP_PORT, ports[i], i, sip_exp_policy,
 				  SIP_EXPECT_MAX,
Signature · 1 line
2.1.4
author maintainer
#3 lore raw

PATCH 3/4 netfilter: nft_set_rbtree: incorrect assumption on lower interval lookups

In reply to Pablo Neira Ayuso

In case of adjacent ranges, we may indeed see either the high part of the range in first place or the low part of it. Remove this incorrect assumption, let's make sure we annotate the low part of the interval in case of we have adjacent interva intervals so we hit a matching in lookups.

---
 net/netfilter/nft_set_rbtree.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
net/netfilter/nft_set_rbtree.c +4 -5
index 71e8fb886a73..78dfbf9588b3 100644
@@ -60,11 +60,10 @@ static bool nft_rbtree_lookup(const struct net *net, const struct nft_set *set,
 		d = memcmp(this, key, set->klen);
 		if (d < 0) {
 			parent = parent->rb_left;
-			/* In case of adjacent ranges, we always see the high
-			 * part of the range in first place, before the low one.
-			 * So don't update interval if the keys are equal.
-			 */
-			if (interval && nft_rbtree_equal(set, this, interval))
+			if (interval &&
+			    nft_rbtree_equal(set, this, interval) &&
+			    nft_rbtree_interval_end(this) &&
+			    !nft_rbtree_interval_end(interval))
 				continue;
 			interval = rbe;
 		} else if (d > 0)
Signature · 1 line
2.1.4
author maintainer
#4 lore raw

PATCH 4/4 netfilter: nf_tables: don't call nfnetlink_set_err() if nfnetlink_send() fails

In reply to Pablo Neira Ayuso

The underlying nlmsg_multicast() already sets sk->sk_err for us to notify socket overruns, so we should not do anything with this return value. So we just call nfnetlink_set_err() if:

1) We fail to allocate the netlink message.

or

2) We don't have enough space in the netlink message to place attributes, which means that we likely need to allocate a larger message.

Before this patch, the internal ESRCH netlink error code was propagated to userspace, which is quite misleading. Netlink semantics mandate that listeners just hit ENOBUFS if the socket buffer overruns.

---
 include/net/netfilter/nf_tables.h |   6 +-
 net/netfilter/nf_tables_api.c     | 133 ++++++++++++++++----------------------
 2 files changed, 58 insertions(+), 81 deletions(-)
include/net/netfilter/nf_tables.h +3 -3
index ac84686aaafb..2aa8a9d80fbe 100644
@@ -988,9 +988,9 @@ struct nft_object *nf_tables_obj_lookup(const struct nft_table *table,
 					const struct nlattr *nla, u32 objtype,
 					u8 genmask);
 
-int nft_obj_notify(struct net *net, struct nft_table *table,
-		   struct nft_object *obj, u32 portid, u32 seq,
-		   int event, int family, int report, gfp_t gfp);
+void nft_obj_notify(struct net *net, struct nft_table *table,
+		    struct nft_object *obj, u32 portid, u32 seq,
+		    int event, int family, int report, gfp_t gfp);
 
 /**
  *	struct nft_object_type - stateful object type
net/netfilter/nf_tables_api.c +55 -78

277 lines not on this page · raw message

Signature · 1 line
2.1.4
maintainer
#5 lore raw
In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Fri, 3 Mar 2017 20:22:21 +0100

Quoted 12 lines

The following patchset contains Netfilter fixes for your net tree, they are:

1) Missing check for full sock in ip_route_me_harder(), from Florian Westphal.

2) Incorrect sip helper structure initilization that breaks it when several ports are used, from Christophe Leroy.

3) Fix incorrect assumption when looking up for matching with adjacent intervals in the nft_set_rbtree.

Quoted 6 lines

4) Fix broken netlink event error reporting in nf_tables that results in misleading ESRCH errors propagated to userspace listeners.

You can pull these changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git

Pulled, thanks a lot Pablo.