Skip to content

Commit 47a6959

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: allow to turn off xtables compat layer
The compat layer needs to parse untrusted input (the ruleset) to translate it to a 64bit compatible format. We had a number of bugs in this department in the past, so allow users to turn this feature off. Add CONFIG_NETFILTER_XTABLES_COMPAT kconfig knob and make it default to y to keep existing behaviour. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 50f2db9 commit 47a6959

15 files changed

Lines changed: 70 additions & 60 deletions

File tree

‎include/linux/netfilter/x_tables.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct xt_match {
158158

159159
/* Called when entry of this type deleted. */
160160
void (*destroy)(const struct xt_mtdtor_param *);
161-
#ifdef CONFIG_COMPAT
161+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
162162
/* Called when userspace align differs from kernel space one */
163163
void (*compat_from_user)(void *dst, const void *src);
164164
int (*compat_to_user)(void __user *dst, const void *src);
@@ -169,7 +169,7 @@ struct xt_match {
169169
const char *table;
170170
unsigned int matchsize;
171171
unsigned int usersize;
172-
#ifdef CONFIG_COMPAT
172+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
173173
unsigned int compatsize;
174174
#endif
175175
unsigned int hooks;
@@ -199,7 +199,7 @@ struct xt_target {
199199

200200
/* Called when entry of this type deleted. */
201201
void (*destroy)(const struct xt_tgdtor_param *);
202-
#ifdef CONFIG_COMPAT
202+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
203203
/* Called when userspace align differs from kernel space one */
204204
void (*compat_from_user)(void *dst, const void *src);
205205
int (*compat_to_user)(void __user *dst, const void *src);
@@ -210,7 +210,7 @@ struct xt_target {
210210
const char *table;
211211
unsigned int targetsize;
212212
unsigned int usersize;
213-
#ifdef CONFIG_COMPAT
213+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
214214
unsigned int compatsize;
215215
#endif
216216
unsigned int hooks;
@@ -452,7 +452,7 @@ xt_get_per_cpu_counter(struct xt_counters *cnt, unsigned int cpu)
452452

453453
struct nf_hook_ops *xt_hook_ops_alloc(const struct xt_table *, nf_hookfn *);
454454

455-
#ifdef CONFIG_COMPAT
455+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
456456
#include <net/compat.h>
457457

458458
struct compat_xt_entry_match {
@@ -533,5 +533,5 @@ int xt_compat_check_entry_offsets(const void *base, const char *elems,
533533
unsigned int target_offset,
534534
unsigned int next_offset);
535535

536-
#endif /* CONFIG_COMPAT */
536+
#endif /* CONFIG_NETFILTER_XTABLES_COMPAT */
537537
#endif /* _X_TABLES_H */

‎include/linux/netfilter_arp/arp_tables.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extern unsigned int arpt_do_table(struct sk_buff *skb,
5959
const struct nf_hook_state *state,
6060
struct xt_table *table);
6161

62-
#ifdef CONFIG_COMPAT
62+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
6363
#include <net/compat.h>
6464

6565
struct compat_arpt_entry {

‎include/linux/netfilter_ipv4/ip_tables.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern unsigned int ipt_do_table(struct sk_buff *skb,
6767
const struct nf_hook_state *state,
6868
struct xt_table *table);
6969

70-
#ifdef CONFIG_COMPAT
70+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
7171
#include <net/compat.h>
7272

7373
struct compat_ipt_entry {

‎include/linux/netfilter_ipv6/ip6_tables.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern unsigned int ip6t_do_table(struct sk_buff *skb,
3333
const struct nf_hook_state *state,
3434
struct xt_table *table);
3535

36-
#ifdef CONFIG_COMPAT
36+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
3737
#include <net/compat.h>
3838

3939
struct compat_ip6t_entry {

‎net/bridge/netfilter/ebt_limit.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static int ebt_limit_mt_check(const struct xt_mtchk_param *par)
8787
}
8888

8989

90-
#ifdef CONFIG_COMPAT
90+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
9191
/*
9292
* no conversion function needed --
9393
* only avg/burst have meaningful values in userspace.
@@ -107,7 +107,7 @@ static struct xt_match ebt_limit_mt_reg __read_mostly = {
107107
.checkentry = ebt_limit_mt_check,
108108
.matchsize = sizeof(struct ebt_limit_info),
109109
.usersize = offsetof(struct ebt_limit_info, prev),
110-
#ifdef CONFIG_COMPAT
110+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
111111
.compatsize = sizeof(struct ebt_compat_limit_info),
112112
#endif
113113
.me = THIS_MODULE,

‎net/bridge/netfilter/ebt_mark.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int ebt_mark_tg_check(const struct xt_tgchk_param *par)
5353
return -EINVAL;
5454
return 0;
5555
}
56-
#ifdef CONFIG_COMPAT
56+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
5757
struct compat_ebt_mark_t_info {
5858
compat_ulong_t mark;
5959
compat_uint_t target;
@@ -87,7 +87,7 @@ static struct xt_target ebt_mark_tg_reg __read_mostly = {
8787
.target = ebt_mark_tg,
8888
.checkentry = ebt_mark_tg_check,
8989
.targetsize = sizeof(struct ebt_mark_t_info),
90-
#ifdef CONFIG_COMPAT
90+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
9191
.compatsize = sizeof(struct compat_ebt_mark_t_info),
9292
.compat_from_user = mark_tg_compat_from_user,
9393
.compat_to_user = mark_tg_compat_to_user,

‎net/bridge/netfilter/ebt_mark_m.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static int ebt_mark_mt_check(const struct xt_mtchk_param *par)
3737
}
3838

3939

40-
#ifdef CONFIG_COMPAT
40+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
4141
struct compat_ebt_mark_m_info {
4242
compat_ulong_t mark, mask;
4343
uint8_t invert, bitmask;
@@ -75,7 +75,7 @@ static struct xt_match ebt_mark_mt_reg __read_mostly = {
7575
.match = ebt_mark_mt,
7676
.checkentry = ebt_mark_mt_check,
7777
.matchsize = sizeof(struct ebt_mark_m_info),
78-
#ifdef CONFIG_COMPAT
78+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
7979
.compatsize = sizeof(struct compat_ebt_mark_m_info),
8080
.compat_from_user = mark_mt_compat_from_user,
8181
.compat_to_user = mark_mt_compat_to_user,

‎net/bridge/netfilter/ebtables.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct ebt_pernet {
4747
static unsigned int ebt_pernet_id __read_mostly;
4848
static DEFINE_MUTEX(ebt_mutex);
4949

50-
#ifdef CONFIG_COMPAT
50+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
5151
static void ebt_standard_compat_from_user(void *dst, const void *src)
5252
{
5353
int v = *(compat_int_t *)src;
@@ -73,7 +73,7 @@ static struct xt_target ebt_standard_target = {
7373
.revision = 0,
7474
.family = NFPROTO_BRIDGE,
7575
.targetsize = sizeof(int),
76-
#ifdef CONFIG_COMPAT
76+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
7777
.compatsize = sizeof(compat_int_t),
7878
.compat_from_user = ebt_standard_compat_from_user,
7979
.compat_to_user = ebt_standard_compat_to_user,
@@ -1502,7 +1502,7 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
15021502
ebt_entry_to_user, entries, tmp.entries);
15031503
}
15041504

1505-
#ifdef CONFIG_COMPAT
1505+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
15061506
/* 32 bit-userspace compatibility definitions. */
15071507
struct compat_ebt_replace {
15081508
char name[EBT_TABLE_MAXNAMELEN];
@@ -2367,7 +2367,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
23672367
if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
23682368
return -EPERM;
23692369

2370-
#ifdef CONFIG_COMPAT
2370+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
23712371
/* try real handler in case userland supplied needed padding */
23722372
if (in_compat_syscall() &&
23732373
((cmd != EBT_SO_GET_INFO && cmd != EBT_SO_GET_INIT_INFO) ||
@@ -2434,15 +2434,15 @@ static int do_ebt_set_ctl(struct sock *sk, int cmd, sockptr_t arg,
24342434

24352435
switch (cmd) {
24362436
case EBT_SO_SET_ENTRIES:
2437-
#ifdef CONFIG_COMPAT
2437+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
24382438
if (in_compat_syscall())
24392439
ret = compat_do_replace(net, arg, len);
24402440
else
24412441
#endif
24422442
ret = do_replace(net, arg, len);
24432443
break;
24442444
case EBT_SO_SET_COUNTERS:
2445-
#ifdef CONFIG_COMPAT
2445+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
24462446
if (in_compat_syscall())
24472447
ret = compat_update_counters(net, arg, len);
24482448
else

‎net/ipv4/netfilter/arp_tables.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ static int copy_entries_to_user(unsigned int total_size,
713713
return ret;
714714
}
715715

716-
#ifdef CONFIG_COMPAT
716+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
717717
static void compat_standard_from_user(void *dst, const void *src)
718718
{
719719
int v = *(compat_int_t *)src;
@@ -800,15 +800,15 @@ static int get_info(struct net *net, void __user *user, const int *len)
800800
return -EFAULT;
801801

802802
name[XT_TABLE_MAXNAMELEN-1] = '\0';
803-
#ifdef CONFIG_COMPAT
803+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
804804
if (in_compat_syscall())
805805
xt_compat_lock(NFPROTO_ARP);
806806
#endif
807807
t = xt_request_find_table_lock(net, NFPROTO_ARP, name);
808808
if (!IS_ERR(t)) {
809809
struct arpt_getinfo info;
810810
const struct xt_table_info *private = t->private;
811-
#ifdef CONFIG_COMPAT
811+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
812812
struct xt_table_info tmp;
813813

814814
if (in_compat_syscall()) {
@@ -835,7 +835,7 @@ static int get_info(struct net *net, void __user *user, const int *len)
835835
module_put(t->me);
836836
} else
837837
ret = PTR_ERR(t);
838-
#ifdef CONFIG_COMPAT
838+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
839839
if (in_compat_syscall())
840840
xt_compat_unlock(NFPROTO_ARP);
841841
#endif
@@ -1044,7 +1044,7 @@ static int do_add_counters(struct net *net, sockptr_t arg, unsigned int len)
10441044
return ret;
10451045
}
10461046

1047-
#ifdef CONFIG_COMPAT
1047+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
10481048
struct compat_arpt_replace {
10491049
char name[XT_TABLE_MAXNAMELEN];
10501050
u32 valid_hooks;
@@ -1412,7 +1412,7 @@ static int do_arpt_set_ctl(struct sock *sk, int cmd, sockptr_t arg,
14121412

14131413
switch (cmd) {
14141414
case ARPT_SO_SET_REPLACE:
1415-
#ifdef CONFIG_COMPAT
1415+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
14161416
if (in_compat_syscall())
14171417
ret = compat_do_replace(sock_net(sk), arg, len);
14181418
else
@@ -1444,7 +1444,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
14441444
break;
14451445

14461446
case ARPT_SO_GET_ENTRIES:
1447-
#ifdef CONFIG_COMPAT
1447+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
14481448
if (in_compat_syscall())
14491449
ret = compat_get_entries(sock_net(sk), user, len);
14501450
else
@@ -1580,7 +1580,7 @@ static struct xt_target arpt_builtin_tg[] __read_mostly = {
15801580
.name = XT_STANDARD_TARGET,
15811581
.targetsize = sizeof(int),
15821582
.family = NFPROTO_ARP,
1583-
#ifdef CONFIG_COMPAT
1583+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
15841584
.compatsize = sizeof(compat_int_t),
15851585
.compat_from_user = compat_standard_from_user,
15861586
.compat_to_user = compat_standard_to_user,

‎net/ipv4/netfilter/ip_tables.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ copy_entries_to_user(unsigned int total_size,
868868
return ret;
869869
}
870870

871-
#ifdef CONFIG_COMPAT
871+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
872872
static void compat_standard_from_user(void *dst, const void *src)
873873
{
874874
int v = *(compat_int_t *)src;
@@ -957,15 +957,15 @@ static int get_info(struct net *net, void __user *user, const int *len)
957957
return -EFAULT;
958958

959959
name[XT_TABLE_MAXNAMELEN-1] = '\0';
960-
#ifdef CONFIG_COMPAT
960+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
961961
if (in_compat_syscall())
962962
xt_compat_lock(AF_INET);
963963
#endif
964964
t = xt_request_find_table_lock(net, AF_INET, name);
965965
if (!IS_ERR(t)) {
966966
struct ipt_getinfo info;
967967
const struct xt_table_info *private = t->private;
968-
#ifdef CONFIG_COMPAT
968+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
969969
struct xt_table_info tmp;
970970

971971
if (in_compat_syscall()) {
@@ -993,7 +993,7 @@ static int get_info(struct net *net, void __user *user, const int *len)
993993
module_put(t->me);
994994
} else
995995
ret = PTR_ERR(t);
996-
#ifdef CONFIG_COMPAT
996+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
997997
if (in_compat_syscall())
998998
xt_compat_unlock(AF_INET);
999999
#endif
@@ -1199,7 +1199,7 @@ do_add_counters(struct net *net, sockptr_t arg, unsigned int len)
11991199
return ret;
12001200
}
12011201

1202-
#ifdef CONFIG_COMPAT
1202+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
12031203
struct compat_ipt_replace {
12041204
char name[XT_TABLE_MAXNAMELEN];
12051205
u32 valid_hooks;
@@ -1621,7 +1621,7 @@ do_ipt_set_ctl(struct sock *sk, int cmd, sockptr_t arg, unsigned int len)
16211621

16221622
switch (cmd) {
16231623
case IPT_SO_SET_REPLACE:
1624-
#ifdef CONFIG_COMPAT
1624+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
16251625
if (in_compat_syscall())
16261626
ret = compat_do_replace(sock_net(sk), arg, len);
16271627
else
@@ -1654,7 +1654,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
16541654
break;
16551655

16561656
case IPT_SO_GET_ENTRIES:
1657-
#ifdef CONFIG_COMPAT
1657+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
16581658
if (in_compat_syscall())
16591659
ret = compat_get_entries(sock_net(sk), user, len);
16601660
else
@@ -1846,7 +1846,7 @@ static struct xt_target ipt_builtin_tg[] __read_mostly = {
18461846
.name = XT_STANDARD_TARGET,
18471847
.targetsize = sizeof(int),
18481848
.family = NFPROTO_IPV4,
1849-
#ifdef CONFIG_COMPAT
1849+
#ifdef CONFIG_NETFILTER_XTABLES_COMPAT
18501850
.compatsize = sizeof(compat_int_t),
18511851
.compat_from_user = compat_standard_from_user,
18521852
.compat_to_user = compat_standard_to_user,

0 commit comments

Comments
 (0)