Skip to content

Commit 9e3cbdc

Browse files
ummakynesgregkh
authored andcommitted
netfilter: xt_SECMARK: add new revision to fix structure layout
[ Upstream commit c7d1335 ] This extension breaks when trying to delete rules, add a new revision to fix this. Fixes: 5e6874c ("[SECMARK]: Add xtables SECMARK target") Signed-off-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 7a0a9f5 commit 9e3cbdc

File tree

2 files changed

+75
-19
lines changed

2 files changed

+75
-19
lines changed

include/uapi/linux/netfilter/xt_SECMARK.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ struct xt_secmark_target_info {
2020
char secctx[SECMARK_SECCTX_MAX];
2121
};
2222

23+
struct xt_secmark_target_info_v1 {
24+
__u8 mode;
25+
char secctx[SECMARK_SECCTX_MAX];
26+
__u32 secid;
27+
};
28+
2329
#endif /*_XT_SECMARK_H_target */

net/netfilter/xt_SECMARK.c

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ MODULE_ALIAS("ip6t_SECMARK");
2626
static u8 mode;
2727

2828
static unsigned int
29-
secmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
29+
secmark_tg(struct sk_buff *skb, const struct xt_secmark_target_info_v1 *info)
3030
{
3131
u32 secmark = 0;
32-
const struct xt_secmark_target_info *info = par->targinfo;
3332

3433
switch (mode) {
3534
case SECMARK_MODE_SEL:
@@ -43,7 +42,7 @@ secmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
4342
return XT_CONTINUE;
4443
}
4544

46-
static int checkentry_lsm(struct xt_secmark_target_info *info)
45+
static int checkentry_lsm(struct xt_secmark_target_info_v1 *info)
4746
{
4847
int err;
4948

@@ -75,15 +74,15 @@ static int checkentry_lsm(struct xt_secmark_target_info *info)
7574
return 0;
7675
}
7776

78-
static int secmark_tg_check(const struct xt_tgchk_param *par)
77+
static int
78+
secmark_tg_check(const char *table, struct xt_secmark_target_info_v1 *info)
7979
{
80-
struct xt_secmark_target_info *info = par->targinfo;
8180
int err;
8281

83-
if (strcmp(par->table, "mangle") != 0 &&
84-
strcmp(par->table, "security") != 0) {
82+
if (strcmp(table, "mangle") != 0 &&
83+
strcmp(table, "security") != 0) {
8584
pr_info_ratelimited("only valid in \'mangle\' or \'security\' table, not \'%s\'\n",
86-
par->table);
85+
table);
8786
return -EINVAL;
8887
}
8988

@@ -118,25 +117,76 @@ static void secmark_tg_destroy(const struct xt_tgdtor_param *par)
118117
}
119118
}
120119

121-
static struct xt_target secmark_tg_reg __read_mostly = {
122-
.name = "SECMARK",
123-
.revision = 0,
124-
.family = NFPROTO_UNSPEC,
125-
.checkentry = secmark_tg_check,
126-
.destroy = secmark_tg_destroy,
127-
.target = secmark_tg,
128-
.targetsize = sizeof(struct xt_secmark_target_info),
129-
.me = THIS_MODULE,
120+
static int secmark_tg_check_v0(const struct xt_tgchk_param *par)
121+
{
122+
struct xt_secmark_target_info *info = par->targinfo;
123+
struct xt_secmark_target_info_v1 newinfo = {
124+
.mode = info->mode,
125+
};
126+
int ret;
127+
128+
memcpy(newinfo.secctx, info->secctx, SECMARK_SECCTX_MAX);
129+
130+
ret = secmark_tg_check(par->table, &newinfo);
131+
info->secid = newinfo.secid;
132+
133+
return ret;
134+
}
135+
136+
static unsigned int
137+
secmark_tg_v0(struct sk_buff *skb, const struct xt_action_param *par)
138+
{
139+
const struct xt_secmark_target_info *info = par->targinfo;
140+
struct xt_secmark_target_info_v1 newinfo = {
141+
.secid = info->secid,
142+
};
143+
144+
return secmark_tg(skb, &newinfo);
145+
}
146+
147+
static int secmark_tg_check_v1(const struct xt_tgchk_param *par)
148+
{
149+
return secmark_tg_check(par->table, par->targinfo);
150+
}
151+
152+
static unsigned int
153+
secmark_tg_v1(struct sk_buff *skb, const struct xt_action_param *par)
154+
{
155+
return secmark_tg(skb, par->targinfo);
156+
}
157+
158+
static struct xt_target secmark_tg_reg[] __read_mostly = {
159+
{
160+
.name = "SECMARK",
161+
.revision = 0,
162+
.family = NFPROTO_UNSPEC,
163+
.checkentry = secmark_tg_check_v0,
164+
.destroy = secmark_tg_destroy,
165+
.target = secmark_tg_v0,
166+
.targetsize = sizeof(struct xt_secmark_target_info),
167+
.me = THIS_MODULE,
168+
},
169+
{
170+
.name = "SECMARK",
171+
.revision = 1,
172+
.family = NFPROTO_UNSPEC,
173+
.checkentry = secmark_tg_check_v1,
174+
.destroy = secmark_tg_destroy,
175+
.target = secmark_tg_v1,
176+
.targetsize = sizeof(struct xt_secmark_target_info_v1),
177+
.usersize = offsetof(struct xt_secmark_target_info_v1, secid),
178+
.me = THIS_MODULE,
179+
},
130180
};
131181

132182
static int __init secmark_tg_init(void)
133183
{
134-
return xt_register_target(&secmark_tg_reg);
184+
return xt_register_targets(secmark_tg_reg, ARRAY_SIZE(secmark_tg_reg));
135185
}
136186

137187
static void __exit secmark_tg_exit(void)
138188
{
139-
xt_unregister_target(&secmark_tg_reg);
189+
xt_unregister_targets(secmark_tg_reg, ARRAY_SIZE(secmark_tg_reg));
140190
}
141191

142192
module_init(secmark_tg_init);

0 commit comments

Comments
 (0)