Skip to contentSkip to conversation

net/sched: em_canid: add length check before reading CAN ID

PATCH In review [email protected] 2 participants 3 messages Nov 26, 2025

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

PATCH 1/1 net/sched: em_canid: add length check before reading CAN ID

From: Shaurya Rane <[email protected]>

Add a check to verify that the skb has at least sizeof(canid_t) bytes before reading the CAN ID from skb->data. This prevents reading uninitialized memory when processing malformed packets that don't contain a valid CAN frame.

Reported-by [email protected]
Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")
---
 net/sched/em_canid.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/em_canid.c +3 -0
index 5337bc462755..a9b6cab70ff1 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 (skb->len < sizeof(canid_t))
+		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 21 lines · On Tue, Nov 25, 2025 at 7:46 PM <[email protected]> wrote:

From: Shaurya Rane <[email protected]>

Add a check to verify that the skb has at least sizeof(canid_t) bytes before reading the CAN ID from skb->data. This prevents reading uninitialized memory when processing malformed packets that don't contain a valid CAN frame.

Reported-by [email protected]
Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")
---
 net/sched/em_canid.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/em_canid.c +0 -0
index 5337bc462755..a9b6cab70ff1 100644

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

Quoted 6 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 (skb->len < sizeof(canid_t))
+               return 0;
+

Please keep in mind that this test is not enough, even if it may prevent a particular syzbot repro from triggering a bug.

Take a look at pskb_may_pull() for details.

#2 lore raw

You're right, checking skb->len alone doesn’t guarantee that the required bytes are present in the linear data area, especially for fragmented skbs. I’ll switch this to a proper pskb_may_pull(skb, sizeof(canid_t)) check to ensure the CAN ID is safely accessible. I’ll send a v2 patch with the corrected validation. Thanks,
Shaurya

Quoted 34 lines · Eric Dumazet
Quoted 21 lines · On Tue, Nov 25, 2025 at 7:46 PM <[email protected]> wrote:

From: Shaurya Rane <[email protected]>

Add a check to verify that the skb has at least sizeof(canid_t) bytes before reading the CAN ID from skb->data. This prevents reading uninitialized memory when processing malformed packets that don't contain a valid CAN frame.

Reported-by [email protected]
Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")
---
 net/sched/em_canid.c | 3 +++
 1 file changed, 3 insertions(+)
net/sched/em_canid.c +0 -0
index 5337bc462755..a9b6cab70ff1 100644

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

Quoted 6 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 (skb->len < sizeof(canid_t))
+               return 0;
+

Please keep in mind that this test is not enough, even if it may prevent a particular syzbot repro from triggering a bug.

Take a look at pskb_may_pull() for details.