Skip to content

Commit b6fe26f

Browse files
committed
netfilter: xtables: restrict several matches to inet family
This is a partial revert of: commit ab4f21e ("netfilter: xtables: use NFPROTO_UNSPEC in more extensions") to allow ipv4 and ipv6 only. - xt_mac - xt_owner - xt_physdev These extensions are not used by ebtables in userspace. Moreover, xt_realm is only for ipv4, since dst->tclassid is ipv4 specific. Fixes: ab4f21e ("netfilter: xtables: use NFPROTO_UNSPEC in more extensions") Reported-by: "Kito Xu (veritas501)" <hxzene@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 6e7066b commit b6fe26f

4 files changed

Lines changed: 68 additions & 34 deletions

File tree

net/netfilter/xt_mac.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,37 @@ static bool mac_mt(const struct sk_buff *skb, struct xt_action_param *par)
3636
return ret;
3737
}
3838

39-
static struct xt_match mac_mt_reg __read_mostly = {
40-
.name = "mac",
41-
.revision = 0,
42-
.family = NFPROTO_UNSPEC,
43-
.match = mac_mt,
44-
.matchsize = sizeof(struct xt_mac_info),
45-
.hooks = (1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_IN) |
46-
(1 << NF_INET_FORWARD),
47-
.me = THIS_MODULE,
39+
static struct xt_match mac_mt_reg[] __read_mostly = {
40+
{
41+
.name = "mac",
42+
.family = NFPROTO_IPV4,
43+
.match = mac_mt,
44+
.matchsize = sizeof(struct xt_mac_info),
45+
.hooks = (1 << NF_INET_PRE_ROUTING) |
46+
(1 << NF_INET_LOCAL_IN) |
47+
(1 << NF_INET_FORWARD),
48+
.me = THIS_MODULE,
49+
},
50+
{
51+
.name = "mac",
52+
.family = NFPROTO_IPV6,
53+
.match = mac_mt,
54+
.matchsize = sizeof(struct xt_mac_info),
55+
.hooks = (1 << NF_INET_PRE_ROUTING) |
56+
(1 << NF_INET_LOCAL_IN) |
57+
(1 << NF_INET_FORWARD),
58+
.me = THIS_MODULE,
59+
},
4860
};
4961

5062
static int __init mac_mt_init(void)
5163
{
52-
return xt_register_match(&mac_mt_reg);
64+
return xt_register_matches(mac_mt_reg, ARRAY_SIZE(mac_mt_reg));
5365
}
5466

5567
static void __exit mac_mt_exit(void)
5668
{
57-
xt_unregister_match(&mac_mt_reg);
69+
xt_unregister_matches(mac_mt_reg, ARRAY_SIZE(mac_mt_reg));
5870
}
5971

6072
module_init(mac_mt_init);

net/netfilter/xt_owner.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,39 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par)
127127
return true;
128128
}
129129

130-
static struct xt_match owner_mt_reg __read_mostly = {
131-
.name = "owner",
132-
.revision = 1,
133-
.family = NFPROTO_UNSPEC,
134-
.checkentry = owner_check,
135-
.match = owner_mt,
136-
.matchsize = sizeof(struct xt_owner_match_info),
137-
.hooks = (1 << NF_INET_LOCAL_OUT) |
138-
(1 << NF_INET_POST_ROUTING),
139-
.me = THIS_MODULE,
130+
static struct xt_match owner_mt_reg[] __read_mostly = {
131+
{
132+
.name = "owner",
133+
.revision = 1,
134+
.family = NFPROTO_IPV4,
135+
.checkentry = owner_check,
136+
.match = owner_mt,
137+
.matchsize = sizeof(struct xt_owner_match_info),
138+
.hooks = (1 << NF_INET_LOCAL_OUT) |
139+
(1 << NF_INET_POST_ROUTING),
140+
.me = THIS_MODULE,
141+
},
142+
{
143+
.name = "owner",
144+
.revision = 1,
145+
.family = NFPROTO_IPV6,
146+
.checkentry = owner_check,
147+
.match = owner_mt,
148+
.matchsize = sizeof(struct xt_owner_match_info),
149+
.hooks = (1 << NF_INET_LOCAL_OUT) |
150+
(1 << NF_INET_POST_ROUTING),
151+
.me = THIS_MODULE,
152+
}
140153
};
141154

142155
static int __init owner_mt_init(void)
143156
{
144-
return xt_register_match(&owner_mt_reg);
157+
return xt_register_matches(owner_mt_reg, ARRAY_SIZE(owner_mt_reg));
145158
}
146159

147160
static void __exit owner_mt_exit(void)
148161
{
149-
xt_unregister_match(&owner_mt_reg);
162+
xt_unregister_matches(owner_mt_reg, ARRAY_SIZE(owner_mt_reg));
150163
}
151164

152165
module_init(owner_mt_init);

net/netfilter/xt_physdev.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,24 +137,33 @@ static int physdev_mt_check(const struct xt_mtchk_param *par)
137137
return 0;
138138
}
139139

140-
static struct xt_match physdev_mt_reg __read_mostly = {
141-
.name = "physdev",
142-
.revision = 0,
143-
.family = NFPROTO_UNSPEC,
144-
.checkentry = physdev_mt_check,
145-
.match = physdev_mt,
146-
.matchsize = sizeof(struct xt_physdev_info),
147-
.me = THIS_MODULE,
140+
static struct xt_match physdev_mt_reg[] __read_mostly = {
141+
{
142+
.name = "physdev",
143+
.family = NFPROTO_IPV4,
144+
.checkentry = physdev_mt_check,
145+
.match = physdev_mt,
146+
.matchsize = sizeof(struct xt_physdev_info),
147+
.me = THIS_MODULE,
148+
},
149+
{
150+
.name = "physdev",
151+
.family = NFPROTO_IPV6,
152+
.checkentry = physdev_mt_check,
153+
.match = physdev_mt,
154+
.matchsize = sizeof(struct xt_physdev_info),
155+
.me = THIS_MODULE,
156+
},
148157
};
149158

150159
static int __init physdev_mt_init(void)
151160
{
152-
return xt_register_match(&physdev_mt_reg);
161+
return xt_register_matches(physdev_mt_reg, ARRAY_SIZE(physdev_mt_reg));
153162
}
154163

155164
static void __exit physdev_mt_exit(void)
156165
{
157-
xt_unregister_match(&physdev_mt_reg);
166+
xt_unregister_matches(physdev_mt_reg, ARRAY_SIZE(physdev_mt_reg));
158167
}
159168

160169
module_init(physdev_mt_init);

net/netfilter/xt_realm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static struct xt_match realm_mt_reg __read_mostly = {
3333
.matchsize = sizeof(struct xt_realm_info),
3434
.hooks = (1 << NF_INET_POST_ROUTING) | (1 << NF_INET_FORWARD) |
3535
(1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_LOCAL_IN),
36-
.family = NFPROTO_UNSPEC,
36+
.family = NFPROTO_IPV4,
3737
.me = THIS_MODULE
3838
};
3939

0 commit comments

Comments
 (0)