From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512406; b=UCgv5qg9yXsRUOLMkIrerV5jFy2f9i/Bx+awrDBBeRnXjGuQfFncIva6b0Z4ep0ZQgOq kQpI1ieV889iqrGnWg6U8OAyzCLdDlymeOAboK1O4sp5dme3iBWf5rABeM+Ruj5leTsgm 5FjgjmqyewdJVGoNeeLj5EWWWe0oki+xUR1rUrXGArudzjTB3fQ/PXgKHpeFjphGOVbht gBw4e5fhIcJZN6cWO0KdvDLXdxKWM6uGODWbD7ILpxQdkpcinZZ1CQrQ7cvzVr9AzcjV4 gh1byNAYxP9J2/t7YEzrq7M2ER2VXAnOOmYsYuTW2q6LTaq4J9Sl8M1w6FpMY5grfHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512406; 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=UpuLyp1ksdnTHuBY5eLMPp/okpObMP6fkiVV0TTqTE4=; b=xAnRV17pJo+6QQjluKkTfH2BiLdhPinqUzi7fKAd+ai+uloC249PWDLe+gc69KV1aW9z jrh4ZYY7cw8i9dc1jeox3ncqdZ1T3xJObyyjwJbtw6zzdsBUt/LxaqV/R7CxTXaGuCHLW ERhuD7Ag6bfXqnnlghunLtCMDGQDxCq3PsJExg9LqOLnCk7NVHq2I72I102O1A/aW2OX1 M/g1WINQTPw8Df4H1BUxWw/CulKO2YJ0PdrT5PWkIxthKIIYoK02fmcyo1Z5Xbx1ArVmp A4Fwryy47S/LcBPGP8bxkjpruk+Gm0pno+RIgPoxIW8LZo2Lny4mLyxaMwJPo7w3ecw== 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=Bk3iOywE; arc=none smtp.remote-ip=209.85.161.48 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.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 9EF21606A334 for ; Sat, 5 Dec 2026 23:13:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9EF21606A334 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=Bk3iOywE Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-702fd86d674so1648505eaf.2 for ; Sat, 05 Dec 2026 15:13:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512404; x=1797117204; 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=UpuLyp1ksdnTHuBY5eLMPp/okpObMP6fkiVV0TTqTE4=; b=Bk3iOywENYLqfWTi5bFOgjfy7aA4eOnDVGWK8YtUtIJ7atLCaHhMmvpJcxdPxnNHXU /wbOFm1A67CsHirMDi2w2EV85OS1aoZL+YQyygO0lO6HcFoH7L+olvWst3IAA1IGusT7 cwNxDXebIs22OW1X0tKK8ZHuWV0vReEiPTByaJXgLKZg7I5hTQXv6egS4O+yupCpcbC4 D7OCoa0J/zc7xa0UDaak2hf6mlhsqYxbGVuErYIgBIpDcLjaQeWqMqveJQQRsdV6eBbJ JgBdRglKZ3hDO9EUktfJVU77PAYVcg4HNUKS76kAxnb5GnDyZW5mfrl6tKTasnhBFPGl uoIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512404; x=1797117204; 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=UpuLyp1ksdnTHuBY5eLMPp/okpObMP6fkiVV0TTqTE4=; b=f2gq9ytudTFGmwEBS8/fLhZBBS7tObA9XIHamfgWh9/KFyMMB5UYlpygyogN1UxNFO kUM1Fgjm5G8HhuSo/aY1gARoPjHvQmxdf1LVPlkvAlGckEBiSCZDHv2kfoLoW5LucYor VDiJN4vZgbKihcmITKT2P1mT6Ezps55S8TjKhkJceAJupkLa3mpW/uJfLNn+q4LErbr8 99G7njtMXWuuwgactAIdcZcvf+sKBAZ6i5uYxsx67CtSUAoAii0y5nia4K9xmzHswELr evueGLme2xltiWFxuM4PD+6iWZ241BhkuVlfBSEiiLFZP4wubXjjIHhbv6CCiYJJFJxk sAMg== X-Gm-Message-State: APuU4Z/r42s1FYJqGO00Db9/6x37Z6I7RksoC9BehSBuxk37eaeeaQT0 M6KFowGVyZd9eXcU8nuSbe4XzWs+W5cqb7OgVbfpB/1qEjfGimcu03Uwj0vU80LwWGpOEDTvHx2 RHngr0rI= X-Gm-Gg: AZFdTZfeYklxXF3dvLlJgpPtRF5NN6eQGJDgAuDu54Dc+LIkrgj1G0OHILtbRHmuJxS jinzAAnIgYzKiXAGL+bXenY2jnmQzErDpHCRZIT4Ue/fMlEEV+VCo7Simn37mx5BiZLvkbI0iR2 4wxVFLm0cHLaXp8WI+Ott2NB21YPsbAiXMlEnLzsaduDl3TgGl1WeXXtQ8+POdYqFR89TxZZKY4 HfKPjBU60EAysDquFgGf7UhrzjDmCWR6Dg8GLTYiSYPqJdqDRQRRulOWL8SFHRnUD+sx+ncJ/n/ ZhHeUy+YQmUS3DWlH81rd239WDaoSJfADZ9uvYZhMtt95ZWkTaOVYFFyy3rPR/2YtPjQvol1WcA +MhBBHwg26cRELIyxw/XHizeryLwhH35mF6LEeQx4Lel974+138lPxlQz/Pcn85f44h+lCfrjoW m5scfSoboTtBxh8c8+aVkCm1uIgx/hEXezSJyY5RVz5n0erEKfTIDAsJzpYXE3jh8E0nXu/M+16 ZzKlhKMUUoHpJK3vhnfdvSdUmDcksrnIsQbmzXoxZA1k1I8HLrNtdiOks/7o9VgnGzgG5Tgq+Ts Y9NB2BqlJXEKuBAXpevA1PD4W8SCDk1J2BvYRRj7pDb+EQ0RZD2V0Ob6NT/LAJzfj97bzSpyOBo EgLtOP59iLrqViJNLo6sMAQSF5v0RFszoOBPI X-Received: by 2002:a05:6820:c2d3:20b0:71b:7b42:845d with SMTP id 006d021491bc7-71bf20703c2mr4040661eaf.28.1796512404565; Sat, 05 Dec 2026 15:13:24 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863f8331ff6sm6269737a34.22.2026.12.05.15.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:13:23 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 7.3.y 09/15] io_uring/net: restore the cmsg buffer on recvmsg retry Date: Sat, 5 Dec 2026 23:12:59 +0000 Message-ID: <20261205231305.4158103-10-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231305.4158103-1-axboe@kernel.dk> References: <20261205231305.4158103-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 --- io_uring/net.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/io_uring/net.c b/io_uring/net.c index 2e1d66504266..688db0f4af4d 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1047,6 +1047,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; int consumed = 0; size_t len; @@ -1084,6 +1086,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); @@ -1108,6 +1112,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; io_kbuf_recycle(req, sel.buf_list, issue_flags); return IOU_RETRY; } -- 2.55.0