From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512406; b=1Y3MHbuc1j3fITf6M7VOo1mu1HtUhDiTdVsQwxcoTgtck3F9lkkZtREd+DCvyTBrd60H Vn254PI4PNYBeMEBeoV1OjjWcTVXRW4o/3pCH1OgYzBkayNrwL3i+y92uanfBq9hWhkY7 vhqjmGT6ptgCKiKnlFW+Is07Q0kmCRd6tsCgUX1ub/1dXhXUYVv+rsglNfzsCiIgGroKo teDRCoT0tBhHbSJzLG5Gxa2ZjqN1co8tqQVcYBU9zXComFZiOcKMgS+JSdHfs6kXhnKiQ UB6Q2RXVtZbCLviqNRUzk7QeLJZgEv2kCXGpt2fGqGQUJeGCm6gQvdXje3GKmrTBdmQ== 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=0/xqT10eBvuqcdOhxBxlIVLuI8bEsXf80rfmRNv0wLRycf2/lwnjE2NsOsnWizMbdbFM 9wVNF0oKFYDWQRDgQy6pkAGJ5CYWYKdwi9/sfAb024GDRnPm6QJC1PQJGAh+aTPGz0+dQ J5Hq0aL3p0YPVkmuevKN+YyEQebttA/xFBBKKa7OqWZr+CmjktKROiy6NeGaU78FxL94V WDG+zSyVohfAu07A/AAw/TkMiCzl/jHSnAwGk49fIDVCGSXXzeTF9r1PJDMnvevKcvLOY hjywsnUdHYC5bnJGy1R0MPamldjG6J6qCVxt1XFT0QdrDD3gKo7DjtGos3sQ2bu93wA== 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.49 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 9C6F4606A32F for ; Sat, 5 Dec 2026 23:13:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C6F4606A32F 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-f49.google.com with SMTP id 006d021491bc7-71ab5e64742so1086334eaf.3 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=Ybu4yv8lpQjEHbCOYVdjOttg1Qb0l5meItZPosed8m276xILHWNkFNCc/31nY1ndrw 24XLl4I0ben4xEYEmwcrjDUGHXJA1fujpaidkUCOV2I5gsJUfNaX+59MV/dsNWe/LpRg aWRG61bUsS5vPlgu7ewMdYvnvN8WAOfAPeCkoL8xyHd8EeRTbQrpZjQtGXAEo23q/SDZ aoDX0kWiBQ2AD3bkdfvog1/hSTHxA4qRwY8iuMRyfwxZ67aIa+a2qPt8EooQR7quPRd9 wRCa+CM84cLPfGBABUAj24nHHm3RqOWLtDMHqmWz/zqwjOUmQU2pYaDpBr1nCKWB0WyC imXw== X-Gm-Message-State: APuU4Z/FsqrXwPdjRk4ThuyLkfOqx8ScOwY2Kd1aYq20dXn9X2zg8BeH jxdEetjtkBhar5pTew1eQDdmuCehfgp2ko/0elN61nADUSEtILjtOj2cqgvoGpui/Dw= X-Gm-Gg: AZFdTZc/nmvegq9V6w8eUuoI8v6qn3TW8deF5+SOvjQK8WHvSVyYxnHIm0OsOT3DQ1N mSqLXyBJRht7hUwEB6zgCS7ARSniH3+n87NH7StQOFHEKe4deau/GeWCLIm6IOkbyCopXeoPHe+ 18wlxZhmCRnOvuk07uDuDVtzl1Nwzi1t78MeBvJ/fGZy4rZb6Pb0JOuSe/M0MeM0Y32FqxJhd2w pLgDGhEIXIcVBo5OcfqQj3Lbxu1NdWiazrNgPxuWKRa0kCbLnykV8wDop15Koggd6vnAB306+eB AtvGgzmaQpyQsh7YkdAzxYynFZhD/d2J7arqxqSW2qK2RGJMOIv5FdFH4x6tsO5uREZx6THBsOX yqMjKeFumvqocNzdolh3eZuHd13YQM8hJHwxZVC4r6hKPtEHu+Ls0zAw6pIWuTGFjS0IoW1Yugr /1Ks+8z0zRKj3c7nm7p1q1uGLWbM9rsT5D2WXGCIbXHTtzIUNzMXtJwbezUQsjoUTxclqB3WuFc g49iJpEJSm/i8U9g8pYF42IkBzmCb57dyGIHJO8Us32pvuuUpn7FORMgDeSKH6BYjFITGtuJR9P JQh4Cdfe8+3RiLPVo8AeXQ03Zo0eSPKcN9OvNyVIeEDnPZxCzTJR/SFrPpZs9sGlCtzseYmh53s ZVhnGDYpvUNlY0Q61Qza67Cde6XaRlSRHjfVi 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: 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 --- 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