Skip to content

Commit c7d1335

Browse files
committed
netfilter: xt_SECMARK: add new revision to fix structure layout
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]>
1 parent bd1af6b commit c7d1335

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
@@ -24,10 +24,9 @@ MODULE_ALIAS("ip6t_SECMARK");
2424
static u8 mode;
2525

2626
static unsigned int
27-
secmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
27+
secmark_tg(struct sk_buff *skb, const struct xt_secmark_target_info_v1 *info)
2828
{
2929
u32 secmark = 0;
30-
const struct xt_secmark_target_info *info = par->targinfo;
3130

3231
switch (mode) {
3332
case SECMARK_MODE_SEL:
@@ -41,7 +40,7 @@ secmark_tg(struct sk_buff *skb, const struct xt_action_param *par)
4140
return XT_CONTINUE;
4241
}
4342

44-
static int checkentry_lsm(struct xt_secmark_target_info *info)
43+
static int checkentry_lsm(struct xt_secmark_target_info_v1 *info)
4544
{
4645
int err;
4746

@@ -73,15 +72,15 @@ static int checkentry_lsm(struct xt_secmark_target_info *info)
7372
return 0;
7473
}
7574

76-
static int secmark_tg_check(const struct xt_tgchk_param *par)
75+
static int
76+
secmark_tg_check(const char *table, struct xt_secmark_target_info_v1 *info)
7777
{
78-
struct xt_secmark_target_info *info = par->targinfo;
7978
int err;
8079

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

@@ -116,25 +115,76 @@ static void secmark_tg_destroy(const struct xt_tgdtor_param *par)
116115
}
117116
}
118117

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

130180
static int __init secmark_tg_init(void)
131181
{
132-
return xt_register_target(&secmark_tg_reg);
182+
return xt_register_targets(secmark_tg_reg, ARRAY_SIZE(secmark_tg_reg));
133183
}
134184

135185
static void __exit secmark_tg_exit(void)
136186
{
137-
xt_unregister_target(&secmark_tg_reg);
187+
xt_unregister_targets(secmark_tg_reg, ARRAY_SIZE(secmark_tg_reg));
138188
}
139189

140190
module_init(secmark_tg_init);

0 commit comments

Comments
 (0)