From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512253; b=lrF05EZ6Ys3iP7yCYBNm3O43bRnkk4uJr9OEKKDgn4UW2VDyRupPDzoAegvGNjyqV0L7 iZmibFV6qUUfD++HZjY8qAUUlVYL1bzc2z1b3mLFFzZ0eqYQIPjt88UGFX5GU+Mxtmkwx jZ4qtYiyY7v5B/WWUVOnUjewDCKoEhvqYEefYSu7YglDxVhT42pNi6RG4OQ8BvX3+iFyO Okd1zMYFDEul4qEZ+8+Yvk15X9JpnzR19fQ7AM1UScBEsBsFXm+hsf7M8h4td1vhwINMe TkBV8ERyTuF8S0HC6sbn7bYgFugGdOIpIWeLe4eiTdSp0a1BKD99kZuhc5ig5KlkPuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512253; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=5JORpzL/XndRXjzy6iGQkrA6QJfbFIt/i5d0QCxnltw=; b=v0TW2UFcEgU+jZLYxs3SK4F34gy0mgwFIKP0QIlxEYK1xmT3SlJjcmEhm9FcxCTLO7vr MHPc/g0lwj8kGlpzEaEHM/Sz4LsvRd5CJBxZLGQ/cJbypOdktdiK/r7Z8FTPy9cdzfogi m2gaBWni2mL8nmD3BgZM+PkKCaEeomhVY+Mqjxozpe+u6SiK1IxFtHhv+om1ECvJqw8qN yN9gMiH8Mzfp9vpn/n7d0uSOPN+/Z8IL37Soq4ripKyBmPc85+hTtjy4ameiaBUYXGWMh ToaUFDsVdFBIJRAh+knDvu+zr4RfyHxramB3bjQM5ADbw7k58N4j99BdVkRlfdtxTcw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=X0evGgKG; arc=none smtp.remote-ip=209.85.210.50 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 647A2606A322 for ; Sat, 5 Dec 2026 23:10:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 647A2606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.dk header.i=@kernel.dk header.a=rsa-sha256 header.s=google header.b=X0evGgKG Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-86298f9267fso1285157a34.0 for ; Sat, 05 Dec 2026 15:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512252; x=1797117052; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5JORpzL/XndRXjzy6iGQkrA6QJfbFIt/i5d0QCxnltw=; b=X0evGgKG9K4g3OH7aPFrDfFhjNDyAIb6k64uTcEIbew9IXDdA6FP8q9U4Ex4WKoWpl CVbNq8nu0j2yui6tRk/4yjlHjfw3CGSq9k3Pq/9CNMC1oTN/D5wz5gOul/bvlp10Rhjh e6eDliBU7LQwXmjtxdTEiz3GZPyUbFWhrqMy0EEHwh3Ubjz4h/DxsOovCeWS85UDwPfm dppG0/jkBUBI3iosUn6OeYAp9EcvVpiZHiWVPWVTGzuaCrCgLx3QFdAMN1PG2o1xXJbd jnhi0qXt59cvdLIHacGPL/RDk+9EZrGWuXpAx8pVEMNTRduLADJce7uqtNp+8bd7C7FF fRjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512252; x=1797117052; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5JORpzL/XndRXjzy6iGQkrA6QJfbFIt/i5d0QCxnltw=; b=pc5fOQlBecZ+VpWJaxWJOlla8dazeLjBwT5G6atzLUtLlnSST89tcE9/OWpg6ZB3KR 16x1YSUGTQg6SNh+q5Rp5Ldt0VzpGGL+bkkM6iHIsuvyFtqaLcSdCNZm1K/90gMxmqhZ g6JH7jagjfWHONbhwVt6rFx7Y7D9oJxEnQesgQ8hII+ZVlfu7Rlm7BBrhKg8qaFSo8Mx Z7LdxhDX/bDXA9RBRQjLv8co8CCmdLcvLfFYpOHjw37jLupmThoE/UyhpIt4h5i4Cnps SustigiC2aq7Z3V/3XiBG5bwRTDYiVkpLJB+PjCAbKR1+KmIfJMW2xHKLg9OzoVkbBx1 slbw== X-Gm-Message-State: APuU4Z9JY38fRbqvnMQiay3xbWNusBvMzorPOxCVpz+1Y5mu2T0u+CqF x0ka1+gDNS5bPkXQlLfB8CCBr4SQxuxaCpG8JU27vJl9H60yC1cRwUDetaqroR8v3gM= X-Gm-Gg: AZFdTZe2ZIBVRv9JKfSioR0eXlEc3htoDTUfyn5ZOuL5mAyuA6x82y6EVJG+mw+Sjvo Xhbus6OAAAXw2sbhRyVsmaLumHjqC7yTbwyfLJ5o8CpU6AEBum2h6ChYNO/cClCxo5r+keAXKbL w2fk9f/o8aBFeEPoz+Q9D7wWcq+8x6qDguoKaJOkEDuLt5hmPX8MSPeTCKH8hCDi1WcIQ8oHekw U+5yl6vVLUFCDRicvhd26YWowIv/RH2v2rvOpZ+H7rZ4YbMqlLpktKfCvloC9zBpo16fRxiGz03 fqhrNgcIGR3R6iZc6vBXuuffFg7LKtV/HYopI43TeTBXfUywIub+X/5vSDqwo3gZVoOnpatD43n YIqk5gOkJfLOT1NiTCSem5E0MJr3SFenvmCH7dbPqBhbirUpfJft+FDgDBrlvvJjJKTyBg+r8sa YVIqvGgFves0/KgynBfzunpGG5g9rfMU1u5WqRZHebZQIaEGhJT46ydU5ZYMXfvW6WMbodJ9qUq xxM2xh7xHE3Wk9xR3ZHgGHrpadjmRPjhNqdyzjKwcaqL46+aVbGX+iOY3fW1s6tnj0BYh7BPKOy 9twgz+Elg6w8KGlloy8W79cgesU3rnBmk6WIXfzpvuMoHXE7VjnSrxaSRNcKOgT6C3IOc6Nn4bo UlFyqhvmfv8Gv8fbWenN5xHbdZkBCGrPs5q7b X-Received: by 2002:a05:6830:2b08:b0:862:bda5:b876 with SMTP id 46e09a7af769-863f89eb9a8mr7266867a34.12.1796512252371; Sat, 05 Dec 2026 15:10:52 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f8313082sm6309624a34.16.2026.12.05.15.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:10:51 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.1.y 9/9] io_uring/net: restore the cmsg buffer on recvmsg retry Date: Sat, 5 Dec 2026 23:10:12 +0000 Message-ID: <20261205231012.3977993-10-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231012.3977993-1-axboe@kernel.dk> References: <20261205231012.3977993-1-axboe@kernel.dk> X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Mason Commit 437e79d6a2a7aba81d56c11198576a72574e6d52 upstream. A single-shot IORING_OP_RECVMSG that is retried after -EAGAIN can report the control messages of the failed attempt, and hide those that came with the data. On an AF_UNIX stream socket with SO_PASSCRED, the caller gets SCM_CREDENTIALS with pid, uid and gid 0, and never sees the descriptors that an SCM_RIGHTS message installed. io_recvmsg() passes the msghdr that was set up at prep to each attempt, so a failed ->recvmsg() has to leave msg_control and msg_controllen as they were. recvmsg(2) doesn't depend on that, since it copies the user's msghdr for each call. unix_stream_read_generic() calls scm_recv_unix() whatever its result is, with a zeroed scm_cookie if the queue was empty, and put_cmsg() advances the control buffer. ____sys_recvmsg() then counts the reported length from where its call started, but the caller reads from the head of its buffer: msg_control = C, msg_controllen = 64 first attempt, the queue is empty put_cmsg(SCM_CREDENTIALS {0, 0, 0}) at C msg_control = C + 32, msg_controllen = 32 return -EAGAIN second attempt cmsg_ptr = C + 32 put_cmsg(SCM_CREDENTIALS of the sender) at C + 32 msg_control = C + 64, msg_controllen = 0 put_user(msg_control - cmsg_ptr = 32, &umsg->msg_controllen) The fix used here is to save the control buffer before each attempt, and to restore it if the attempt fails with -EAGAIN and will be retried. The tradeoff: with MSG_WAITALL, a retry whose control buffer the failed attempts had used up went on after a short receive until the data buffer was full. It now completes short, as every recvmsg with a control buffer does since commit 78d0d2063bab ("io_uring/net: disable partial retries for recvmsg with cmsg"). Fixes: e54937963fa2 ("net: remove cmsg restriction from io_uring based send/recvmsg calls") Signed-off-by: Chris Mason Signed-off-by: Jens Axboe [axboe: 6.1 retries through io_setup_async_msg(), which copies the msghdr on the first -EAGAIN. Restore the control buffer before that call] --- io_uring/net.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 78ae996840c2..4e06ecbf00ac 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -779,6 +779,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) int ret, min_ret = 0; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; bool mshot_finished = true; + void __user *control; + size_t controllen; sock = sock_from_file(req->file); if (unlikely(!sock)) @@ -826,6 +828,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) flags |= MSG_DONTWAIT; kmsg->msg.msg_get_inq = 1; + control = kmsg->msg.msg_control_user; + controllen = kmsg->msg.msg_controllen; if (req->flags & REQ_F_APOLL_MULTISHOT) { ret = io_recvmsg_multishot(sock, sr, kmsg, flags, &mshot_finished); @@ -840,6 +844,12 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) if (ret < min_ret) { if (ret == -EAGAIN && force_nonblock) { + /* + * Don't depend on the control buffer being untouched, a + * protocol may post a cmsg before it finds no data. + */ + kmsg->msg.msg_control_user = control; + kmsg->msg.msg_controllen = controllen; ret = io_setup_async_msg(req, kmsg, issue_flags); if (ret == -EAGAIN && (issue_flags & IO_URING_F_MULTISHOT)) { io_kbuf_recycle(req, issue_flags); -- 2.55.0