net_sched: fix skb memory leak in deferred qdisc drops
Subsystems (2)
PATCH 1/1 net_sched: fix skb memory leak in deferred qdisc drops
When the network stack cleans up the deferred list via qdisc_run_end(), it operates on the root qdisc. If the root qdisc do not implement the TCQ_F_DEQUEUE_DROPS flag the packets queue to free are never freed and gets stranded on the child's local to_free list.
Fix this by making qdisc_dequeue_drop() aware of the root qdisc. It fetches the root qdisc and check for the TCQ_F_DEQUEUE_DROPS flag. If the flag is present, the packet is appended directly to the root's to_free list. Otherwise, drop it directly as it was done before the optimization was implemented.
--- include/net/sch_generic.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
include/net/sch_generic.h +9 -3
@@ -1170,12 +1170,18 @@ static inline void tcf_kfree_skb_list(struct sk_buff *skb)static inline void qdisc_dequeue_drop (struct Qdisc *q,struct sk_buff *skb,enum skb_drop_reason reason) { +struct Qdisc *root =qdisc_root_sleeping (q); +DEBUG_NET_WARN_ON_ONCE (!(q->flags &TCQ_F_DEQUEUE_DROPS ));DEBUG_NET_WARN_ON_ONCE (q->flags &TCQ_F_NOLOCK ); -tcf_set_drop_reason (skb, reason); - skb->next = q->to_free; - q->to_free = skb; +if (root->flags &TCQ_F_DEQUEUE_DROPS ) { +tcf_set_drop_reason (skb, reason); + skb->next = q->to_free; + q->to_free = skb; + }else { +kfree_skb_reason (skb, reason); + } }/* Instead of calling kfree_skb() while root qdisc lock is held,
Signature · 1 line
2.53.0
Quoted 34 lines · Fernando Fernandez Mancera
When the network stack cleans up the deferred list via
qdisc_run_end(), it operates on the root qdisc. If the root qdisc do not implement theTCQ_F_DEQUEUE_DROPSflag the packets queue to free are never freed and gets stranded on the child's localto_freelist.Fix this by making
qdisc_dequeue_drop()aware of the root qdisc. It fetches the root qdisc and check for theTCQ_F_DEQUEUE_DROPSflag. If the flag is present, the packet is appended directly to the root'sto_freelist. Otherwise, drop it directly as it was done before the optimization was implemented.Fixes a6efc273ab82 ("net_sched: use qdisc_dequeue_drop() in cake, codel, fq_codel")Reported-by Damilola Bello <[email protected]>Closes https://lore.kernel.org/netdev/CAPgFtOLaedBMU0f_BxV2bXftTJSmJr018Q5uozOo5vVo6b9tjw@mail.gmail.com/ open hereSigned-off-by Fernando Fernandez Mancera <[email protected]>--- include/net/sch_generic.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)include/net/sch_generic.h +2
-2@@ -1170,12 +1170,18 @@ static inline void tcf_kfree_skb_list(struct sk_buff *skb)static inline void qdisc_dequeue_drop (struct Qdisc *q,struct sk_buff *skb,enum skb_drop_reason reason) { +struct Qdisc *root =qdisc_root_sleeping (q); +DEBUG_NET_WARN_ON_ONCE (!(q->flags &TCQ_F_DEQUEUE_DROPS ));DEBUG_NET_WARN_ON_ONCE (q->flags &TCQ_F_NOLOCK ); -tcf_set_drop_reason (skb, reason); - skb->next = q->to_free;
include/net/sch_generic.h static inline void tcf_kfree_skb_list(struct sk_buff *skb) · line 1186
Quoted 10 lines
include/net/sch_generic.h +7
-1- q->to_free = skb; +if (root->flags &TCQ_F_DEQUEUE_DROPS ) { +tcf_set_drop_reason (skb, reason); + skb->next = q->to_free; + q->to_free = skb; + }else { +kfree_skb_reason (skb, reason); + } }
*sigh* this is missing the following diff - tested it but forgot to amend it. Anyway, Eric let me know what do you think, if you like this solution I can send the v2 appending the skb to the root's to_free list properly.
include/net/sch_generic.h +2 -2
@@ -1177,8 +1177,8 @@ static inline void qdisc_dequeue_drop(struct Qdisc *q, struct sk_buff *skb,if (root->flags &TCQ_F_DEQUEUE_DROPS ) {tcf_set_drop_reason (skb, reason); - skb->next = q->to_free; - q->to_free = skb; + skb->next = root->to_free; + root->to_free = skb; }else {kfree_skb_reason (skb, reason); }
Quoted 69 lines · Fernando Fernandez Mancera
Quoted 34 lines · Fernando Fernandez Mancera
When the network stack cleans up the deferred list via
qdisc_run_end(), it operates on the root qdisc. If the root qdisc do not implement theTCQ_F_DEQUEUE_DROPSflag the packets queue to free are never freed and gets stranded on the child's localto_freelist.Fix this by making
qdisc_dequeue_drop()aware of the root qdisc. It fetches the root qdisc and check for theTCQ_F_DEQUEUE_DROPSflag. If the flag is present, the packet is appended directly to the root'sto_freelist. Otherwise, drop it directly as it was done before the optimization was implemented.Fixes a6efc273ab82 ("net_sched: use qdisc_dequeue_drop() in cake, codel, fq_codel")Reported-by Damilola Bello <[email protected]>Closes https://lore.kernel.org/netdev/CAPgFtOLaedBMU0f_BxV2bXftTJSmJr018Q5uozOo5vVo6b9tjw@mail.gmail.com/ open hereSigned-off-by Fernando Fernandez Mancera <[email protected]>--- include/net/sch_generic.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)include/net/sch_generic.h +2
-2@@ -1170,12 +1170,18 @@ static inline void tcf_kfree_skb_list(struct sk_buff *skb)static inline void qdisc_dequeue_drop (struct Qdisc *q,struct sk_buff *skb,enum skb_drop_reason reason) { +struct Qdisc *root =qdisc_root_sleeping (q); +DEBUG_NET_WARN_ON_ONCE (!(q->flags &TCQ_F_DEQUEUE_DROPS ));DEBUG_NET_WARN_ON_ONCE (q->flags &TCQ_F_NOLOCK ); -tcf_set_drop_reason (skb, reason); - skb->next = q->to_free;include/net/sch_generic.h static inline void tcf_kfree_skb_list(struct sk_buff *skb) · line 1186
Quoted 10 lines
include/net/sch_generic.h +7
-1- q->to_free = skb; +if (root->flags &TCQ_F_DEQUEUE_DROPS ) { +tcf_set_drop_reason (skb, reason); + skb->next = q->to_free; + q->to_free = skb; + }else { +kfree_skb_reason (skb, reason); + } }*sigh* this is missing the following diff - tested it but forgot to amend it. Anyway, Eric let me know what do you think, if you like this solution I can send the v2 appending the skb to the root's
to_freelist properly.include/net/sch_generic.h +2
-2@@ -1177,8 +1177,8 @@ static inline void qdisc_dequeue_drop(struct Qdisc *q, struct sk_buff *skb, if (root->flags & TCQ_F_DEQUEUE_DROPS) {tcf_set_drop_reason (skb, reason); - skb->next = q->to_free; - q->to_free = skb; + skb->next = root->to_free; + root->to_free = skb; } else {kfree_skb_reason (skb, reason);
Quoted 2 lines
}
Sure, please also use rcu_read_lock() before calling qdisc_root_sleeping()
syzbot ci has tested the following series
syzbot ci has tested the following series
[v1] net_sched: fix skb memory leak in deferred qdisc drops
https://lore.kernel.org/all/[email protected]
* [PATCH net] net_sched: fix skb memory leak in deferred qdisc drops
and found the following issue:
WARNING: suspicious RCU usage in cake_dequeue
Full report is available here:
https://ci.syzbot.org/series/90acbb62-3e93-4bb7-af7a-51d555f5956b
***
WARNING: suspicious RCU usage in cake_dequeue
tree: net URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netdev/net.git base: a9b8b18364fffce4c451e6f6fd218fa4ab646705 arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/a5e0fad0-c9c8-4102-b2af-b4d1c7947ee3/config syz repro: https://ci.syzbot.org/findings/b1dd239a-f59f-414f-8bde-578258899e94/syz_repro
=============================
WARNING: suspicious RCU usage
syzkaller #0 Not tainted
-----------------------------./include/net/sch_generic.h:581 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
2 locks held by syz.0.51/6016:
#0: ffffffff8e75e640 (rcu_read_lock_bh){....}-{1:3}, at: local_bh_disable include/linux/bottom_half.h:20 [inline] #0: ffffffff8e75e640 (rcu_read_lock_bh){....}-{1:3}, at: rcu_read_lock_bh include/linux/rcupdate.h:903 [inline] #0: ffffffff8e75e640 (rcu_read_lock_bh){....}-{1:3}, at: __dev_queue_xmit+0x277/0x3890 net/core/dev.c:4778 #1: ffff8881ad9e8170 (&sch->root_lock_key#31){+...}-{3:3}, at: spin_lock include/linux/spinlock.h:341 [inline] #1: ffff8881ad9e8170 (&sch->root_lock_key#31){+...}-{3:3}, at: __dev_xmit_skb net/core/dev.c:4241 [inline] #1: ffff8881ad9e8170 (&sch->root_lock_key#31){+...}-{3:3}, at: __dev_queue_xmit+0xbf2/0x3890 net/core/dev.c:4819
stack backtrace: CPU: 1 UID: 0 PID: 6016 Comm: syz.0.51 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 lockdep_rcu_suspicious+0x13f/0x1d0 kernel/locking/lockdep.c:6876 qdisc_root_sleeping include/net/sch_generic.h:581 [inline] qdisc_dequeue_drop include/net/sch_generic.h:1173 [inline] cake_dequeue+0x23a7/0x4e50 net/sched/sch_cake.c:2240 dequeue_skb net/sched/sch_generic.c:297 [inline] qdisc_restart net/sched/sch_generic.c:402 [inline] __qdisc_run+0x26c/0x15d0 net/sched/sch_generic.c:420 qdisc_run include/net/pkt_sched.h:120 [inline] __dev_xmit_skb net/core/dev.c:4286 [inline] __dev_queue_xmit+0x1bad/0x3890 net/core/dev.c:4819 packet_snd net/packet/af_packet.c:3076 [inline] packet_sendmsg+0x3eb6/0x50f0 net/packet/af_packet.c:3108 sock_sendmsg_nosec net/socket.c:727 [inline] __sock_sendmsg net/socket.c:742 [inline] __sys_sendto+0x672/0x710 net/socket.c:2206 __do_sys_sendto net/socket.c:2213 [inline] __se_sys_sendto net/socket.c:2209 [inline] __x64_sys_sendto+0xde/0x100 net/socket.c:2209 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x14d/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f077b39c819 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f077c28c028 EFLAGS: 00000246 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 00007f077b615fa0 RCX: 00007f077b39c819 RDX: 000000000000fc13 RSI: 0000200000000800 RDI: 0000000000000003 RBP: 00007f077b432c91 R08: 0000000000000000 R09: fffffffffffffef0 R10: 0000000000000880 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f077b616038 R14: 00007f077b615fa0 R15: 00007fffceb20038 </TASK>
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
To test a patch for this bug, please reply with #syz test (should be on a separate line).
The patch should be attached to the email.
Note: arguments like custom git repos and branches are not supported.