Skip to content

Commit 2754a96

Browse files
committed
net/sched: cls_u32: Fix reference counter leak leading to overflow
jira VULN-6545 cve CVE-2023-3609 commit-author Lee Jones <[email protected]> commit 04c5538 In the event of a failure in tcf_change_indev(), u32_set_parms() will immediately return without decrementing the recently incremented reference counter. If this happens enough times, the counter will rollover and the reference freed, leading to a double free which can be used to do 'bad things'. In order to prevent this, move the point of possible failure above the point where the reference counter is incremented. Also save any meaningful return values to be applied to the return data at the appropriate point in time. This issue was caught with KASAN. Fixes: 705c709 ("net: sched: cls_u32: no need to call tcf_exts_change for newly allocated struct") Suggested-by: Eric Dumazet <[email protected]> Signed-off-by: Lee Jones <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit 04c5538) Signed-off-by: David Gomez <[email protected]>
1 parent 35d1c79 commit 2754a96

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

net/sched/cls_u32.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,19 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
720720
struct nlattr *est, u32 flags, u32 fl_flags,
721721
struct netlink_ext_ack *extack)
722722
{
723-
int err;
723+
int err, ifindex = -1;
724724

725725
err = tcf_exts_validate_ex(net, tp, tb, est, &n->exts, flags,
726726
fl_flags, extack);
727727
if (err < 0)
728728
return err;
729729

730+
if (tb[TCA_U32_INDEV]) {
731+
ifindex = tcf_change_indev(net, tb[TCA_U32_INDEV], extack);
732+
if (ifindex < 0)
733+
return -EINVAL;
734+
}
735+
730736
if (tb[TCA_U32_LINK]) {
731737
u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
732738
struct tc_u_hnode *ht_down = NULL, *ht_old;
@@ -761,13 +767,9 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
761767
tcf_bind_filter(tp, &n->res, base);
762768
}
763769

764-
if (tb[TCA_U32_INDEV]) {
765-
int ret;
766-
ret = tcf_change_indev(net, tb[TCA_U32_INDEV], extack);
767-
if (ret < 0)
768-
return -EINVAL;
769-
n->ifindex = ret;
770-
}
770+
if (ifindex >= 0)
771+
n->ifindex = ifindex;
772+
771773
return 0;
772774
}
773775

0 commit comments

Comments
 (0)