Skip to content

Commit 768b658

Browse files
committed
net/sched: cls_u32: Fix reference counter leak leading to overflow
jira VULN-8824 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 a242e08 commit 768b658

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

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

726+
if (tb[TCA_U32_INDEV]) {
727+
ifindex = tcf_change_indev(net, tb[TCA_U32_INDEV], extack);
728+
if (ifindex < 0)
729+
return -EINVAL;
730+
}
731+
726732
if (tb[TCA_U32_LINK]) {
727733
u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
728734
struct tc_u_hnode *ht_down = NULL, *ht_old;
@@ -757,13 +763,9 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
757763
tcf_bind_filter(tp, &n->res, base);
758764
}
759765

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

0 commit comments

Comments
 (0)