Skip to content

Commit f5ffa3b

Browse files
zhengchaoshaodavem330
authored andcommitted
Revert "net: sched: fq_codel: remove redundant resource cleanup in fq_codel_init()"
This reverts commit 494f506. When the default qdisc is fq_codel, if the qdisc of dev_queue fails to be inited during mqprio_init(), fq_codel_reset() is invoked to clear resources. In this case, the flow is NULL, and it will cause gpf issue. The process is as follows: qdisc_create_dflt() fq_codel_init() ... q->flows_cnt = 1024; ... q->flows = kvcalloc(...) --->failed, q->flows is NULL ... qdisc_put() ... fq_codel_reset() ... flow = q->flows + i --->q->flows is NULL The following is the Call Trace information: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:fq_codel_reset+0x14d/0x350 Call Trace: <TASK> qdisc_reset+0xed/0x6f0 qdisc_destroy+0x82/0x4c0 qdisc_put+0x9e/0xb0 qdisc_create_dflt+0x2c3/0x4a0 mqprio_init+0xa71/0x1760 qdisc_create+0x3eb/0x1000 tc_modify_qdisc+0x408/0x1720 rtnetlink_rcv_msg+0x38e/0xac0 netlink_rcv_skb+0x12d/0x3a0 netlink_unicast+0x4a2/0x740 netlink_sendmsg+0x826/0xcc0 sock_sendmsg+0xc5/0x100 ____sys_sendmsg+0x583/0x690 ___sys_sendmsg+0xe8/0x160 __sys_sendmsg+0xbf/0x160 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0 RIP: 0033:0x7fd272b22d04 </TASK> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 51f9a89 commit f5ffa3b

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

net/sched/sch_fq_codel.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,24 +478,26 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
478478
if (opt) {
479479
err = fq_codel_change(sch, opt, extack);
480480
if (err)
481-
return err;
481+
goto init_failure;
482482
}
483483

484484
err = tcf_block_get(&q->block, &q->filter_list, sch, extack);
485485
if (err)
486-
return err;
486+
goto init_failure;
487487

488488
if (!q->flows) {
489489
q->flows = kvcalloc(q->flows_cnt,
490490
sizeof(struct fq_codel_flow),
491491
GFP_KERNEL);
492-
if (!q->flows)
493-
return -ENOMEM;
494-
492+
if (!q->flows) {
493+
err = -ENOMEM;
494+
goto init_failure;
495+
}
495496
q->backlogs = kvcalloc(q->flows_cnt, sizeof(u32), GFP_KERNEL);
496-
if (!q->backlogs)
497-
return -ENOMEM;
498-
497+
if (!q->backlogs) {
498+
err = -ENOMEM;
499+
goto alloc_failure;
500+
}
499501
for (i = 0; i < q->flows_cnt; i++) {
500502
struct fq_codel_flow *flow = q->flows + i;
501503

@@ -508,6 +510,13 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt,
508510
else
509511
sch->flags &= ~TCQ_F_CAN_BYPASS;
510512
return 0;
513+
514+
alloc_failure:
515+
kvfree(q->flows);
516+
q->flows = NULL;
517+
init_failure:
518+
q->flows_cnt = 0;
519+
return err;
511520
}
512521

513522
static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)

0 commit comments

Comments
 (0)