Skip to contentSkip to conversation

netfilter: x_tables: don't reject valid target size on some architectures

PATCH Applied Florian Westphal 2 participants 2 messages Jun 1, 2016 – Jun 2, 2016

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: x_tables: don't reject valid target size on some architectures

Quoting John Stultz:
In updating a 32bit arm device from 4.6 to Linus' current HEAD, I noticed I was having some trouble with networking, and realized that /proc/net/ip_tables_names was suddenly empty.
Digging through the registration process, it seems we're catching on the:

if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&

       target_offset + sizeof(struct xt_standard_target) != next_offset)
         return -EINVAL;

Where next_offset seems to be 4 bytes larger then the offset + standard_target struct size.

next_offset needs to be aligned via XT_ALIGN (so we can access all members of ip(6)t_entry struct).

This problem didn't show up on i686 as it only needs 4-byte alignment for u64, but iptables userspace on other 32bit arches does insert extra padding.

Fixes 7ed2abddd20cf ("netfilter: x_tables: check standard target size too")
---
 net/netfilter/x_tables.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/x_tables.c +2 -2
index c69c892..2675d58 100644
@@ -612,7 +612,7 @@ int xt_compat_check_entry_offsets(const void *base, const char *elems,
 		return -EINVAL;
 
 	if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&
-	    target_offset + sizeof(struct compat_xt_standard_target) != next_offset)
+	    COMPAT_XT_ALIGN(target_offset + sizeof(struct compat_xt_standard_target)) != next_offset)
 		return -EINVAL;
 
 	/* compat_xt_entry match has less strict aligment requirements,
@@ -694,7 +694,7 @@ int xt_check_entry_offsets(const void *base,
 		return -EINVAL;
 
 	if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&
-	    target_offset + sizeof(struct xt_standard_target) != next_offset)
+	    XT_ALIGN(target_offset + sizeof(struct xt_standard_target)) != next_offset)
 		return -EINVAL;
 
 	return xt_check_entry_match(elems, base + target_offset,
Signature · 1 line
2.7.3
maintainer Applied
#1 lore raw
Quoted 10 lines · Florian Westphal

Quoting John Stultz:
In updating a 32bit arm device from 4.6 to Linus' current HEAD, I noticed I was having some trouble with networking, and realized that /proc/net/ip_tables_names was suddenly empty.
Digging through the registration process, it seems we're catching on the:

   if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0 &&
       target_offset + sizeof(struct xt_standard_target) != next_offset)
         return -EINVAL;
Quoted 8 lines

Where next_offset seems to be 4 bytes larger then the offset + standard_target struct size.

next_offset needs to be aligned via XT_ALIGN (so we can access all members of ip(6)t_entry struct).

This problem didn't show up on i686 as it only needs 4-byte alignment for u64, but iptables userspace on other 32bit arches does insert extra padding.

Applied, thanks Florian.