mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: ssrane_b23@ee.vjti.ac.in, Marc Kleine-Budde <mkl@pengutronix.de>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Rostislav Lisovy <lisovy@gmail.com>,
	linux-can@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
	linux-kernel-mentees@lists.linux.dev,
	david.hunter.linux@gmail.com, khalid@kernel.org,
	syzbot+5d8269a1e099279152bc@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] net/sched: em_canid: fix uninit-value in em_canid_match
Date: Wed, 26 Nov 2025 09:02:54 +0100	[thread overview]
Message-ID: <9c9e9356-55c2-4ec0-9a0e-742a374e0d04@hartkopp.net> (raw)
In-Reply-To: <20251126070641.39532-1-ssranevjti@gmail.com>

Hello Shaurya,

many thanks that you picked up this KMSAN issue!

On 26.11.25 08:06, ssrane_b23@ee.vjti.ac.in wrote:
> From: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
> 
> 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.
> 
> Reported-by: syzbot+5d8269a1e099279152bc@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=5d8269a1e099279152bc
> Fixes: f057bbb6f9ed ("net: em_canid: Ematch rule to match CAN frames according to their identifiers")
> Signed-off-by: Shaurya Rane <ssrane_b23@ee.vjti.ac.in>
> ---
> 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(+)
> 
> diff --git a/net/sched/em_canid.c b/net/sched/em_canid.c
> index 5337bc462755..2214b548fab8 100644
> --- a/net/sched/em_canid.c
> +++ b/net/sched/em_canid.c
> @@ -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.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/can.h#n221

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


> +		return 0;
> +
>   	can_id = em_canid_get_id(skb);
>   
>   	if (can_id & CAN_EFF_FLAG) {


  reply	other threads:[~2025-11-26  8:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-26  7:06 ssrane_b23
2025-11-26  8:02 ` Oliver Hartkopp [this message]
2025-11-26  8:57   ` SHAURYA RANE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9c9e9356-55c2-4ec0-9a0e-742a374e0d04@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=davem@davemloft.net \
    --cc=david.hunter.linux@gmail.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=khalid@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lisovy@gmail.com \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=skhan@linuxfoundation.org \
    --cc=ssrane_b23@ee.vjti.ac.in \
    --cc=syzbot+5d8269a1e099279152bc@syzkaller.appspotmail.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®