All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v8 1/7] ipv4: fix uninitialized memory in zerocopy cmsg
Date: Mon, 23 Nov 2026 08:37:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-228907@kernel.org> (raw)
In-Reply-To: <2819758329599addb172d144f078727112ecf17c.1795421388.git.tanggeliang@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ipv4: non-existent bug claimed in
  ipv4_datagram_support_cmsg()
- [Low] ipv4: inaccurate Fixes trailer in ipv4_datagram_support_cmsg()
  commit
--

commit 700237f41e9bcbea5b22f49b39d9b8d4e38cf887
Author: Geliang Tang <geliang@kernel.org>

> ipv4: fix uninitialized memory in zerocopy cmsg
>
> When SOF_TIMESTAMPING_OPT_CMSG is enabled and applications read
> MSG_ZEROCOPY completion notifications from the error queue, the
> ipv4_datagram_support_cmsg() function attempts to read ip_hdr(skb)->saddr
> to populate IP_PKTINFO cmsg data. However, zerocopy completion notification
> skbs don't have IP headers, causing this read to access uninitialized
> memory which is then leaked to userspace via put_cmsg().
>
> This is because the function checks PKTINFO_SKB_CB(skb)->ipi_ifindex (which
> aliases the ops pointer in ubuf_info_msgzc stored in skb->cb), and if
> non-NULL, proceeds to read ip_hdr(skb)->saddr without verifying that the
> skb actually has an IP header.
>
> Fix this by adding an early check for SO_EE_ORIGIN_ZEROCOPY and returning
> false, since zerocopy completion notifications don't have IP headers and
> IP_PKTINFO cmsg is not applicable to them.
>
> Fixes: 829ae9d61165 ("net-timestamp: allow reading recv cmsg on errqueue with origin tstamp")
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>

[Severity: Low]
Is this Fixes: tag accurate?

Commit 829ae9d61165 ("net-timestamp: allow reading recv cmsg on errqueue with
origin tstamp") explicitly required ee_origin == SO_EE_ORIGIN_TIMESTAMPING and
predated SO_EE_ORIGIN_ZEROCOPY, which was added later in commit 52267790ef52
("sock: add MSG_ZEROCOPY").

> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> index 90d0b5bee68b5..8d1a9db54f839 100644
> --- a/net/ipv4/ip_sockglue.c
> +++ b/net/ipv4/ip_sockglue.c
> @@ -504,6 +504,12 @@ static bool ipv4_datagram_support_cmsg(const struct sock *sk,
>  	if (ee_origin == SO_EE_ORIGIN_LOCAL)
>  		return false;
>  
> +	/* Zerocopy completion notifications don't have IP headers,
> +	 * so IP_PKTINFO cmsg is not applicable.
> +	 */
> +	if (ee_origin == SO_EE_ORIGIN_ZEROCOPY)
> +		return false;

[Severity: Medium]
Can ipv4_datagram_support_cmsg() actually reach ip_hdr(skb)->saddr for a
SO_EE_ORIGIN_ZEROCOPY notification skb?

Before queueing a zerocopy completion notification onto sk_error_queue,
__msg_zerocopy_callback() overwrites ubuf_info_msgzc in skb->cb (and note that
struct ubuf_info has not had an ops pointer since commit ecca9bb2c855 ("net:
replace Callbacks inside ubuf_info with single function")):

net/core/skbuff.c:__msg_zerocopy_callback() {
	...
	serr = SKB_EXT_ERR(skb);
	memset(serr, 0, sizeof(*serr));
	serr->ee.ee_errno = 0;
	serr->ee.ee_origin = SO_EE_ORIGIN_ZEROCOPY;
	...
}

Because SKB_EXT_ERR(skb) and PKTINFO_SKB_CB(skb) both sit at the start of
skb->cb, memset(serr, 0, sizeof(*serr)) zeroes PKTINFO_SKB_CB(skb)->ipi_ifindex
(which aliases serr->header.h4.iif).  The existing !info->ipi_ifindex check in
ipv4_datagram_support_cmsg() therefore already returns false for every
SO_EE_ORIGIN_ZEROCOPY skb before ip_hdr(skb)->saddr is read.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795421388.git.tanggeliang@kylinos.cn?part=1

  reply	other threads:[~2026-11-23  8:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  8:19 [PATCH mptcp-next v8 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-23  8:19 ` [PATCH mptcp-next v8 1/7] ipv4: fix uninitialized memory in zerocopy cmsg Geliang Tang
2026-11-23  8:37   ` sashiko-bot [this message]
2026-11-24 23:30   ` netdev-bot+sashiko
2026-11-23  8:19 ` [PATCH mptcp-next v8 2/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-24 23:30   ` netdev-bot+sashiko
2026-11-23  8:19 ` [PATCH mptcp-next v8 3/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-24 23:30   ` netdev-bot+sashiko
2026-11-23  8:19 ` [PATCH mptcp-next v8 4/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-23  8:46   ` sashiko-bot
2026-11-24 23:30   ` netdev-bot+sashiko
2026-11-23  8:19 ` [PATCH mptcp-next v8 5/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-23  8:36   ` sashiko-bot
2026-11-24 23:30   ` netdev-bot+sashiko
2026-11-23  8:19 ` [PATCH mptcp-next v8 6/7] selftests: mptcp: connect: add zerocopy io mode Geliang Tang
2026-11-23  8:37   ` sashiko-bot
2026-11-24 23:30   ` netdev-bot+sashiko
2026-11-23  8:19 ` [PATCH mptcp-next v8 7/7] selftests: mptcp: connect: cover zerocopy mode Geliang Tang
2026-11-24 23:30   ` netdev-bot+sashiko
2026-11-23 10:42 ` [PATCH mptcp-next v8 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI

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-228907@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=sashiko-reviews@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.