Skip to content

Commit 689a91f

Browse files
ummakynesgregkh
authored andcommitted
netfilter: xtables: restrict several matches to inet family
[ Upstream commit b6fe26f ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a8e0a32 commit 689a91f

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
@@ -38,25 +38,37 @@ static bool mac_mt(const struct sk_buff *skb, struct xt_action_param *par)
3838
return ret;
3939
}
4040

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

5264
static int __init mac_mt_init(void)
5365
{
54-
return xt_register_match(&mac_mt_reg);
66+
return xt_register_matches(mac_mt_reg, ARRAY_SIZE(mac_mt_reg));
5567
}
5668

5769
static void __exit mac_mt_exit(void)
5870
{
59-
xt_unregister_match(&mac_mt_reg);
71+
xt_unregister_matches(mac_mt_reg, ARRAY_SIZE(mac_mt_reg));
6072
}
6173

6274
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
@@ -115,24 +115,33 @@ static int physdev_mt_check(const struct xt_mtchk_param *par)
115115
return 0;
116116
}
117117

118-
static struct xt_match physdev_mt_reg __read_mostly = {
119-
.name = "physdev",
120-
.revision = 0,
121-
.family = NFPROTO_UNSPEC,
122-
.checkentry = physdev_mt_check,
123-
.match = physdev_mt,
124-
.matchsize = sizeof(struct xt_physdev_info),
125-
.me = THIS_MODULE,
118+
static struct xt_match physdev_mt_reg[] __read_mostly = {
119+
{
120+
.name = "physdev",
121+
.family = NFPROTO_IPV4,
122+
.checkentry = physdev_mt_check,
123+
.match = physdev_mt,
124+
.matchsize = sizeof(struct xt_physdev_info),
125+
.me = THIS_MODULE,
126+
},
127+
{
128+
.name = "physdev",
129+
.family = NFPROTO_IPV6,
130+
.checkentry = physdev_mt_check,
131+
.match = physdev_mt,
132+
.matchsize = sizeof(struct xt_physdev_info),
133+
.me = THIS_MODULE,
134+
},
126135
};
127136

128137
static int __init physdev_mt_init(void)
129138
{
130-
return xt_register_match(&physdev_mt_reg);
139+
return xt_register_matches(physdev_mt_reg, ARRAY_SIZE(physdev_mt_reg));
131140
}
132141

133142
static void __exit physdev_mt_exit(void)
134143
{
135-
xt_unregister_match(&physdev_mt_reg);
144+
xt_unregister_matches(physdev_mt_reg, ARRAY_SIZE(physdev_mt_reg));
136145
}
137146

138147
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)