Skip to content

Commit a13b67c

Browse files
tammelakuba-moo
authored andcommitted
net/sched: sch_hfsc: upgrade 'rt' to 'sc' when it becomes a inner curve
Christian Theune says: I upgraded from 6.1.38 to 6.1.55 this morning and it broke my traffic shaping script, leaving me with a non-functional uplink on a remote router. A 'rt' curve cannot be used as a inner curve (parent class), but we were allowing such configurations since the qdisc was introduced. Such configurations would trigger a UAF as Budimir explains: The parent will have vttree_insert() called on it in init_vf(), but will not have vttree_remove() called on it in update_vf() because it does not have the HFSC_FSC flag set. The qdisc always assumes that inner classes have the HFSC_FSC flag set. This is by design as it doesn't make sense 'qdisc wise' for an 'rt' curve to be an inner curve. Budimir's original patch disallows users to add classes with a 'rt' parent, but this is too strict as it breaks users that have been using 'rt' as a inner class. Another approach, taken by this patch, is to upgrade the inner 'rt' into a 'sc', warning the user in the process. It avoids the UAF reported by Budimir while also being more permissive to bad scripts/users/code using 'rt' as a inner class. Users checking the `tc class ls [...]` or `tc class get [...]` dumps would observe the curve change and are potentially breaking with this change. v1->v2: https://lore.kernel.org/all/[email protected]/ - Correct 'Fixes' tag and merge with revert (Jakub) Cc: Christian Theune <[email protected]> Cc: Budimir Markovic <[email protected]> Fixes: b3d26c5 ("net/sched: sch_hfsc: Ensure inner classes have fsc curve") Signed-off-by: Pedro Tammela <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1f9f214 commit a13b67c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

net/sched/sch_hfsc.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,14 @@ hfsc_change_usc(struct hfsc_class *cl, struct tc_service_curve *usc,
902902
cl->cl_flags |= HFSC_USC;
903903
}
904904

905+
static void
906+
hfsc_upgrade_rt(struct hfsc_class *cl)
907+
{
908+
cl->cl_fsc = cl->cl_rsc;
909+
rtsc_init(&cl->cl_virtual, &cl->cl_fsc, cl->cl_vt, cl->cl_total);
910+
cl->cl_flags |= HFSC_FSC;
911+
}
912+
905913
static const struct nla_policy hfsc_policy[TCA_HFSC_MAX + 1] = {
906914
[TCA_HFSC_RSC] = { .len = sizeof(struct tc_service_curve) },
907915
[TCA_HFSC_FSC] = { .len = sizeof(struct tc_service_curve) },
@@ -1011,10 +1019,6 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
10111019
if (parent == NULL)
10121020
return -ENOENT;
10131021
}
1014-
if (!(parent->cl_flags & HFSC_FSC) && parent != &q->root) {
1015-
NL_SET_ERR_MSG(extack, "Invalid parent - parent class must have FSC");
1016-
return -EINVAL;
1017-
}
10181022

10191023
if (classid == 0 || TC_H_MAJ(classid ^ sch->handle) != 0)
10201024
return -EINVAL;
@@ -1065,6 +1069,12 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
10651069
cl->cf_tree = RB_ROOT;
10661070

10671071
sch_tree_lock(sch);
1072+
/* Check if the inner class is a misconfigured 'rt' */
1073+
if (!(parent->cl_flags & HFSC_FSC) && parent != &q->root) {
1074+
NL_SET_ERR_MSG(extack,
1075+
"Forced curve change on parent 'rt' to 'sc'");
1076+
hfsc_upgrade_rt(parent);
1077+
}
10681078
qdisc_class_hash_insert(&q->clhash, &cl->cl_common);
10691079
list_add_tail(&cl->siblings, &parent->children);
10701080
if (parent->level == 0)

0 commit comments

Comments
 (0)