Skip to contentSkip to conversation

: Netfilter fixes

PATCH In review Patrick McHardy 3 participants 11 messages Feb 19, 2008 – Feb 20, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover : Netfilter fixes

Hi Dave,

following are a few netfilter fixes for 2.6.25, fixing a BUG() when mangling non-linear skbs in {ip,ip6,nfnetlink}_queue, a compilation error in busybox, IPv6 address range matching in xt_iprange, missing unidef'ing of xt_policy.h. Additionally there is a patch to remove an unnecessary member from the xt_hashlimit matchinfo, which we need to do know before it hits a release.

Please apply, thanks.

 include/linux/netfilter.h              |    2 +-
 include/linux/netfilter/Kbuild         |    2 +-
 include/linux/netfilter/xt_hashlimit.h |    1 -
 net/bridge/netfilter/ebt_dnat.c        |    2 +-
 net/bridge/netfilter/ebt_redirect.c    |    2 +-
 net/bridge/netfilter/ebt_snat.c        |    2 +-
 net/ipv4/netfilter/arpt_mangle.c       |    2 +-
 net/ipv4/netfilter/ip_queue.c          |   12 +++++++-----
 net/ipv6/netfilter/ip6_queue.c         |   10 ++++++----
 net/netfilter/nfnetlink_queue.c        |   10 ++++++----
 net/netfilter/xt_hashlimit.c           |    3 ---
 net/netfilter/xt_iprange.c             |    2 +-
 net/netfilter/xt_u32.c                 |   11 +++++------
 13 files changed, 31 insertions(+), 30 deletions(-)

Jan Engelhardt (2):
[NETFILTER]: xt_hashlimit: remove unneeded struct member [NETFILTER]: xt_iprange: fix subtraction-based comparison

Joonwoo Park (1):
[NETFILTER]: Fix incorrect use of skb_make_writable

Patrick McHardy (2):
[NETFILTER]: {ip,ip6,nfnetlink}_queue: fix SKB_LINEAR_ASSERT when mangling packet data [NETFILTER]: Use __u32 in struct nf_inet_addr

Pavel Emelyanov (1):
[NETFILTER]: xt_u32: drop the actually unused variable from u32_match_it

Robert P. J. Day (1):
[NETFILTER]: Make sure xt_policy.h is unifdef'ed.

#1 lore raw

PATCH 1/7 : nfnetlink_queue: fix SKB_LINEAR_ASSERT when mangling packet data

[NETFILTER]: {ip,ip6,nfnetlink}_queue: fix SKB_LINEAR_ASSERT when mangling packet data

As reported by Tomas Simonaitis <[email protected]>, inserting new data in skbs queued over {ip,ip6,nfnetlink}_queue triggers a SKB_LINEAR_ASSERT in skb_put().

Going back through the git history, it seems this bug is present since at least 2.6.12-rc2, probably even since the removal of skb_linearize() for netfilter.

Linearize non-linear skbs through skb_copy_expand() when enlarging them. Tested by Thomas, fixes bugzilla #9933.

---
commit 2292fd9623ce0391217dfe8cec57f70fd90da538
tree ba852b5da64fac4aaec85ecf9622cca31e3ffb0d
parent 73b9987a76c8e0b5326afcc3632f79be425676bc
author Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:26 +0100 committer Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:26 +0100

 net/ipv4/netfilter/ip_queue.c   |   12 +++++++-----
 net/ipv6/netfilter/ip6_queue.c  |   10 ++++++----
 net/netfilter/nfnetlink_queue.c |   10 ++++++----
 3 files changed, 19 insertions(+), 13 deletions(-)
net/ipv4/netfilter/ip_queue.c +7 -5
index 6bda110..fe05da4 100644
@@ -283,8 +283,8 @@ static int
 ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
 {
 	int diff;
-	int err;
 	struct iphdr *user_iph = (struct iphdr *)v->payload;
+	struct sk_buff *nskb;
 
 	if (v->data_len < sizeof(*user_iph))
 		return 0;
@@ -296,14 +296,16 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
 		if (v->data_len > 0xFFFF)
 			return -EINVAL;
 		if (diff > skb_tailroom(e->skb)) {
-			err = pskb_expand_head(e->skb, 0,
+			nskb = skb_copy_expand(e->skb, 0,
 					       diff - skb_tailroom(e->skb),
 					       GFP_ATOMIC);
-			if (err) {
+			if (!nskb) {
 				printk(KERN_WARNING "ip_queue: error "
-				      "in mangle, dropping packet: %d\n", -err);
-				return err;
+				      "in mangle, dropping packet\n");
+				return -ENOMEM;
 			}
+			kfree_skb(e->skb);
+			e->skb = nskb;
 		}
 		skb_put(e->skb, diff);
 	}
net/ipv6/netfilter/ip6_queue.c +6 -4
index e869916..cc2f9af 100644
@@ -285,8 +285,8 @@ static int
 ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
 {
 	int diff;
-	int err;
 	struct ipv6hdr *user_iph = (struct ipv6hdr *)v->payload;
+	struct sk_buff *nskb;
 
 	if (v->data_len < sizeof(*user_iph))
 		return 0;
@@ -298,14 +298,16 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
 		if (v->data_len > 0xFFFF)
 			return -EINVAL;
 		if (diff > skb_tailroom(e->skb)) {
-			err = pskb_expand_head(e->skb, 0,
+			nskb = skb_copy_expand(e->skb, 0,
 					       diff - skb_tailroom(e->skb),
 					       GFP_ATOMIC);
-			if (err) {
+			if (!nskb) {
 				printk(KERN_WARNING "ip6_queue: OOM "
 				      "in mangle, dropping packet\n");
-				return err;
+				return -ENOMEM;
 			}
+			kfree_skb(e->skb);
+			e->skb = nskb;
 		}
 		skb_put(e->skb, diff);
 	}
net/netfilter/nfnetlink_queue.c +6 -4
index a48b20f..0043d3a 100644
@@ -443,8 +443,8 @@ err_out:
 static int
 nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e)
 {
+	struct sk_buff *nskb;
 	int diff;
-	int err;
 
 	diff = data_len - e->skb->len;
 	if (diff < 0) {
@@ -454,14 +454,16 @@ nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e)
 		if (data_len > 0xFFFF)
 			return -EINVAL;
 		if (diff > skb_tailroom(e->skb)) {
-			err = pskb_expand_head(e->skb, 0,
+			nskb = skb_copy_expand(e->skb, 0,
 					       diff - skb_tailroom(e->skb),
 					       GFP_ATOMIC);
-			if (err) {
+			if (!nskb) {
 				printk(KERN_WARNING "nf_queue: OOM "
 				      "in mangle, dropping packet\n");
-				return err;
+				return -ENOMEM;
 			}
+			kfree_skb(e->skb);
+			e->skb = nskb;
 		}
 		skb_put(e->skb, diff);
 	}
#2 lore raw

PATCH 2/7 : xt_u32: drop the actually unused variable from u32_match_it

In reply to Patrick McHardy

[NETFILTER]: xt_u32: drop the actually unused variable from u32_match_it

The int ret variable is used only to trigger the BUG_ON() after the skb_copy_bits() call, so check the call failure directly and drop the variable.

---
commit 30c709c51fa0f400859890d534cfa02eb8d06cc7
tree 6df1f3fd873cae02ae066e2a76bafd1ef32e055a
parent 2292fd9623ce0391217dfe8cec57f70fd90da538
author Pavel Emelyanov <[email protected]> Tue, 19 Feb 2008 17:15:26 +0100 committer Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:26 +0100

 net/netfilter/xt_u32.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
net/netfilter/xt_u32.c +5 -6
index 9b8ed39..627e0f3 100644
@@ -26,7 +26,6 @@ static bool u32_match_it(const struct xt_u32 *data,
 	u_int32_t pos;
 	u_int32_t val;
 	u_int32_t at;
-	int ret;
 
 	/*
 	 * Small example: "0 >> 28 == 4 && 8 & 0xFF0000 >> 16 = 6, 17"
@@ -40,8 +39,8 @@ static bool u32_match_it(const struct xt_u32 *data,
 		if (skb->len < 4 || pos > skb->len - 4)
 			return false;
 
-		ret   = skb_copy_bits(skb, pos, &n, sizeof(n));
-		BUG_ON(ret < 0);
+		if (skb_copy_bits(skb, pos, &n, sizeof(n)) < 0)
+			BUG();
 		val   = ntohl(n);
 		nnums = ct->nnums;
 
@@ -67,9 +66,9 @@ static bool u32_match_it(const struct xt_u32 *data,
 				    pos > skb->len - at - 4)
 					return false;
 
-				ret = skb_copy_bits(skb, at + pos, &n,
-						    sizeof(n));
-				BUG_ON(ret < 0);
+				if (skb_copy_bits(skb, at + pos, &n,
+						    sizeof(n)) < 0)
+					BUG();
 				val = ntohl(n);
 				break;
 			}
#3 lore raw

PATCH 3/7 : Fix incorrect use of skb_make_writable

In reply to Patrick McHardy

[NETFILTER]: Fix incorrect use of skb_make_writable

http://bugzilla.kernel.org/show_bug.cgi?id=9920
The function skb_make_writable returns true or false.

---
commit 02413e566cd9a49bcf1f15f69cdc749780181412
tree 9ec6b55a428fbfdd24da2bc619ebf4c5dabb0354
parent 30c709c51fa0f400859890d534cfa02eb8d06cc7
author Joonwoo Park <[email protected]> Tue, 19 Feb 2008 17:15:27 +0100 committer Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:27 +0100

 net/bridge/netfilter/ebt_dnat.c     |    2 +-
 net/bridge/netfilter/ebt_redirect.c |    2 +-
 net/bridge/netfilter/ebt_snat.c     |    2 +-
 net/ipv4/netfilter/arpt_mangle.c    |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
net/bridge/netfilter/ebt_dnat.c +1 -1
index e700cbf..1ec671d 100644
@@ -20,7 +20,7 @@ static int ebt_target_dnat(struct sk_buff *skb, unsigned int hooknr,
 {
 	const struct ebt_nat_info *info = data;
 
-	if (skb_make_writable(skb, 0))
+	if (!skb_make_writable(skb, 0))
 		return NF_DROP;
 
 	memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN);
net/bridge/netfilter/ebt_redirect.c +1 -1
index bfdf2fb..bfb9f74 100644
@@ -21,7 +21,7 @@ static int ebt_target_redirect(struct sk_buff *skb, unsigned int hooknr,
 {
 	const struct ebt_redirect_info *info = data;
 
-	if (skb_make_writable(skb, 0))
+	if (!skb_make_writable(skb, 0))
 		return NF_DROP;
 
 	if (hooknr != NF_BR_BROUTING)
net/bridge/netfilter/ebt_snat.c +1 -1
index e252dab..204f996 100644
@@ -22,7 +22,7 @@ static int ebt_target_snat(struct sk_buff *skb, unsigned int hooknr,
 {
 	const struct ebt_nat_info *info = data;
 
-	if (skb_make_writable(skb, 0))
+	if (!skb_make_writable(skb, 0))
 		return NF_DROP;
 
 	memcpy(eth_hdr(skb)->h_source, info->mac, ETH_ALEN);
net/ipv4/netfilter/arpt_mangle.c +1 -1
index 45fa4e2..3f4222b 100644
@@ -19,7 +19,7 @@ target(struct sk_buff *skb,
 	unsigned char *arpptr;
 	int pln, hln;
 
-	if (skb_make_writable(skb, skb->len))
+	if (!skb_make_writable(skb, skb->len))
 		return NF_DROP;
 
 	arp = arp_hdr(skb);
#4 lore raw

PATCH 4/7 : Make sure xt_policy.h is unifdef'ed.

In reply to Patrick McHardy

[NETFILTER]: Make sure xt_policy.h is unifdef'ed.

Since the header file xt_policy.h tests __KERNEL__, it should be unifdef'ed before exporting to userspace.

---
commit 0776e52cdb04aad5b59c4e12dc16e7b58737c2d2
tree d8f3cb734bad2c4df073262ab9ac14989f28eb28
parent 02413e566cd9a49bcf1f15f69cdc749780181412
author Robert P. J. Day <[email protected]> Tue, 19 Feb 2008 17:15:28 +0100 committer Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:28 +0100

 include/linux/netfilter/Kbuild |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/netfilter/Kbuild +1 -1
index 91fef0c..3aff513 100644
@@ -30,7 +30,6 @@ header-y += xt_mark.h
 header-y += xt_multiport.h
 header-y += xt_owner.h
 header-y += xt_pkttype.h
-header-y += xt_policy.h
 header-y += xt_rateest.h
 header-y += xt_realm.h
 header-y += xt_sctp.h
@@ -47,3 +46,4 @@ unifdef-y += nfnetlink.h
 unifdef-y += nfnetlink_compat.h
 unifdef-y += x_tables.h
 unifdef-y += xt_physdev.h
+unifdef-y += xt_policy.h
#5 lore raw

PATCH 5/7 : xt_hashlimit: remove unneeded struct member

In reply to Patrick McHardy

[NETFILTER]: xt_hashlimit: remove unneeded struct member

By allocating ->hinfo, we already have the needed indirection to cope with the per-cpu xtables struct match_entry.

[Patrick: do this now before the revision 1 struct is used by userspace]

---
commit 4e2e7aba6471fcd945a3f8fdc40d5cf11e7039b3
tree fee4fdd8dfbf77ac747e89a316b591fab09bf884
parent 0776e52cdb04aad5b59c4e12dc16e7b58737c2d2
author Jan Engelhardt <[email protected]> Tue, 19 Feb 2008 17:15:28 +0100 committer Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:28 +0100

 include/linux/netfilter/xt_hashlimit.h |    1 -
 net/netfilter/xt_hashlimit.c           |    3 ---
 2 files changed, 0 insertions(+), 4 deletions(-)
include/linux/netfilter/xt_hashlimit.h +0 -1
index 58b818e..51b18d8 100644
@@ -61,7 +61,6 @@ struct xt_hashlimit_mtinfo1 {
 
 	/* Used internally by the kernel */
 	struct xt_hashlimit_htable *hinfo __attribute__((aligned(8)));
-	struct xt_hashlimit_mtinfo1 *master __attribute__((aligned(8)));
 };
 
 #endif /*_XT_HASHLIMIT_H*/
net/netfilter/xt_hashlimit.c +0 -3
index 744c7f2..5418ce5 100644
@@ -774,9 +774,6 @@ hashlimit_mt_check(const char *tablename, const void *inf,
 		return false;
 	}
 	mutex_unlock(&hlimit_mutex);
-
-	/* Ugly hack: For SMP, we only want to use one set */
-	info->master = info;
 	return true;
 }
 
#6 lore raw

PATCH 6/7 : xt_iprange: fix subtraction-based comparison

In reply to Patrick McHardy

[NETFILTER]: xt_iprange: fix subtraction-based comparison

The host address parts need to be converted to host-endian first before arithmetic makes any sense on them.

---
commit 5a090319a35aac1052102d97c431230d3140daf1
tree 72fb9bcb9ebf94fad277a3461288d23841f50662
parent 4e2e7aba6471fcd945a3f8fdc40d5cf11e7039b3
author Jan Engelhardt <[email protected]> Tue, 19 Feb 2008 17:15:29 +0100 committer Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:29 +0100

 net/netfilter/xt_iprange.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/xt_iprange.c +1 -1
index 4f984dc..500528d 100644
@@ -102,7 +102,7 @@ iprange_ipv6_sub(const struct in6_addr *a, const struct in6_addr *b)
 	int r;
 
 	for (i = 0; i < 4; ++i) {
-		r = (__force u32)a->s6_addr32[i] - (__force u32)b->s6_addr32[i];
+		r = ntohl(a->s6_addr32[i]) - ntohl(b->s6_addr32[i]);
 		if (r != 0)
 			return r;
 	}
#7 lore raw

PATCH 7/7 : Use __u32 in struct nf_inet_addr

In reply to Patrick McHardy

[NETFILTER]: Use __u32 in struct nf_inet_addr

As reported by David Woodhouse <[email protected]>, using u_int32_t in struct nf_inet_addr breaks the busybox build. Fix by using __u32.

---
commit 4f4e9be33da8cc1a297c4d7ef51c1fa1effcbace
tree a856969ae8edeebca7c8018e18e4304cd198e529
parent 5a090319a35aac1052102d97c431230d3140daf1
author Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:29 +0100 committer Patrick McHardy <[email protected]> Tue, 19 Feb 2008 17:15:29 +0100

 include/linux/netfilter.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/netfilter.h +1 -1
index d74e79b..b74b615 100644
@@ -51,7 +51,7 @@ enum nf_inet_hooks {
 };
 
 union nf_inet_addr {
-	u_int32_t	all[4];
+	__u32		all[4];
 	__be32		ip;
 	__be32		ip6[4];
 	struct in_addr	in;
#8 lore raw

Re: [NETFILTER 07/07]: Use __u32 in struct nf_inet_addr

Quoted 4 lines · Patrick McHardy

[NETFILTER]: Use __u32 in struct nf_inet_addr

As reported by David Woodhouse <[email protected]>, using u_int32_t in struct nf_inet_addr breaks the busybox build. Fix by using __u32.

... that's why I say we should use uint32_t (with just one underscore), because that is available in userspace thorugh <stdint.h>, while u_int32_t is not (at first glance²).

² db1/db.h and ALSA do seem to use it, though.
-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [NETFILTER 07/07]: Use __u32 in struct nf_inet_addr

Quoted 9 lines · Jan Engelhardt
Quoted 4 lines · Patrick McHardy

[NETFILTER]: Use __u32 in struct nf_inet_addr

As reported by David Woodhouse <[email protected]>, using u_int32_t in struct nf_inet_addr breaks the busybox build. Fix by using __u32.

... that's why I say we should use uint32_t (with just one underscore), because that is available in userspace thorugh <stdint.h>, while u_int32_t is not (at first glance²).

As David explained, kernel headers shouldn't assume that userspace has pulled in any of these typedefs and therefore should use the kernel-internally defined types.

-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#10 lore raw
In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Tue, 19 Feb 2008 17:25:44 +0100 (MET)

Quoted 8 lines

following are a few netfilter fixes for 2.6.25, fixing a BUG() when mangling non-linear skbs in {ip,ip6,nfnetlink}_queue, a compilation error in busybox, IPv6 address range matching in xt_iprange, missing unidef'ing of xt_policy.h. Additionally there is a patch to remove an unnecessary member from the xt_hashlimit matchinfo, which we need to do know before it hits a release.

Please apply, thanks.

All applied, thanks Patrick.