Skip to contentSkip to conversation

net/sched: em_canid: fix uninit-value in em_canid_match

PATCH Applied [email protected] 3 participants 3 messages Nov 26, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 net/sched: em_canid: fix uninit-value in em_canid_match

From: Shaurya Rane <[email protected]>

Use pskb_may_pull() to ensure a complete CAN frame is present in the linear data buffer before reading the CAN ID. A simple skb->len check is insufficient because it only verifies the total data length but does not guarantee the data is present in skb->data (it could be in fragments).

pskb_may_pull() both validates the length and pulls fragmented data into the linear buffer if necessary, making it safe to directly access skb->data.

Reported-by [email protected]
Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")

---
v3: Use CAN_MTU to validate a complete CAN frame is present
v2: Use pskb_may_pull() instead of skb->len check to properly
handle fragmented skbs

---
 net/sched/em_canid.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/em_canid.c +3 -0
index 5337bc462755..2d27f91d8441 100644
@@ -99,6 +99,9 @@ static int em_canid_match(struct sk_buff *skb, struct tcf_ematch *m,
 	int i;
 	const struct can_filter *lp;
 
+	if (!pskb_may_pull(skb, CAN_MTU))
+		return 0;
+
 	can_id = em_canid_get_id(skb);
 
 	if (can_id & CAN_EFF_FLAG) {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 30 lines · On Wed, Nov 26, 2025 at 12:57 AM <[email protected]> wrote:

From: Shaurya Rane <[email protected]>

Use pskb_may_pull() to ensure a complete CAN frame is present in the linear data buffer before reading the CAN ID. A simple skb->len check is insufficient because it only verifies the total data length but does not guarantee the data is present in skb->data (it could be in fragments).

pskb_may_pull() both validates the length and pulls fragmented data into the linear buffer if necessary, making it safe to directly access skb->data.

Reported-by [email protected]
Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")

---
v3: Use CAN_MTU to validate a complete CAN frame is present
v2: Use pskb_may_pull() instead of skb->len check to properly
handle fragmented skbs

---
 net/sched/em_canid.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/em_canid.c +0 -0
index 5337bc462755..2d27f91d8441 100644

net/sched/em_canid.c static int em_canid_match(struct sk_buff *skb, struct tcf_ematch *m, · line 107

Quoted 9 lines
net/sched/em_canid.c +3 -0
@@ -99,6 +99,9 @@ static int em_canid_match(struct sk_buff *skb, struct tcf_ematch *m,
        int i;
        const struct can_filter *lp;
 
+       if (!pskb_may_pull(skb, CAN_MTU))
+               return 0;
+
        can_id = em_canid_get_id(skb);
 
        if (can_id & CAN_EFF_FLAG) {

For your next netdev patches, please read
Documentation/process/maintainer-netdev.rst

Resending after review
~~~~~~~~~~~~~~~~~~~~~~

Allow at least 24 hours to pass between postings. This will ensure reviewers from all geographical locations have a chance to chime in. Do not wait too long (weeks) between postings either as it will make it harder for reviewers to recall all the context.

Thank you.

maintainer Applied
#2 lore raw
In reply to [email protected]
Quoted 8 lines · On 26.11.2025 14:27:18, [email protected] wrote:

From: Shaurya Rane <[email protected]>

Use pskb_may_pull() to ensure a complete CAN frame is present in the linear data buffer before reading the CAN ID. A simple skb->len check is insufficient because it only verifies the total data length but does not guarantee the data is present in skb->data (it could be in fragments).

Quoted 8 lines

pskb_may_pull() both validates the length and pulls fragmented data into the linear buffer if necessary, making it safe to directly access skb->data.

Reported-by [email protected]
Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")

Applied to linux-can

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |