Skip to contentSkip to conversation

net/sched: mqprio: fix stack out-of-bounds write in tc entry parsing

PATCH Superseded Maher Azzouzi 4 participants 5 messages Jul 22, 2025 – Jul 25, 2025 1 message not in the archive

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/sched: mqprio: fix stack out-of-bounds write in tc entry parsing

From: MaherAzzouzi <[email protected]>

TCA_MQPRIO_TC_ENTRY_INDEX is validated using NLA_POLICY_MAX(NLA_U32, TC_QOPT_MAX_QUEUE), which allows the value TC_QOPT_MAX_QUEUE (16). This leads to a 4-byte out-of-bounds stack write in the fp[] array, which only has room for 16 elements (0–15).

Fix this by changing the policy to allow only up to TC_QOPT_MAX_QUEUE - 1.

Fixes f62af20bed2d ("net/sched: mqprio: allow per-TC user input of FP adminStatus")
---
 net/sched/sch_mqprio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_mqprio.c +1 -1
index 51d4013b6121..f3e5ef9a9592 100644
@@ -152,7 +152,7 @@ static int mqprio_parse_opt(struct net_device *dev, struct tc_mqprio_qopt *qopt,
 static const struct
 nla_policy mqprio_tc_entry_policy[TCA_MQPRIO_TC_ENTRY_MAX + 1] = {
 	[TCA_MQPRIO_TC_ENTRY_INDEX]	= NLA_POLICY_MAX(NLA_U32,
-							 TC_QOPT_MAX_QUEUE),
+							 TC_QOPT_MAX_QUEUE - 1),
 	[TCA_MQPRIO_TC_ENTRY_FP]	= NLA_POLICY_RANGE(NLA_U32,
 							   TC_FP_EXPRESS,
 							   TC_FP_PREEMPTIBLE),
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw

+ Ferenc and Vladimir

Quoted 1 line · Maher Azzouzi

From: MaherAzzouzi <[email protected]>

nit: space between your names please

Quoted 10 lines

TCA_MQPRIO_TC_ENTRY_INDEX is validated using NLA_POLICY_MAX(NLA_U32, TC_QOPT_MAX_QUEUE), which allows the value TC_QOPT_MAX_QUEUE (16). This leads to a 4-byte out-of-bounds stack write in the fp[] array, which only has room for 16 elements (0–15).

Fix this by changing the policy to allow only up to TC_QOPT_MAX_QUEUE - 1.

Fixes f62af20bed2d ("net/sched: mqprio: allow per-TC user input of FP adminStatus")

I don't think there is any need to include a Reported-by tag if you are also the patch author.

Quoted 1 line

I agree with your analysis and that this is a good fix.

I do think it is misleading to name this #define MAX, but it's part of the UAPI so that ship has sailed.

It seems that taprio has a similar problem, but that it is not a bug due to an additional check. I wonder if something like this for net-next is appropriate to align it's implementation wit that of maprio.

net/sched/sch_taprio.c +4 -8
index 2b14c81a87e5..e759e43ad27e 100644
@@ -998,7 +998,7 @@ static const struct nla_policy entry_policy[TCA_TAPRIO_SCHED_ENTRY_MAX + 1] = {
 
 static const struct nla_policy taprio_tc_policy[TCA_TAPRIO_TC_ENTRY_MAX + 1] = {
 	[TCA_TAPRIO_TC_ENTRY_INDEX]	   = NLA_POLICY_MAX(NLA_U32,
-							    TC_QOPT_MAX_QUEUE),
+							    TC_QOPT_MAX_QUEUE - 1),
 	[TCA_TAPRIO_TC_ENTRY_MAX_SDU]	   = { .type = NLA_U32 },
 	[TCA_TAPRIO_TC_ENTRY_FP]	   = NLA_POLICY_RANGE(NLA_U32,
 							      TC_FP_EXPRESS,
@@ -1698,19 +1698,15 @@ static int taprio_parse_tc_entry(struct Qdisc *sch,
 	if (err < 0)
 		return err;
 
-	if (!tb[TCA_TAPRIO_TC_ENTRY_INDEX]) {
+	if (NL_REQ_ATTR_CHECK(extack, opt, tb, TCA_TAPRIO_TC_ENTRY_INDEX)) {
 		NL_SET_ERR_MSG_MOD(extack, "TC entry index missing");
 		return -EINVAL;
 	}
 
 	tc = nla_get_u32(tb[TCA_TAPRIO_TC_ENTRY_INDEX]);
-	if (tc >= TC_QOPT_MAX_QUEUE) {
-		NL_SET_ERR_MSG_MOD(extack, "TC entry index out of range");
-		return -ERANGE;
-	}
-
 	if (*seen_tcs & BIT(tc)) {
-		NL_SET_ERR_MSG_MOD(extack, "Duplicate TC entry");
+		NL_SET_ERR_MSG_ATTR(extack, tb[TCA_TAPRIO_TC_ENTRY_INDEX],
+				    "Duplicate tc entry");
 		return -EINVAL;
 	}
 
Quoted 20 lines
---
 net/sched/sch_mqprio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_mqprio.c +1 -2
index 51d4013b6121..f3e5ef9a9592 100644
@@ -152,7 +152,7 @@ static int mqprio_parse_opt(struct net_device *dev, struct tc_mqprio_qopt *qopt,
 static const struct
 nla_policy mqprio_tc_entry_policy[TCA_MQPRIO_TC_ENTRY_MAX + 1] = {
      [TCA_MQPRIO_TC_ENTRY_INDEX]     = NLA_POLICY_MAX(NLA_U32,
-                                                      TC_QOPT_MAX_QUEUE),
+                                                      TC_QOPT_MAX_QUEUE - 1),
      [TCA_MQPRIO_TC_ENTRY_FP]        = NLA_POLICY_RANGE(NLA_U32,
                                                         TC_FP_EXPRESS,
                                                         TC_FP_PREEMPTIBLE),
--

2.34.1

A message that is not in the archive (sent off-list or not yet received): CAFQ-Uc_qYu--YG4LNVOB=UQeUGyuQ9fSPT=e52HwHu-j3kjQtQ@mail.gmail.com

#3 lore raw

Hi Maher,

Quoted 7 lines · maher azz

Hello,

Thank you for taking the time to look into it. Should I remove the “reported by” tag? resend another patch or is it fine like that?

Best regards,
Maher

For an initial patch submission, the quality is reasonable. But it needs improvement before it can be merged, and I recommend submitting a v2, no earlier than 24 hours after the initial submission.

Some comments:

1. The "Author:" (in git; in the email it is the "From:" field) and last "Signed-off-by:" tag need to coincide. In your case, they point to the same person (you), but the formatting is different, so they don't coincide. Please fix your "git config --global user.name" in the way that Simon indicated.
2. Please don't top-post. Trim the quoted email to just the relevant portions you're responding to, and respond below the quoted email.
3. Please configure your email client to respond only using plain-text emails, no HTML.

#4 lore raw
In reply to Simon Horman

Hi Simon,

Quoted 30 lines · Simon Horman

It seems that taprio has a similar problem, but that it is not a bug due to an additional check. I wonder if something like this for net-next is appropriate to align it's implementation wit that of maprio.

net/sched/sch_taprio.c +2 -3
index 2b14c81a87e5..e759e43ad27e 100644
@@ -998,7 +998,7 @@ static const struct nla_policy entry_policy[TCA_TAPRIO_SCHED_ENTRY_MAX + 1] = {
 
 static const struct nla_policy taprio_tc_policy[TCA_TAPRIO_TC_ENTRY_MAX + 1] = {
 	[TCA_TAPRIO_TC_ENTRY_INDEX]	   = NLA_POLICY_MAX(NLA_U32,
-							    TC_QOPT_MAX_QUEUE),
+							    TC_QOPT_MAX_QUEUE - 1),
 	[TCA_TAPRIO_TC_ENTRY_MAX_SDU]	   = { .type = NLA_U32 },
 	[TCA_TAPRIO_TC_ENTRY_FP]	   = NLA_POLICY_RANGE(NLA_U32,
 							      TC_FP_EXPRESS,
@@ -1698,19 +1698,15 @@ static int taprio_parse_tc_entry(struct Qdisc *sch,
 	if (err < 0)
 		return err;
 
-	if (!tb[TCA_TAPRIO_TC_ENTRY_INDEX]) {
+	if (NL_REQ_ATTR_CHECK(extack, opt, tb, TCA_TAPRIO_TC_ENTRY_INDEX)) {
 		NL_SET_ERR_MSG_MOD(extack, "TC entry index missing");
 		return -EINVAL;
 	}
 
 	tc = nla_get_u32(tb[TCA_TAPRIO_TC_ENTRY_INDEX]);
-	if (tc >= TC_QOPT_MAX_QUEUE) {

net/sched/sch_taprio.c static int taprio_parse_tc_entry(struct Qdisc *sch, · line 1711

Quoted 10 lines
net/sched/sch_taprio.c +2 -5
-		NL_SET_ERR_MSG_MOD(extack, "TC entry index out of range");
-		return -ERANGE;
-	}
-
 	if (*seen_tcs & BIT(tc)) {
-		NL_SET_ERR_MSG_MOD(extack, "Duplicate TC entry");
+		NL_SET_ERR_MSG_ATTR(extack, tb[TCA_TAPRIO_TC_ENTRY_INDEX],
+				    "Duplicate tc entry");
 		return -EINVAL;
 	}

Yes, this is net-next material, and you can submit it independently of the taprio change (i.e. right away).

Reviewed-by
#5 lore raw
In reply to Simon Horman
Quoted 13 lines · Simon Horman

+ Ferenc and Vladimir

Quoted 1 line · Maher Azzouzi

From: MaherAzzouzi <[email protected]>

nit: space between your names please

Quoted 6 lines

TCA_MQPRIO_TC_ENTRY_INDEX is validated using NLA_POLICY_MAX(NLA_U32, TC_QOPT_MAX_QUEUE), which allows the value TC_QOPT_MAX_QUEUE (16). This leads to a 4-byte out-of-bounds stack write in the fp[] array, which only has room for 16 elements (0–15).

Quoted 7 lines
Quoted 4 lines

Fix this by changing the policy to allow only up to TC_QOPT_MAX_QUEUE - 1.

Fixes f62af20bed2d ("net/sched: mqprio: allow per-TC user input of FP adminStatus")

I don't think there is any need to include a Reported-by tag if you are also the patch author.

+1

Quoted 6 lines
Quoted 2 lines

I agree with your analysis and that this is a good fix.

Thanks for the patch.