Skip to content

Commit 0323bce

Browse files
M A Ramdhankuba-moo
authored andcommitted
net/sched: cls_fw: Fix improper refcount update leads to use-after-free
In the event of a failure in tcf_change_indev(), fw_set_parms() will immediately return an error after incrementing or decrementing reference counter in tcf_bind_filter(). If attacker can control reference counter to zero and make reference freed, leading to use after free. In order to prevent this, move the point of possible failure above the point where the TC_FW_CLASSID is handled. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: M A Ramdhan <ramdhan@starlabs.sg> Signed-off-by: M A Ramdhan <ramdhan@starlabs.sg> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Reviewed-by: Pedro Tammela <pctammela@mojatatu.com> Message-ID: <20230705161530.52003-1-ramdhan@starlabs.sg> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 525c469 commit 0323bce

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

net/sched/cls_fw.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,6 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,
212212
if (err < 0)
213213
return err;
214214

215-
if (tb[TCA_FW_CLASSID]) {
216-
f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]);
217-
tcf_bind_filter(tp, &f->res, base);
218-
}
219-
220215
if (tb[TCA_FW_INDEV]) {
221216
int ret;
222217
ret = tcf_change_indev(net, tb[TCA_FW_INDEV], extack);
@@ -233,6 +228,11 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,
233228
} else if (head->mask != 0xFFFFFFFF)
234229
return err;
235230

231+
if (tb[TCA_FW_CLASSID]) {
232+
f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]);
233+
tcf_bind_filter(tp, &f->res, base);
234+
}
235+
236236
return 0;
237237
}
238238

0 commit comments

Comments
 (0)