Skip to content

Commit fa44042

Browse files
committed
Merge branch 'net_sched-fix-uaf-vulnerability-in-hfsc-qdisc'
Cong Wang says: ==================== net_sched: Fix UAF vulnerability in HFSC qdisc This patchset contains two bug fixes and a selftest for the first one which we have a reliable reproducer, please check each patch description for details. ==================== Link: https://patch.msgid.link/20250417184732.943057-1-xiyou.wangcong@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents d861a5d + 7629d1a commit fa44042

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

net/sched/sch_hfsc.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
961961

962962
if (cl != NULL) {
963963
int old_flags;
964+
int len = 0;
964965

965966
if (parentid) {
966967
if (cl->cl_parent &&
@@ -991,9 +992,13 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
991992
if (usc != NULL)
992993
hfsc_change_usc(cl, usc, cur_time);
993994

995+
if (cl->qdisc->q.qlen != 0)
996+
len = qdisc_peek_len(cl->qdisc);
997+
/* Check queue length again since some qdisc implementations
998+
* (e.g., netem/codel) might empty the queue during the peek
999+
* operation.
1000+
*/
9941001
if (cl->qdisc->q.qlen != 0) {
995-
int len = qdisc_peek_len(cl->qdisc);
996-
9971002
if (cl->cl_flags & HFSC_RSC) {
9981003
if (old_flags & HFSC_RSC)
9991004
update_ed(cl, len);
@@ -1636,10 +1641,16 @@ hfsc_dequeue(struct Qdisc *sch)
16361641
if (cl->qdisc->q.qlen != 0) {
16371642
/* update ed */
16381643
next_len = qdisc_peek_len(cl->qdisc);
1639-
if (realtime)
1640-
update_ed(cl, next_len);
1641-
else
1642-
update_d(cl, next_len);
1644+
/* Check queue length again since some qdisc implementations
1645+
* (e.g., netem/codel) might empty the queue during the peek
1646+
* operation.
1647+
*/
1648+
if (cl->qdisc->q.qlen != 0) {
1649+
if (realtime)
1650+
update_ed(cl, next_len);
1651+
else
1652+
update_d(cl, next_len);
1653+
}
16431654
} else {
16441655
/* the class becomes passive */
16451656
eltree_remove(cl);

tools/testing/selftests/tc-testing/tc-tests/infra/qdiscs.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,44 @@
313313
"$TC qdisc del dev $DUMMY handle 1: root",
314314
"$IP addr del 10.10.10.10/24 dev $DUMMY || true"
315315
]
316+
},
317+
{
318+
"id": "a4c3",
319+
"name": "Test HFSC with netem/blackhole - queue emptying during peek operation",
320+
"category": [
321+
"qdisc",
322+
"hfsc",
323+
"netem",
324+
"blackhole"
325+
],
326+
"plugins": {
327+
"requires": "nsPlugin"
328+
},
329+
"setup": [
330+
"$IP link set dev $DUMMY up || true",
331+
"$IP addr add 10.10.10.10/24 dev $DUMMY || true",
332+
"$TC qdisc add dev $DUMMY handle 1:0 root drr",
333+
"$TC class add dev $DUMMY parent 1:0 classid 1:1 drr",
334+
"$TC class add dev $DUMMY parent 1:0 classid 1:2 drr",
335+
"$TC qdisc add dev $DUMMY parent 1:1 handle 2:0 plug limit 1024",
336+
"$TC qdisc add dev $DUMMY parent 1:2 handle 3:0 hfsc default 1",
337+
"$TC class add dev $DUMMY parent 3:0 classid 3:1 hfsc rt m1 5Mbit d 10ms m2 10Mbit",
338+
"$TC qdisc add dev $DUMMY parent 3:1 handle 4:0 netem delay 1ms",
339+
"$TC qdisc add dev $DUMMY parent 4:1 handle 5:0 blackhole",
340+
"ping -c 3 -W 0.01 -i 0.001 -s 1 10.10.10.10 -I $DUMMY > /dev/null 2>&1 || true",
341+
"$TC class change dev $DUMMY parent 3:0 classid 3:1 hfsc sc m1 5Mbit d 10ms m2 10Mbit",
342+
"$TC class del dev $DUMMY parent 3:0 classid 3:1",
343+
"$TC class add dev $DUMMY parent 3:0 classid 3:1 hfsc rt m1 5Mbit d 10ms m2 10Mbit",
344+
"ping -c 3 -W 0.01 -i 0.001 -s 1 10.10.10.10 -I $DUMMY > /dev/null 2>&1 || true"
345+
],
346+
"cmdUnderTest": "$TC class change dev $DUMMY parent 3:0 classid 3:1 hfsc sc m1 5Mbit d 10ms m2 10Mbit",
347+
"expExitCode": "0",
348+
"verifyCmd": "$TC -s qdisc show dev $DUMMY",
349+
"matchPattern": "qdisc hfsc 3:.*parent 1:2.*default 1",
350+
"matchCount": "1",
351+
"teardown": [
352+
"$TC qdisc del dev $DUMMY handle 1:0 root",
353+
"$IP addr del 10.10.10.10/24 dev $DUMMY || true"
354+
]
316355
}
317356
]

0 commit comments

Comments
 (0)