From: sashiko-bot@kernel.org
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux.dev, "Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH net v5 6/7] net: add ip4_parse()
Date: Fri, 23 Oct 2026 12:59:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-182807@kernel.org> (raw)
In-Reply-To: <65a4d0ba37073c48d75251039882161efe5a4025.1792668082.git.mst@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] net: use-after-free of iph in ip4_parse() after pskb_may_pull()
--
commit f0109d51e8b0adc3b479c25e0e4799b7ae07962f
Author: Michael S. Tsirkin <mst@redhat.com>
net: add ip4_parse()
This commit introduces the ip4_parse() helper in include/linux/ip.h to
pull and minimally validate an IPv4 header and its options, converting
several callers in virtio_net, bridge netfilter, ipv4 input, and
netfilter ipv4 reject.
> diff --git a/include/linux/ip.h b/include/linux/ip.h
> index d11c25f5030a0..7e047d18a61c9 100644
> --- a/include/linux/ip.h
> +++ b/include/linux/ip.h
> @@ -56,4 +56,41 @@ static inline void iph_set_totlen(struct iphdr *iph, unsigned int len)
> {
> iph->tot_len = len <= IP_MAX_MTU ? htons(len) : 0;
> }
> +
> +/**
> + * ip4_parse - pull and minimally validate an IPv4 header
> + * @skb: buffer to parse
> + * @nhoff: offset of the IPv4 header within the linear data
> + * @thoff: returns the transport header offset
> + *
> + * The whole header, options included, is guaranteed linear on
> + * return, so the transport header offset is within the linear
> + * data. Callers that need to read the transport header must
> + * pull further.
> + *
> + * Return: the validated IPv4 header, or NULL if truncated or
> + * malformed.
> + */
> +static inline struct iphdr *ip4_parse(struct sk_buff *skb,
> + unsigned int nhoff,
> + unsigned int *thoff)
> +{
> + struct iphdr *iph;
> +
> + if (!pskb_may_pull(skb, nhoff + sizeof(struct iphdr)))
> + return NULL;
> +
> + iph = (struct iphdr *)(skb->data + nhoff);
> + if (iph->version != 4 || iph->ihl < sizeof(struct iphdr) / sizeof(u32))
> + return NULL;
> +
> + /* Pull the options as well: the transport header offset
> + * returned below must be within the linear data.
> + */
> + if (!pskb_may_pull(skb, nhoff + iph->ihl * sizeof(u32)))
> + return NULL;
> +
> + *thoff = nhoff + iph->ihl * sizeof(u32);
[Severity: Critical]
Can this dereference of iph->ihl after the second pskb_may_pull() cause a
use-after-free?
In include/linux/ip.h:ip4_parse(), iph is initialized to point into
skb->data before the second pskb_may_pull() call pulls the IPv4 options.
When IPv4 options (ihl > 5) reside in non-linear skb data and either
skb_cloned(skb) is true or skb->head lacks tailroom (or when
skb_might_realloc() triggers), the call chain:
pskb_may_pull()
pskb_may_pull_reason()
__pskb_pull_tail()
pskb_expand_head()
allocates a new skb->head buffer, updates skb->data, and frees the old
buffer that iph points into. Reading iph->ihl again afterward to compute
*thoff accesses freed memory before skb->data + nhoff is recomputed for
the return value.
Would computing *thoff = nhoff + iph->ihl * sizeof(u32) before calling
pskb_may_pull(skb, *thoff) avoid dereferencing the stale iph pointer?
> + return (struct iphdr *)(skb->data + nhoff);
> +}
> #endif /* _LINUX_IP_H */
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.v5.git.mst@redhat.com?part=6
next prev parent reply other threads:[~2026-10-23 12:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 12:57 [PATCH net v5 0/7] more virtio-net csum hardening Michael S. Tsirkin
2026-10-22 12:57 ` [PATCH net v5 1/7] net: account for ingress-resolved virtio net hdr state Michael S. Tsirkin
2026-10-22 14:37 ` Willem de Bruijn
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:30 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 2/7] um: vector: trim skbs before verifying the header Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 3/7] virtio_net: parse tunnel csum_start little-endian Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-22 12:58 ` [PATCH net v5 4/7] net: resolve uncommon partial checksums at ingress Michael S. Tsirkin
2026-10-22 14:52 ` Willem de Bruijn
2026-10-22 15:49 ` Michael S. Tsirkin
2026-10-22 17:52 ` Chris Arges
2026-10-22 23:38 ` Michael S. Tsirkin
2026-10-23 1:38 ` Chris Arges
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 5/7] net: add a sysctl to opt out of virtio net hdr checksum validation Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 6/7] net: add ip4_parse() Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot [this message]
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 12:58 ` [PATCH net v5 7/7] virtio_net: cleanup protocol calculation Michael S. Tsirkin
2026-10-23 12:59 ` sashiko-bot
2026-10-25 5:31 ` netdev-bot+sashiko
2026-10-22 17:54 ` [PATCH net v5 0/7] more virtio-net csum hardening Chris Arges
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=sashiko-outbox-182807@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/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