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=1796512331; b=pCrYgUlQQGDdEbRT2DzIh0hnNTaRYRfpO53JkFSwNqhkSjhXxT07vnLptoOqTKexjKXv IDT9KgA2gPdWDyipgIGgD/7stdaznp04RFJDr6Uiiwgo5BUZqY4MZNj9AvZgALoOhimUP QnHZ++8K2hF89dsFXM/8/Qpy+CLOk8JMeKBsAqzTrRkCesyipwwNBIxsz6crxzJTFxtba oJAqhNyPjYwwbqZetM55U8fO9sFCBSFTfufRvIszR/AMN6zTh9Lx4Qr9BRUktbftthg4q 3FvtMGRTXv62amYXNstuxq1O0WxnXRE7DcU7zchGHak4CO4sa7CpgvNH6ENsd6pgGZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512331; 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=FsEVIxawJxIHtmQqo81eWscmyvyuxScrCTqMpVntt6A=; b=KhSf5U2VNzKy/QWOobWpJtTpL5J70ZqQTZQJAA8rBih524fvGJ6ZrW9/4OWfMTBfn80O 82zEPPndNgiif4hG3o+Ly0mufbJLdb3xmMsH8DhWEqynKpkkLw1+SVuqrbpeXL97zdaDU jaiiHCbOZ1Cpy/GpW/4XkJvnJWZh3lCoEnG8rZkTaGbQFRXMKCBhnN5b6rRvZA28B0u/C 6UcqqvfFTrI+6nu9yqTr1xjiI1eBShIpJLe+6gjgHx88QwcwjF1CZu7I81ZjEoRPf8PAM jKT+JhxEKA8PP0q54qR5alm7U+/Dskm9Ox40Ld/7JsImYdVfY8sSphjDbIwkU1wmxfQ== 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="HOVj/L0b"; 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 C357B606A32F for ; Sat, 5 Dec 2026 23:12:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C357B606A32F 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=HOVj/L0b Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-862df509ccbso1392549a34.2 for ; Sat, 05 Dec 2026 15:12:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512330; x=1797117130; 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=FsEVIxawJxIHtmQqo81eWscmyvyuxScrCTqMpVntt6A=; b=HOVj/L0b5+9n5QzXF+WzS0l7oYxJLKAAHMOcrSJlZm8YBdR2i7gjKOE6HIcBk0FIvl PZPYRcsLyXNxaNxrRSsjqvGGgoCm9hOuUjBbZTiHW1lL5TsONDR4Eog7wy8LLcgrHQ21 r9vWQgYG21FtJrnBQXipRH7mOrNDqTO5eInA+lmfigCxcutXcTUkuX4Yma2rb0sgOOWy onMmuJ8od2+B9II2H+iuGPuTSlNoefDuh1O/09ztcTwGKp8c3u0e6SwUvpqiyUOCSh1I T0XJ0ADYwCRb6fUr0Jrles9PYAQ76726LtHU7NgA07hBTerC57KJD2Lf6zYjiXg8Nyt0 4tyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512330; x=1797117130; 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=FsEVIxawJxIHtmQqo81eWscmyvyuxScrCTqMpVntt6A=; b=X9WptOi+lhW3zNP2bzkSF6VLnt14cX28o1h+gej5qnBsuKQmT8gYnbg/LmJ+0q8Grq jdYMTYeMpfTFmDkw7DY1pF8Mzhpx5W17V8AeggsXaAFByghb4NqsEu2vHVk1gYzX8T0j rGMjoTBo+WMRFzWRL6C/Lv9ULClVDeWDZbBldybb8yuyTbXJPdgh0DnKQeAxRn/yFw3I E4Q2C/Q/E/nD6zQv38iWFFHRAaU44XNboERc2fgv+67RTaZHkApvbu2RKTCPtgcBgWVn YlO2QwA4hHfpC8aVBNK//L3YNH4XyfWTKWN7NSAuiN/N5+9lCwKw6VMB8TcDHyz4IbO2 j/Sg== X-Gm-Message-State: APuU4Z9l5r0I9LptArMuTum0L5OcU5Br6gndbYRsuiW8Ua0+/s3AV+mx MFk+DBTIikRoTXC4V01Q6pRSb2HTJePitJ/rRal+JKx/nKHWDkFTogdIWwEY18i+IwI= X-Gm-Gg: AZFdTZdYyaRL8hYoe1+jb2xBROeiEvUdOpSpqO0uMWbPdkJ0ji7OPrG0g2scTDSV4aw I7DfRpVPBH2A3ZSn/PTFTdLU2FYtYcH43S7owsOwJH6YTnVt+utHFBOTULR5jYzrqx3aW1U8Qdl 4VJVk+1RbIFbig6zbJIaqfGkbNxPRGJNf8faF/SA/7RKX6I0MZ+b1nJbK7suVkKviwaD8e5fp3E ZUe4lFGSrs1/pM0BX7wZ9ddUiNnyoTLsj4t+Vv244D0ry0w4QHgnjhqvoRC2dkJNYyRV31a9jiN w78atiV74pnRKXlv7II8xvapgKJGC7Wj8bwARnG8UA0xy0cOqJcV0u1ESOxA5556LSu2cwJ2bS5 egUJaFtgCcURC0108x1bXijirOU6PbLNlaXuKkb1X8JlC+UFWdF1hQ6NCk0dzntLQJN5WhSmYY+ KydxRaVxhT2J1FwHUrCFkY1wR8sRicG276BlDvMaSYRS7jlaYcvAXh13wEdttmVpO+VSq0cInWW /xN5SQqP1loVRFEo5Q7AqugUu/VD98TB7F7QaPq5+RaJhO1lOSiRNe00TzJCldKswN0y6dPAkTC mCxU+tc0hdHvNL9Xqev6k9PMUAmlyteA6e2FXPLC/y3DsmWTGPACM76RSv6wb9F8fhzaPrIf+Vo ID8uP4UsRzouBB85rQ/b0n2jegIr62DwD8rV+ X-Received: by 2002:a05:6808:2381:b0:53a:65aa:152e with SMTP id 5614622812f47-57f207f5cbbmr5839997b6e.35.1796512329719; Sat, 05 Dec 2026 15:12:09 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f6fe2ecsm4086916b6e.14.2026.12.05.15.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:12:08 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.18.y 10/14] io_uring/net: restore the cmsg buffer on recvmsg retry Date: Sat, 5 Dec 2026 23:11:43 +0000 Message-ID: <20261205231147.4095031-11-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231147.4095031-1-axboe@kernel.dk> References: <20261205231147.4095031-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 09ef15e0700e..476ae9b38b63 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1045,6 +1045,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; @@ -1082,6 +1084,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); @@ -1106,6 +1110,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