From: Nnamdi Onyeyiri <nnamdio@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v5 1/2] bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup
Date: Mon, 20 Jul 2026 11:41:38 +0100 [thread overview]
Message-ID: <al3uUF4FaneGEvmB@localhost.localdomain> (raw)
In-Reply-To: <20260717170146.A8CCB1F000E9@smtp.kernel.org>
On Fri, Jul 17, 2026 at 05:01:46PM +0000, sashiko-bot@kernel.org wrote:
>
> [Severity: High]
> This is a pre-existing issue in tcp_bpf_recvmsg_parser(), but this patch
> copies the same logic into tcp_bpf_recvmsg(). Does this create an unkillable
> infinite loop if the user calls recv() with a length of 0?
>
> If a user waits for data to be queued and ensures an error state is set (for
> example, the peer sends a FIN setting RCV_SHUTDOWN), and then calls
> recv(fd, buf, 0, 0), sk_msg_recvmsg() immediately returns 0 since len is 0.
>
> The code enters the if (!copied) block, hits the RCV_SHUTDOWN check, and
> because !sk_psock_queue_empty(psock) is true, it executes goto
> msg_bytes_ready.
>
> Since len is 0, the cycle repeats immediately without releasing the socket
> lock or checking for signals, pegging the CPU and potentially causing a
> soft lockup. Is there a way to safely break out of this loop when len is 0?
>
I don't think this is possible, as both tcp_bpf_recvmsg() and
tcp_bpf_recvmsg_parser() have an early return (before the loop) if len is 0.
>
> [Severity: High]
> This is a pre-existing issue, but does tcp_bpf_recvmsg() propagate an
> incorrect -EFAULT to userspace when receiving a 0-length message?
>
> If a BPF verdict program redirects a 0-length packet (such as an empty TCP
> FIN) to a sockmap socket, it is queued as an sk_msg with sge->length == 0.
>
> When the user calls recv(), __sk_msg_recvmsg() in net/core/skmsg.c
> processes the element, sets copy = sge->length (which is 0), and bypasses
> copy_page_to_iter(). It then evaluates if (!copy).
>
> Since copy is 0, it triggers copied = copied ? copied : -EFAULT, returning
> -EFAULT.
>
> Because -EFAULT is not 0, tcp_bpf_recvmsg() bypasses the if (!copied) error
> handling block above and directly assigns ret = copied, returning the
> -EFAULT back to the syscall caller. Should this case return EOF (0) instead
> of -EFAULT?
>
I can reproduce this in a selftest. As this patchset is addressing
EAGAIN errors, I'll send patch for the EFAULT separately.
next prev parent reply other threads:[~2026-07-20 10:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 15:53 [PATCH v5 0/2] bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup Nnamdi Onyeyiri
2026-07-17 15:53 ` [PATCH v5 1/2] " Nnamdi Onyeyiri
2026-07-17 17:01 ` sashiko-bot
2026-07-20 10:41 ` Nnamdi Onyeyiri [this message]
2026-07-17 15:53 ` [PATCH v5 2/2] selftest/bpf: added selftest sockmap_basic/sockmap recvfrom eagain Nnamdi Onyeyiri
2026-07-17 16:36 ` bot+bpf-ci
2026-07-17 17:29 ` sashiko-bot
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=al3uUF4FaneGEvmB@localhost.localdomain \
--to=nnamdio@gmail.com \
--cc=bpf@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).