From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512254; b=PICeyVEfhskv1/KM7zWFndb6+BUfoz2JsXE4yHPhcU7q6eEzCbZyPS6rDI+qWr93fsvR mUxqQL4QSGQPplISi769I3plVBgmB2JX7xVLg16MFxECrNA3O32WdVn+gnSE19i2pLx+x +rFSznQdCRSREd1+qCGv31yXBGSNSzf7QVi8m9UxiL4xw1FibOPkC35omqWlCIHso/oKl BRFSWUKV0+sgMKaPwADwxe7AlCSraDoqp95CvQ1lfrCukGvWGlM771Y9/mvfhLRrnyMLl jRIeiMixrYoIbQd1R5sABBMVfFU/GIKpC7vju1j6/PhD91wfU2iuvEcrrCsG4SqS/+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512254; 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=r0cbHV7gyxOFERgwBrupxO/G0B7RfzkIpLbMDp8G0gtQwARSxMrAaxBId74uFO3ErFn+ ZoGVykJ10+A78QCZv7yv1MmzOPV9VtROZyuA9DIq8ugNlb+NEqP9yRcaG9J4nAX5EzPdY iaTakt97+GF6NAykQgp+Ni5VlS7hUobGf/xJPJwoO08eD1Q3r/0tyVVuG2yH+n4Zov2jW pGdGltqI6AgxrGjmH/OZAKLiHT7uBlZzUpYy/frH/yo38coykpa4FJHCftX44R5y6iPzG k8EP8/xxPHgtoqqTlRAP00RgE+RIe6nnQKPmJ37N8rqP6fYJiWdcSxaJHgoin3XiI6w== 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.46 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (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 B944F606A32F for ; Sat, 5 Dec 2026 23:10:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B944F606A32F 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-f46.google.com with SMTP id 46e09a7af769-862df509ccbso1392135a34.2 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=N4eZRfYd1/LIuK9lI3d+Cc1LF9vU2RV1y/ggamGYHtbSpL5g13k2I4rvah5qZ0QvRo d0TBBPyKJ+bXcPL5t1NVRsXJk4PjXufOtcJqd48oUi/OwMxSDO0ycqQh/C4GBwVc0yag h2P/0sbySLGYKgFvfOCaEr5SoyRL5IBLssWgwcIBqD6ULenHORL82v2e4VoenbmbvCi6 4KDWmKAYxqWmK13stOdGlzncG2Ww3D3oMKHsrRTEWwAz6uqSWdbRYD140Zci/AQEn0gF MQB5yd36eW5Bug+CR9zvdBDOqeDg1R98eYnQBPfVp5TOxzgm55VpzYhfVxfBE477ufwI 0gHg== X-Gm-Message-State: APuU4Z/VrWIv7qTRdQvD0khgwYBTvnykOjomc7kN21SLFrrQoQT3Uvlf 2UjaKOJ8mNf+GoaKHy50oc1uraA3lzZ62zW+sx8pACtZJiSh1qWp7XtonAOgdu28r9fPIVsyskZ Uv5Gtbxs= X-Gm-Gg: AZFdTZf3HQDZJjHpVTIihfGQ3XAjjtzZiNF+JUZJ04aVOd7+2SxUZ0ARJp0oboJrZ2b hKQtWjSONxcncbmZbqkBqfM9njMGvbxw7NFkJmfrAogdgFA6jLHe0lGuwbntGnLXn0OXiwUcE80 FcD+5rr25vt4lNBUlnamq1AXzA0w6V8fSmwFZCsvURXgvhuWQ4QzFt6gb5hqrBCZ5QJQCogpPj5 LddIaW3UZBx+O0EIVNEhqWbhochJRqgWdtWMsq44J9g63bgmq0p0zZLaJ0jasgiBNnKzUe8xfP3 z/one+DTqJzliAb85zVqMgmmnt+y62gTH7DlIxbsZq0fUua2aEP9XYT+lAaMOb0gI//RlmaFK/j hZtaxKd2bodmJjZE+uniR4zjwCBMeBA3a7kDd7TTRoVOkaVTOxEylRJ2RTI8K1yymSrXWXX8EgW S3ULahkJyaZvQcZmcwFHo6cXmvIR6CAhKivmFcSh0XfQEcfU2D09XXgk6vn5MMIR+m8aRiLDHXp O5F5uctRBk/J/QWRDDB/caAChgTNo2YcIhV8gA43kT6mq8hD01UUD5L6jfKKbhLcyAnGVDVHx4Y cc9tG48st0OdEq3H1OAbcAbpv61dzNlF7jetQ+lDaKK0KbTmGWBVlG+04m7n46cA7Q/JC6ixTyn POMz8NtkMN8tguVyxt2HXq3WCVGo47wc5eTzC 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: 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.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