public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Nikola Z. Ivanov" <zlatistiv@gmail.com>
To: kuba@kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@google.com, pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Nikola Z. Ivanov" <zlatistiv@gmail.com>
Subject: [PATCH net] netdevsim: Initialize all fields of ip header when building dummy sk_buff
Date: Tue, 21 Apr 2026 10:37:38 +0300	[thread overview]
Message-ID: <20260421073738.22110-1-zlatistiv@gmail.com> (raw)

Syzbot reports a KMSAN uninit-value originating from
nsim_dev_trap_skb_build, with the allocation also
being performed in the same function.

The cause of the KMSAN warning is a missing assignment of
the tos and id fields of the ip header.

Fix this by calling skb_put_zero instead of skb_put to
guarantee null initialization.
Additionally remove the now redundant zero assignments
and reorder the remaining ones so that they more closely
match the order of the fields as they appear in the ip header.

Closes: https://syzkaller.appspot.com/bug?extid=23d7fcd204e3837866ff
Fixes: da58f90f11f5 ("netdevsim: Add devlink-trap support")
Signed-off-by: Nikola Z. Ivanov <zlatistiv@gmail.com>
---
There is a very similar function in psample.c called nsim_dev_psample_skb_build
which is almost identical to nsim_dev_trap_skb_build except for the
allocation flag reflecting its non-interrupt context and the fact
it does proper initialization of all fields.
Since these 2 are almost identical would it make sense to combine them
into 1, possbly by passing the allocation flags as parameters?

Thank you in advance for reviewing and answering!

 drivers/net/netdevsim/dev.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index 1e06e781c835..64b7cc3a6575 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -829,16 +829,14 @@ static struct sk_buff *nsim_dev_trap_skb_build(void)
 	skb->protocol = htons(ETH_P_IP);
 
 	skb_set_network_header(skb, skb->len);
-	iph = skb_put(skb, sizeof(struct iphdr));
-	iph->protocol = IPPROTO_UDP;
-	iph->saddr = in_aton("192.0.2.1");
-	iph->daddr = in_aton("198.51.100.1");
-	iph->version = 0x4;
-	iph->frag_off = 0;
+	iph = skb_put_zero(skb, sizeof(struct iphdr));
 	iph->ihl = 0x5;
+	iph->version = 0x4;
 	iph->tot_len = htons(tot_len);
 	iph->ttl = 100;
-	iph->check = 0;
+	iph->protocol = IPPROTO_UDP;
+	iph->saddr = in_aton("192.0.2.1");
+	iph->daddr = in_aton("198.51.100.1");
 	iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
 
 	skb_set_transport_header(skb, skb->len);
-- 
2.53.0


             reply	other threads:[~2026-04-21  7:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-21  7:37 Nikola Z. Ivanov [this message]
2026-04-21  8:19 ` [PATCH net] netdevsim: Initialize all fields of ip header when building dummy sk_buff Breno Leitao
2026-04-21  8:54   ` Nikola Z. Ivanov
2026-04-21  9:12     ` Breno Leitao
2026-04-21 11:44       ` Nikola Z. Ivanov
2026-04-21 15:20 ` Jakub Kicinski

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=20260421073738.22110-1-zlatistiv@gmail.com \
    --to=zlatistiv@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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