From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512374; b=ftcy6qXaJ3IPh1rRIK9dca09p+QSqbdRjB2xTsdNzimZTPBDa9N7bYLqdClAoTyaHmIU Zc3Wf8AdjvrSTlTid7G3ajYIaYnUjNzHW21gzhBw/tkEx6z+O6m4nwKAYS2hq6wXQayAt 1PN/wvfQkVHFVsiGoqUoZDWcCZIv9I+tRdO7eDmmlCUYfiuG/aG8dTHKcmcAnjsPjigoR MmGbfuygWBzZwmb9A3sIQ+2XyKa1jqUO4XsvhmKeaxLGLUolk8e2f7XsmR4A4jiRWpgln sJenXq7dvTYGDNtEG0mtPWntvOJ1QyuT2NbN6OXAJh7BPE1HKtOrbKdvQGPry4v7WtA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512374; 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=c6CmEcbYA7P99vZk0nIxpynlJ7t4ZZiQRWGx1kY/mxY=; b=m++eXJOtcQWnPJS6py0YBDjC971zY4sA4fpQz1W1PIp4a7ereWjg/TFewdIQdKBWON6Y Uw//pL6Jh1g7nwMIJztpLzNlpvnmCnHDYZQvuItCEAo8zSnla91ooWRuB20DpzZtv3fcr EkZUzs2ASMMH5v7MKgkRBozVHUjFZECw0mrwZwqd8QFqC4VjJ3hMzZeKXXxKra7YaSVDZ HKvOGP+JjpfCg6f0P3nO/nJRZw4iLwMLENAhz1g7sfT2K4vwfNKNlcEB22+Op5yIkaLuI jcDWnlklfX/4onaCTxQYObV9jr9G1Kzm8uK0eYUH9+6vZzH7lPexZrWEwVT7a1lanxg== 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=b1xSqyL5; arc=none smtp.remote-ip=209.85.210.48 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 B4A4B606A322 for ; Sat, 5 Dec 2026 23:12:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4A4B606A322 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=b1xSqyL5 Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-845788309b4so953760a34.1 for ; Sat, 05 Dec 2026 15:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512373; x=1797117173; 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=c6CmEcbYA7P99vZk0nIxpynlJ7t4ZZiQRWGx1kY/mxY=; b=b1xSqyL5ULgI5zB0+p9jVHO5K5hTKg+dNmOx3d6Qd2i0BNuLpeB2q827jCmxFkv7Bb 7+IktmZlcUt9aXxG26jszJzrKQ6aSadRkWtEWjB0bQz82duTRan/5zapciuyZyKMyRCQ k66lJYkpnhwb16HUy46wJdMq4MgbY69qxeS6Oz9e2ySCo/gtDmQdaCbJ8LaLZoKIAR57 I4Wv2pb2h44XIknoR5sf6Xbmjyc95id64zu9L+jKzRKAH+uQUC3OgaDXn0EN/zJ9Q5ww 2OSDcOZthGHheXuDNW+MXR10VNyj0FqYq17y3gHBvCOPifwxXR0RmpcZv8CeeS9+8qKQ dxBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512373; x=1797117173; 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=c6CmEcbYA7P99vZk0nIxpynlJ7t4ZZiQRWGx1kY/mxY=; b=n+857gocVD+XhUizmGrscmxmnLInGs8ySqZBc9TeXUFtkvpWkHVqro6+GotlacNxHo mhC3Ba2l01AqqvZTP3woAcOP1T96AhCtBrpQh5D4HIdoJSJjJAE8cmZiYZjfS67bdWAt 4KG9tLCOLc8AO9ixktuEr2tTPZaqfQ1wANnbAk6kTKAB6KanSRd1Q9mKEawn4gGYhyut rRI2Rrh6eaie2d/8ZTOmGUwjFkmXAzyS6PuSHB1OPE2MDzFHxrN6iI6m9TYUGXaEeCwv Lh1PTl9Y0a/LeOLyMnciTrDek1ANY+0L2/MUwVzjrBpMODjAv5/FFjrtFWtC8Gb4D9zO CQKg== X-Gm-Message-State: APuU4Z/pbmXkK/sT7ZX27E1TbRRLxGk2sgOf19qq1PNRC+K1K8uHNV+q zBxAewlmkjFQvEUpwaiQaIzHPr5UD3JmZP6MyIc9tAjz8o+0uiMwdW1O2bxtRbQeDcdeWyhFEl1 zG+0kr/g= X-Gm-Gg: AZFdTZf1dHsxeXnj9EdOAwtnQOfGsup6/DNOHJvWOEVjRUWp9T4ytXKRvThPNNex+nI EeMO8Fj9/hF5tMaJHe/17s9uoXiD4q3J1cAeIilwZaBuHrL/Mn3tcwNUuVaiAWis0+HGEBZkyDT P6t2SW9xgeRVYVGloMgJE15cjhAqYD/Lghe/MM8gyxk4r7ilaVz39C2UGTUiTPh0+wCQ4aEv+c2 /S9GLzA5SD3zTJUPXxITm9mE2fj3yJWnz3e2pTCziKDQ5Qsve4c9DD8/JYmeIQkZMJPsHZ4sQNf bZQFf4YtbG1270sovZo5Jo7LKesV/TmrBhFp/2kOYSmRXJ1QfVtX9jJUuOVHyjUNsSPPzWZNvuu DxPc/i4FQytNr573oj/9e3DhBE/ZaSZWFmnj+9awifdnLEwCWNME3imGV/mCsvbmUofZT84bv1M lNAcBtU5rj+2UI+n7FQwgSIY5/s0ffvdfL+e66hpyY1bJKtSRdq+UMjW16LRFabx887o9i93wXS sveFa5Q79c9P89uZkn4SEYEQRaKn5y8TwOpSOjz5vmxTUVVGSkvrF2Mn/wGjSa2ngMLQqiVQ6DV ekTP1J1xBq0PDzb1rfNmApivVZgu+/3FlDsoUvRanMLzW+RHo71NTrVuI+maHaUvrDGTJXHkdSy MoEzj9xD2qEBN1e46TDix6xJ5j54HMa86KiOw X-Received: by 2002:a05:6830:2315:b0:862:bb04:b557 with SMTP id 46e09a7af769-863f898c10amr7061245a34.8.1796512372792; Sat, 05 Dec 2026 15:12:52 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f7dd42a8sm6279788a34.0.2026.12.05.15.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:12:51 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.6.y 10/13] io_uring/net: restore the cmsg buffer on recvmsg retry Date: Sat, 5 Dec 2026 23:12:30 +0000 Message-ID: <20261205231233.4140988-11-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231233.4140988-1-axboe@kernel.dk> References: <20261205231233.4140988-1-axboe@kernel.dk> X-Mailing-List: stable@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.6 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 3705b50673eb..4f4a386d6a33 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -828,6 +828,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)) @@ -876,6 +878,8 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) kmsg->msg.msg_get_inq = 1; kmsg->msg.msg_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); @@ -890,6 +894,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