Skip to content

Commit 6f22c11

Browse files
dvdgomezPlaidCat
authored andcommitted
net/sched: sch_qfq: refactor parsing of netlink parameters
jira LE-588 cve-prereq CVE-2023-3611 commit 2536989 Two parameters can be transformed into netlink policies and validated while parsing the netlink message. Reviewed-by: Simon Horman <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: Pedro Tammela <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit 2536989) Signed-off-by: David Gomez <[email protected]>
1 parent 83f4c1b commit 6f22c11

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

net/sched/sch_qfq.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116

117117
#define QFQ_MTU_SHIFT 16 /* to support TSO/GSO */
118118
#define QFQ_MIN_LMAX 512 /* see qfq_slot_insert */
119+
#define QFQ_MAX_LMAX (1UL << QFQ_MTU_SHIFT)
119120

120121
#define QFQ_MAX_AGG_CLASSES 8 /* max num classes per aggregate allowed */
121122

@@ -217,9 +218,14 @@ static struct qfq_class *qfq_find_class(struct Qdisc *sch, u32 classid)
217218
return container_of(clc, struct qfq_class, common);
218219
}
219220

221+
static struct netlink_range_validation lmax_range = {
222+
.min = QFQ_MIN_LMAX,
223+
.max = QFQ_MAX_LMAX,
224+
};
225+
220226
static const struct nla_policy qfq_policy[TCA_QFQ_MAX + 1] = {
221-
[TCA_QFQ_WEIGHT] = { .type = NLA_U32 },
222-
[TCA_QFQ_LMAX] = { .type = NLA_U32 },
227+
[TCA_QFQ_WEIGHT] = NLA_POLICY_RANGE(NLA_U32, 1, QFQ_MAX_WEIGHT),
228+
[TCA_QFQ_LMAX] = NLA_POLICY_FULL_RANGE(NLA_U32, &lmax_range),
223229
};
224230

225231
/*
@@ -411,29 +417,20 @@ static int qfq_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
411417
}
412418

413419
err = nla_parse_nested_deprecated(tb, TCA_QFQ_MAX, tca[TCA_OPTIONS],
414-
qfq_policy, NULL);
420+
qfq_policy, extack);
415421
if (err < 0)
416422
return err;
417423

418-
if (tb[TCA_QFQ_WEIGHT]) {
424+
if (tb[TCA_QFQ_WEIGHT])
419425
weight = nla_get_u32(tb[TCA_QFQ_WEIGHT]);
420-
if (!weight || weight > (1UL << QFQ_MAX_WSHIFT)) {
421-
pr_notice("qfq: invalid weight %u\n", weight);
422-
return -EINVAL;
423-
}
424-
} else
426+
else
425427
weight = 1;
426428

427429
if (tb[TCA_QFQ_LMAX])
428430
lmax = nla_get_u32(tb[TCA_QFQ_LMAX]);
429431
else
430432
lmax = psched_mtu(qdisc_dev(sch));
431433

432-
if (lmax < QFQ_MIN_LMAX || lmax > (1UL << QFQ_MTU_SHIFT)) {
433-
pr_notice("qfq: invalid max length %u\n", lmax);
434-
return -EINVAL;
435-
}
436-
437434
inv_w = ONE_FP / weight;
438435
weight = ONE_FP / inv_w;
439436

0 commit comments

Comments
 (0)