Netdev List
 help / color / mirror / Atom feed
From: Shawn Shao <shawnq1@163.com>
To: edumazet@kernel.org, kuniyu@google.com, pabeni@redhat.com,
	willemb@google.com
Cc: davem@davemloft.net, kuba@kernel.org, horms@kernel.org,
	netdev@vger.kernel.org
Subject: [PATCH] net: preserve recvmmsg count after timeout copyout failure
Date: Sat,  5 Dec 2026 05:42:45 +0000	[thread overview]
Message-ID: <20261205054245.2964596-1-shawnq1@163.com> (raw)


__sys_recvmmsg() replaces a positive message count with -EFAULT when it
cannot copy the remaining timeout back to userspace. The datagrams have
already been dequeued and copied to userspace at that point, so the error
hides completed receives from the caller.

Keep the received count when the optional timeout copyout fails.

Tested on x86_64 with QEMU TCG. A read-only timeout mapping receives two
datagrams and returns 2; writable, PROT_NONE, empty-queue, NULL-timeout,
and pselect controls pass.

Link: https://gist.github.com/shaos26/d697e44ff0f9bd801f61f2ce00a2dd51
Fixes: a2e2725541fa ("net: Introduce recvmmsg socket syscall")
Signed-off-by: Shawn Shao <shawnq1@163.com>
---
 net/socket.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index 08658a9b8065d..02b7e813c902c 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -3151,11 +3151,11 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg,
 	if (datagrams <= 0)
 		return datagrams;
 
-	if (timeout && put_timespec64(&timeout_sys, timeout))
-		datagrams = -EFAULT;
-
-	if (timeout32 && put_old_timespec32(&timeout_sys, timeout32))
-		datagrams = -EFAULT;
+	/* The datagrams are already consumed; preserve their count on copyout. */
+	if (timeout)
+		put_timespec64(&timeout_sys, timeout);
+	if (timeout32)
+		put_old_timespec32(&timeout_sys, timeout32);
 
 	return datagrams;
 }
-- 
2.34.1


             reply	other threads:[~2026-12-05  5:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  5:42 Shawn Shao [this message]
2026-12-05  5:48 ` [PATCH] net: preserve recvmmsg count after timeout copyout failure netdev-bot+sinfo

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=20261205054245.2964596-1-shawnq1@163.com \
    --to=shawnq1@163.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.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