Skip to content

Commit 2985d19

Browse files
Florian Westphalgregkh
authored andcommitted
netfilter: x_tables: add compat version of xt_check_entry_offsets
commit fc1221b3a163d1386d1052184202d5dc50d302d1 upstream. 32bit rulesets have different layout and alignment requirements, so once more integrity checks get added to xt_check_entry_offsets it will reject well-formed 32bit rulesets. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ed30e07 commit 2985d19

5 files changed

Lines changed: 31 additions & 3 deletions

File tree

include/linux/netfilter/x_tables.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
492492
unsigned int *size);
493493
int xt_compat_target_to_user(const struct xt_entry_target *t,
494494
void __user **dstptr, unsigned int *size);
495+
int xt_compat_check_entry_offsets(const void *base,
496+
unsigned int target_offset,
497+
unsigned int next_offset);
495498

496499
#endif /* CONFIG_COMPAT */
497500
#endif /* _X_TABLES_H */

net/ipv4/netfilter/arp_tables.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,8 @@ check_compat_entry_size_and_hooks(struct compat_arpt_entry *e,
12531253
if (!arp_checkentry(&e->arp))
12541254
return -EINVAL;
12551255

1256-
ret = xt_check_entry_offsets(e, e->target_offset, e->next_offset);
1256+
ret = xt_compat_check_entry_offsets(e, e->target_offset,
1257+
e->next_offset);
12571258
if (ret)
12581259
return ret;
12591260

net/ipv4/netfilter/ip_tables.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,8 @@ check_compat_entry_size_and_hooks(struct compat_ipt_entry *e,
15121512
if (!ip_checkentry(&e->ip))
15131513
return -EINVAL;
15141514

1515-
ret = xt_check_entry_offsets(e, e->target_offset, e->next_offset);
1515+
ret = xt_compat_check_entry_offsets(e,
1516+
e->target_offset, e->next_offset);
15161517
if (ret)
15171518
return ret;
15181519

net/ipv6/netfilter/ip6_tables.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,8 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
15241524
if (!ip6_checkentry(&e->ipv6))
15251525
return -EINVAL;
15261526

1527-
ret = xt_check_entry_offsets(e, e->target_offset, e->next_offset);
1527+
ret = xt_compat_check_entry_offsets(e,
1528+
e->target_offset, e->next_offset);
15281529
if (ret)
15291530
return ret;
15301531

net/netfilter/x_tables.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,27 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
538538
return 0;
539539
}
540540
EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
541+
542+
int xt_compat_check_entry_offsets(const void *base,
543+
unsigned int target_offset,
544+
unsigned int next_offset)
545+
{
546+
const struct compat_xt_entry_target *t;
547+
const char *e = base;
548+
549+
if (target_offset + sizeof(*t) > next_offset)
550+
return -EINVAL;
551+
552+
t = (void *)(e + target_offset);
553+
if (t->u.target_size < sizeof(*t))
554+
return -EINVAL;
555+
556+
if (target_offset + t->u.target_size > next_offset)
557+
return -EINVAL;
558+
559+
return 0;
560+
}
561+
EXPORT_SYMBOL(xt_compat_check_entry_offsets);
541562
#endif /* CONFIG_COMPAT */
542563

543564
/**
@@ -548,6 +569,7 @@ EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
548569
* @next_offset: the arp/ip/ip6_t->next_offset
549570
*
550571
* validates that target_offset and next_offset are sane.
572+
* Also see xt_compat_check_entry_offsets for CONFIG_COMPAT version.
551573
*
552574
* The arp/ip/ip6t_entry structure @base must have passed following tests:
553575
* - it must point to a valid memory location

0 commit comments

Comments
 (0)