taprio: Add boundary check for sched-entry values
Subsystems (4)
PATCH v2 1/1 taprio: Add boundary check for sched-entry values
Adds boundary checks for the gatemask provided against the number of traffic class defined for each sched-entry.
Without this check, the user would not know that the gatemask provided is invalid and the driver has already truncated the gatemask provided to match the number of traffic class defined.
--- net/sched/sch_taprio.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/sched/sch_taprio.c +8 -0
@@ -102,6 +102,7 @@ struct taprio_sched {u32 max_sdu[TC_MAX_QUEUE ];/* save info from the user */ u32 fp[TC_QOPT_MAX_QUEUE ];/* only for dump and offloading */ u32 txtime_delay; +u8 num_tc; };struct __tc_taprio_qopt_offload {
@@ -1063,6 +1064,11 @@ static int fill_sched_entry(struct taprio_sched *q, struct nlattr **tb,return -EINVAL ; } +if (entry->gate_mask >= q->num_tc) { +NL_SET_ERR_MSG (extack,"Traffic Class defined less than gatemask" ); +return -EINVAL ; + } + entry->interval = interval;return 0 ;
@@ -1913,6 +1919,8 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,for (i =0 ; i <=TC_BITMASK ; i++)netdev_set_prio_tc_map (dev, i, mqprio->prio_tc_map[i]); + + q->num_tc = mqprio->num_tc; } err =parse_taprio_schedule (q, tb, new_admin, extack);
Signature · 1 line
1.9.1
Quoted 27 lines · Lai Peter Jun Ann
Adds boundary checks for the gatemask provided against the number of traffic class defined for each sched-entry.
Without this check, the user would not know that the gatemask provided is invalid and the driver has already truncated the gatemask provided to match the number of traffic class defined.
Signed-off-by Muhammad Husaini Zulkifli <[email protected]>Signed-off-by Michael Sit Wei Hong <[email protected]>Signed-off-by Lai Peter Jun Ann <[email protected]>--- net/sched/sch_taprio.c | 8 ++++++++ 1 file changed, 8 insertions(+)net/sched/sch_taprio.c +1
-0@@ -102,6 +102,7 @@ struct taprio_sched {u32 max_sdu[TC_MAX_QUEUE ];/* save info from the user */ u32 fp[TC_QOPT_MAX_QUEUE ];/* only for dump and offloading */ u32 txtime_delay; +u8 num_tc; };struct __tc_taprio_qopt_offload {
net/sched/sch_taprio.c static int fill_sched_entry(struct taprio_sched *q, struct nlattr **tb, · line 1067
Quoted 4 lines
net/sched/sch_taprio.c +1
-0@@ -1063,6 +1064,11 @@ static int fill_sched_entry(struct taprio_sched *q, struct nlattr **tb,return -EINVAL ; } +if (entry->gate_mask >= q->num_tc) {
As far as I know within gate_mask every bit represents a traffic class. So for 3 traffic classes at gate_mask of 0x7 is valid but this check fails with 0x7 >= 3.
Quoted 16 lines
net/sched/sch_taprio.c +6
-0+NL_SET_ERR_MSG (extack,"Traffic Class defined less than gatemask" ); +return -EINVAL ; + } + entry->interval = interval;return 0 ;@@ -1913,6 +1919,8 @@ static int taprio_change(struct Qdisc *sch, struct nlattr *opt,for (i =0 ; i <=TC_BITMASK ; i++)netdev_set_prio_tc_map (dev, i, mqprio->prio_tc_map[i]); + + q->num_tc = mqprio->num_tc; } err =parse_taprio_schedule (q, tb, new_admin, extack);
Paolo Abeni
maintainerQuoted 31 lines · Gerhard Engleder
Quoted 30 lines · Lai Peter Jun Ann
Adds boundary checks for the gatemask provided against the number of traffic class defined for each sched-entry.
Without this check, the user would not know that the gatemask provided is invalid and the driver has already truncated the gatemask provided to match the number of traffic class defined.
Signed-off-by Muhammad Husaini Zulkifli <[email protected]>Signed-off-by Michael Sit Wei Hong <[email protected]>Signed-off-by Lai Peter Jun Ann <[email protected]>--- net/sched/sch_taprio.c | 8 ++++++++ 1 file changed, 8 insertions(+)net/sched/sch_taprio.c +1
-0@@ -102,6 +102,7 @@ struct taprio_sched {u32 max_sdu[TC_MAX_QUEUE ];/* save info from the user */ u32 fp[TC_QOPT_MAX_QUEUE ];/* only for dump and offloading */ u32 txtime_delay; +u8 num_tc; };struct __tc_taprio_qopt_offload {@@ -1063,6 +1064,11 @@ static int fill_sched_entry(struct taprio_sched *q, struct nlattr **tb,return -EINVAL ; }
Quoted 5 lines
net/sched/sch_taprio.c static int fill_sched_entry(struct taprio_sched *q, struct nlattr **tb, · line 1067
Quoted 1 line
net/sched/sch_taprio.c +1
-0+if (entry->gate_mask >= q->num_tc) {As far as I know within
gate_maskevery bit represents a traffic class. So for 3 traffic classes atgate_maskof0x7is valid but this check fails with0x7>= 3.
Additionally whatever check we put in place previously just ignored by the existing code, could break the existing user-space: we can't accept such change.
Cheers,
Paolo
Quoted 16 lines · Paolo Abeni
Quoted 15 lines · Gerhard Engleder
Quoted 14 lines · Lai Peter Jun Ann
Adds boundary checks for the gatemask provided against the number of traffic class defined for each sched-entry.
Without this check, the user would not know that the gatemask provided is invalid and the driver has already truncated the gatemask provided to match the number of traffic class defined.
Signed-off-by Muhammad Husaini Zulkifli <[email protected]>Signed-off-by Michael Sit Wei Hong <[email protected]>Signed-off-by Lai Peter Jun Ann <[email protected]>--- net/sched/sch_taprio.c | 8 ++++++++ 1 file changed, 8 insertions(+)
Quoted 9 lines
Quoted 9 lines
net/sched/sch_taprio.c struct taprio_sched { · line 105
Quoted 9 lines
net/sched/sch_taprio.c +1
-0@@ -102,6 +102,7 @@ struct taprio_sched {u32 max_sdu[TC_MAX_QUEUE ];/* save info from the user */ u32 fp[TC_QOPT_MAX_QUEUE ];/* only for dump and offloading */ u32 txtime_delay; +u8 num_tc;
To the patch: I would oppose introducing an "u8 num_tc" to struct taprio_sched for one purpose only. It is a duplication of netdev->num_tc, the only problem is that it hasn't yet been set, which can be solved with a bit of code reorganization.
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
net/sched/sch_taprio.c +0
-0};struct __tc_taprio_qopt_offload {@@ -1063,6 +1064,11 @@ static int fill_sched_entry(struct taprio_sched *q, struct nlattr **tb,return -EINVAL ; }Quoted 5 lines
net/sched/sch_taprio.c static int fill_sched_entry(struct taprio_sched *q, struct nlattr **tb, · line 1067
Quoted 1 line
net/sched/sch_taprio.c +1
-0+if (entry->gate_mask >= q->num_tc) {As far as I know within
gate_maskevery bit represents a traffic class. So for 3 traffic classes atgate_maskof0x7is valid but this check fails with0x7>= 3.
Quoted 3 lines
Additionally whatever check we put in place previously just ignored by the existing code, could break the existing user-space: we can't accept such change.
I agree, and I would oppose erroring out.
I used to have this patch which simply masks off the excess bits, calling netdev_warn() - which can be transformed into a warning netlink extack - instead.
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
I didn't have a strong motivation for the patch, and I dropped it. If Lai Peter Jun Ann can come with the motivation, we can go with that approach.