[PATCH] net: sched: sch_multiq: fix possible OOB write in multiq_tune()

Hangyu Hua posted 1 patch 1 year, 8 months ago
net/sched/sch_multiq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] net: sched: sch_multiq: fix possible OOB write in multiq_tune()
Posted by Hangyu Hua 1 year, 8 months ago
q->bands will be assigned to qopt->bands to execute subsequent code logic
after kmalloc. So the old q->bands should not be used in kmalloc.
Otherwise, an out-of-bounds write will occur.

Fixes: c2999f7fb05b ("net: sched: multiq: don't call qdisc_put() while holding tree lock")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 net/sched/sch_multiq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c
index 79e93a19d5fa..06e03f5cd7ce 100644
--- a/net/sched/sch_multiq.c
+++ b/net/sched/sch_multiq.c
@@ -185,7 +185,7 @@ static int multiq_tune(struct Qdisc *sch, struct nlattr *opt,
 
 	qopt->bands = qdisc_dev(sch)->real_num_tx_queues;
 
-	removed = kmalloc(sizeof(*removed) * (q->max_bands - q->bands),
+	removed = kmalloc(sizeof(*removed) * (q->max_bands - qopt->bands),
 			  GFP_KERNEL);
 	if (!removed)
 		return -ENOMEM;
-- 
2.34.1
Re: [PATCH] net: sched: sch_multiq: fix possible OOB write in multiq_tune()
Posted by Cong Wang 1 year, 8 months ago
On Mon, Jun 03, 2024 at 03:13:03PM +0800, Hangyu Hua wrote:
> q->bands will be assigned to qopt->bands to execute subsequent code logic
> after kmalloc. So the old q->bands should not be used in kmalloc.
> Otherwise, an out-of-bounds write will occur.
> 
> Fixes: c2999f7fb05b ("net: sched: multiq: don't call qdisc_put() while holding tree lock")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>

Looks good to me.

Acked-by: Cong Wang <cong.wang@bytedance.com>

Thanks.