Skip to content

Commit 6c58c88

Browse files
f0rm2l1nkuba-moo
authored andcommitted
net/sched: mqprio: Add length check for TCA_MQPRIO_{MAX/MIN}_RATE64
The nla_for_each_nested parsing in function mqprio_parse_nlattr() does not check the length of the nested attribute. This can lead to an out-of-attribute read and allow a malformed nlattr (e.g., length 0) to be viewed as 8 byte integer and passed to priv->max_rate/min_rate. This patch adds the check based on nla_len() when check the nla_type(), which ensures that the length of these two attribute must equals sizeof(u64). Fixes: 4e8b86c ("mqprio: Introduce new hardware offload mode and shaper in mqprio") Reviewed-by: Victor Nogueira <[email protected]> Signed-off-by: Lin Ma <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0f0fa27 commit 6c58c88

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

net/sched/sch_mqprio.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt,
290290
"Attribute type expected to be TCA_MQPRIO_MIN_RATE64");
291291
return -EINVAL;
292292
}
293+
294+
if (nla_len(attr) != sizeof(u64)) {
295+
NL_SET_ERR_MSG_ATTR(extack, attr,
296+
"Attribute TCA_MQPRIO_MIN_RATE64 expected to have 8 bytes length");
297+
return -EINVAL;
298+
}
299+
293300
if (i >= qopt->num_tc)
294301
break;
295302
priv->min_rate[i] = nla_get_u64(attr);
@@ -312,6 +319,13 @@ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt,
312319
"Attribute type expected to be TCA_MQPRIO_MAX_RATE64");
313320
return -EINVAL;
314321
}
322+
323+
if (nla_len(attr) != sizeof(u64)) {
324+
NL_SET_ERR_MSG_ATTR(extack, attr,
325+
"Attribute TCA_MQPRIO_MAX_RATE64 expected to have 8 bytes length");
326+
return -EINVAL;
327+
}
328+
315329
if (i >= qopt->num_tc)
316330
break;
317331
priv->max_rate[i] = nla_get_u64(attr);

0 commit comments

Comments
 (0)