Skip to content

Commit b29c457

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: x_tables: fix compat match/target pad out-of-bound write
xt_compat_match/target_from_user doesn't check that zeroing the area to start of next rule won't write past end of allocated ruleset blob. Remove this code and zero the entire blob beforehand. Reported-by: [email protected] Reported-by: Andy Nguyen <[email protected]> Fixes: 9fa492c ("[NETFILTER]: x_tables: simplify compat API") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent d163a92 commit b29c457

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

net/ipv4/netfilter/arp_tables.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,8 @@ static int translate_compat_table(struct net *net,
11931193
if (!newinfo)
11941194
goto out_unlock;
11951195

1196+
memset(newinfo->entries, 0, size);
1197+
11961198
newinfo->number = compatr->num_entries;
11971199
for (i = 0; i < NF_ARP_NUMHOOKS; i++) {
11981200
newinfo->hook_entry[i] = compatr->hook_entry[i];

net/ipv4/netfilter/ip_tables.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ translate_compat_table(struct net *net,
14281428
if (!newinfo)
14291429
goto out_unlock;
14301430

1431+
memset(newinfo->entries, 0, size);
1432+
14311433
newinfo->number = compatr->num_entries;
14321434
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
14331435
newinfo->hook_entry[i] = compatr->hook_entry[i];

net/ipv6/netfilter/ip6_tables.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,8 @@ translate_compat_table(struct net *net,
14431443
if (!newinfo)
14441444
goto out_unlock;
14451445

1446+
memset(newinfo->entries, 0, size);
1447+
14461448
newinfo->number = compatr->num_entries;
14471449
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
14481450
newinfo->hook_entry[i] = compatr->hook_entry[i];

net/netfilter/x_tables.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
733733
{
734734
const struct xt_match *match = m->u.kernel.match;
735735
struct compat_xt_entry_match *cm = (struct compat_xt_entry_match *)m;
736-
int pad, off = xt_compat_match_offset(match);
736+
int off = xt_compat_match_offset(match);
737737
u_int16_t msize = cm->u.user.match_size;
738738
char name[sizeof(m->u.user.name)];
739739

@@ -743,9 +743,6 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
743743
match->compat_from_user(m->data, cm->data);
744744
else
745745
memcpy(m->data, cm->data, msize - sizeof(*cm));
746-
pad = XT_ALIGN(match->matchsize) - match->matchsize;
747-
if (pad > 0)
748-
memset(m->data + match->matchsize, 0, pad);
749746

750747
msize += off;
751748
m->u.user.match_size = msize;
@@ -1116,7 +1113,7 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
11161113
{
11171114
const struct xt_target *target = t->u.kernel.target;
11181115
struct compat_xt_entry_target *ct = (struct compat_xt_entry_target *)t;
1119-
int pad, off = xt_compat_target_offset(target);
1116+
int off = xt_compat_target_offset(target);
11201117
u_int16_t tsize = ct->u.user.target_size;
11211118
char name[sizeof(t->u.user.name)];
11221119

@@ -1126,9 +1123,6 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
11261123
target->compat_from_user(t->data, ct->data);
11271124
else
11281125
memcpy(t->data, ct->data, tsize - sizeof(*ct));
1129-
pad = XT_ALIGN(target->targetsize) - target->targetsize;
1130-
if (pad > 0)
1131-
memset(t->data + target->targetsize, 0, pad);
11321126

11331127
tsize += off;
11341128
t->u.user.target_size = tsize;

0 commit comments

Comments
 (0)