net/sched: em_canid: fix uninit-value in em_canid_match
Subsystems (5)
PATCH v2 1/1 net/sched: em_canid: fix uninit-value in em_canid_match
From: Shaurya Rane <[email protected]>
Use pskb_may_pull() to ensure the CAN ID is accessible in the linear data buffer before reading it. 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.
---
v2: Use pskb_may_pull() instead of skb->len check to properly
handle fragmented skbs (Eric Dumazet)
--- net/sched/em_canid.c | 3 +++ 1 file changed, 3 insertions(+)
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,sizeof (canid_t))) +return 0 ; + can_id =em_canid_get_id (skb);if (can_id &CAN_EFF_FLAG ) {
Signature · 1 line
2.34.1
Oliver Hartkopp
maintainerHello Shaurya,
many thanks that you picked up this KMSAN issue!
Quoted 27 lines · On 26.11.25 08:06, [email protected] wrote:
From: Shaurya Rane <[email protected]>
Use
pskb_may_pull()to ensure the CAN ID is accessible in the linear data buffer before reading it. A simpleskb->lencheck is insufficient because it only verifies the total data length but does not guarantee the data is present inskb->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 accessskb->data.Reported-by [email protected]Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")Signed-off-by Shaurya Rane <[email protected]>---
v2: Usepskb_may_pull()instead ofskb->lencheck to properly
handle fragmented skbs (Eric Dumazet)--- net/sched/em_canid.c | 3 +++ 1 file changed, 3 insertions(+)net/sched/em_canid.c +0
-0
net/sched/em_canid.c static int em_canid_match(struct sk_buff *skb, struct tcf_ematch *m, · line 102
Quoted 4 lines
net/sched/em_canid.c +1
-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,sizeof (canid_t)))
The EM CANID handles struct CAN frames in skb->data.
The smallest type of CAN frame that can be properly handled with EM CANID is a Classical CAN frame which has a length of 16 bytes.
Therefore I would suggest
if (!pskb_may_pull(skb, CAN_MTU))
instead of only checking for the first element in struct can_frame.
Many thanks and best regards,
Oliver
Quoted 5 lines
net/sched/em_canid.c +2
-0+return 0 ; + can_id =em_canid_get_id (skb);if (can_id &CAN_EFF_FLAG ) {
Thanks Oliver,
That makes sense EM_CANID operates on a full struct can_frame, so ensuring CAN_MTU bytes are available is the correct approach. I’ll update the patch accordingly and send a v3.
Thanks for the clarification!
Shaurya
Quoted 61 lines · Oliver Hartkopp
Hello Shaurya,
many thanks that you picked up this KMSAN issue!
Quoted 27 lines · On 26.11.25 08:06, [email protected] wrote:
From: Shaurya Rane <[email protected]>
Use
pskb_may_pull()to ensure the CAN ID is accessible in the linear data buffer before reading it. A simpleskb->lencheck is insufficient because it only verifies the total data length but does not guarantee the data is present inskb->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 accessskb->data.Reported-by [email protected]Fixes f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")Signed-off-by Shaurya Rane <[email protected]>---
v2: Usepskb_may_pull()instead ofskb->lencheck to properly
handle fragmented skbs (Eric Dumazet)--- net/sched/em_canid.c | 3 +++ 1 file changed, 3 insertions(+)net/sched/em_canid.c +0
-0net/sched/em_canid.c static int em_canid_match(struct sk_buff *skb, struct tcf_ematch *m, · line 102
Quoted 4 lines
net/sched/em_canid.c +1
-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,sizeof (canid_t)))The EM CANID handles struct CAN frames in
skb->data.The smallest type of CAN frame that can be properly handled with EM CANID is a Classical CAN frame which has a length of 16 bytes.
Therefore I would suggest
if (!pskb_may_pull(skb, CAN_MTU))instead of only checking for the first element in struct
can_frame.Many thanks and best regards,
OliverQuoted 5 lines
net/sched/em_canid.c +2
-0+return 0 ; + can_id =em_canid_get_id (skb);if (can_id &CAN_EFF_FLAG ) {