Skip to content

Commit 04c5538

Browse files
lag-linarodavem330
authored andcommitted
net/sched: cls_u32: Fix reference counter leak leading to overflow
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]>
1 parent be3618d commit 04c5538

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
@@ -718,13 +718,19 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
718718
struct nlattr *est, u32 flags, u32 fl_flags,
719719
struct netlink_ext_ack *extack)
720720
{
721-
int err;
721+
int err, ifindex = -1;
722722

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

728+
if (tb[TCA_U32_INDEV]) {
729+
ifindex = tcf_change_indev(net, tb[TCA_U32_INDEV], extack);
730+
if (ifindex < 0)
731+
return -EINVAL;
732+
}
733+
728734
if (tb[TCA_U32_LINK]) {
729735
u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
730736
struct tc_u_hnode *ht_down = NULL, *ht_old;
@@ -759,13 +765,9 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
759765
tcf_bind_filter(tp, &n->res, base);
760766
}
761767

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

0 commit comments

Comments
 (0)