Skip to content

Commit fb66df2

Browse files
vladimirolteankuba-moo
authored andcommitted
net/sched: taprio: extend minimum interval restriction to entire cycle too
It is possible for syzbot to side-step the restriction imposed by the blamed commit in the Fixes: tag, because the taprio UAPI permits a cycle-time different from (and potentially shorter than) the sum of entry intervals. We need one more restriction, which is that the cycle time itself must be larger than N * ETH_ZLEN bit times, where N is the number of schedule entries. This restriction needs to apply regardless of whether the cycle time came from the user or was the implicit, auto-calculated value, so we move the existing "cycle == 0" check outside the "if "(!new->cycle_time)" branch. This way covers both conditions and scenarios. Add a selftest which illustrates the issue triggered by syzbot. Fixes: b5b73b2 ("taprio: Fix allowing too small intervals") Reported-by: [email protected] Closes: https://lore.kernel.org/netdev/[email protected]/ Signed-off-by: Vladimir Oltean <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e634134 commit fb66df2

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

net/sched/sch_taprio.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,11 +1151,6 @@ static int parse_taprio_schedule(struct taprio_sched *q, struct nlattr **tb,
11511151
list_for_each_entry(entry, &new->entries, list)
11521152
cycle = ktime_add_ns(cycle, entry->interval);
11531153

1154-
if (!cycle) {
1155-
NL_SET_ERR_MSG(extack, "'cycle_time' can never be 0");
1156-
return -EINVAL;
1157-
}
1158-
11591154
if (cycle < 0 || cycle > INT_MAX) {
11601155
NL_SET_ERR_MSG(extack, "'cycle_time' is too big");
11611156
return -EINVAL;
@@ -1164,6 +1159,11 @@ static int parse_taprio_schedule(struct taprio_sched *q, struct nlattr **tb,
11641159
new->cycle_time = cycle;
11651160
}
11661161

1162+
if (new->cycle_time < new->num_entries * length_to_duration(q, ETH_ZLEN)) {
1163+
NL_SET_ERR_MSG(extack, "'cycle_time' is too small");
1164+
return -EINVAL;
1165+
}
1166+
11671167
taprio_calculate_gate_durations(q, new);
11681168

11691169
return 0;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,28 @@
154154
"echo \"1\" > /sys/bus/netdevsim/del_device"
155155
]
156156
},
157+
{
158+
"id": "831f",
159+
"name": "Add taprio Qdisc with too short cycle-time",
160+
"category": [
161+
"qdisc",
162+
"taprio"
163+
],
164+
"plugins": {
165+
"requires": "nsPlugin"
166+
},
167+
"setup": [
168+
"echo \"1 1 8\" > /sys/bus/netdevsim/new_device"
169+
],
170+
"cmdUnderTest": "$TC qdisc add dev $ETH root handle 1: taprio num_tc 2 queues 1@0 1@1 sched-entry S 01 200000 sched-entry S 02 200000 cycle-time 100 clockid CLOCK_TAI",
171+
"expExitCode": "2",
172+
"verifyCmd": "$TC qdisc show dev $ETH",
173+
"matchPattern": "qdisc taprio 1: root refcnt",
174+
"matchCount": "0",
175+
"teardown": [
176+
"echo \"1\" > /sys/bus/netdevsim/del_device"
177+
]
178+
},
157179
{
158180
"id": "3e1e",
159181
"name": "Add taprio Qdisc with an invalid cycle-time",

0 commit comments

Comments
 (0)