From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512294; b=YG1TlmOjYP1+1+omReYYY26k+nHVg5IRAxkYY1Evz0IDWdsFrBM3nwGxbixM0+Wmvy3C IfkqtkvUwXYM2SeuxNSUJZRmNxzutCZ1CYcIjIwHOJE9nmJgcppbKAdBo+ng57n3FYd8q 4hOQrKb2a9yzy3esJ5hiDwFlfxpke7wpIosyYogjQ359hrT/Wr9wepxZSM5MBJdU3gNcv mgPLAFGQJelCeIm7TXcxHVMA5GsEnbYnMZNC2Cp9wD5vgztT/KMBC3YKLolSHoGjkEYin 739P2fl06u6sqzDAa7sdnuW4xkcNoHRrhXJeVknzL9mQWMACef1ThXLJZAZ2WxsRvCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512294; 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=QLtjQePMDqeqc3AidtONfLMrb0rblYKp2IZ+MyPrvMs=; b=uDTSyg+rc06p+Xr839QN9QMpN/mr0GtY59GRs6fyQvGWkohyg73uQ+Uf6A0Cj/djFwKZ QnnSPrzR6rS/pFvaQufnqnYB+GCXENMitCNh14y6DehMqyohtdUO1An+GBPnvj3N3pu51 YfLFA11oTa3g/RoiOWTai+fQGfi/jKNtNjWtoNs38zhS+cGIWcGs7F5FKdkrIW3//YSHi 1F4a2lL42pcTQnFGXn+rZsDOd6aH1LM0EzZ6hUxxP3oIAYuCeeoxhpKso2/oSJXs4Z4K5 d66ayZ/xSe2G94/aUcykwyLyhjhJVHqcKpU6/NWW+kXUZZVGriF/kw2Kz6s/iSPozIw== 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=fhZ14ANf; arc=none smtp.remote-ip=209.85.167.175 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (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 B239D606A31F for ; Sat, 5 Dec 2026 23:11:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B239D606A31F 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=fhZ14ANf Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-53dbe9b8d6eso2179295b6e.1 for ; Sat, 05 Dec 2026 15:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512293; x=1797117093; 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=QLtjQePMDqeqc3AidtONfLMrb0rblYKp2IZ+MyPrvMs=; b=fhZ14ANfVuNzUTijB/tmyvnuhLoO3/IZJAJqPFn965PAo8EysixxyybEzS7sm7ZrZ3 1pF9hP2qvUI+rXoF7fzCOCeoTNQiwaXP3rPLFJByBrwo2T3mA/H6MDcNbqMWCikcDtcl GkSWoRk3tTPYe2xqKYL1B4rFOX2GNTCJU7IlSME30uJtgwffwtOL7pyJWsY7qpFPOphX DqrbE4LAGvKiTcKAyy2Gni07tpNYoVnXyPZvL8grUzAN91TMhg28Jfh8plo/b2V/zQ+i QqRo/0jVkBsYmmeLbNgNFjPvWZuYjKj2t6FaJpVP2KvjCYCL33ElzGuXFnnAg1hZkmoU iDBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512293; x=1797117093; 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=QLtjQePMDqeqc3AidtONfLMrb0rblYKp2IZ+MyPrvMs=; b=m/+UCK7uxzpGudhdb6e1VD43Z+Bj899WzgKbOeDqZL0nR177tEsr5V5NXZdkUv7M/a HjKORfINNjC6LRAkV0hwbi3PWVtEtm/BJm68EF2LjKT94Qp/w/9EkY7q4HnDoBvnKa5w Ow0J4OI1d0RB/vLa9uRfzfWH0X47tysveKXV+JB/HZHBjz/ZpP1zpC7FbhZbZ+DWSsnj z958Ik/96Ji/7RhE84zmSz7kYqLfVuYm8yb6CIIcC7nSRggf06Ll4UOfIBanTLAso9AC 8sp21KODH6pBbyQVlvRUQB9yb1qIcN0JVKNjgnYIeOX1XeRimL2gymKkkK7PJfZS0/5B QC+g== X-Gm-Message-State: APuU4Z/pAHifCRNRt1N6HLiXb96kJOG01qW7nFIi2umzkNcH15g0L+EL A5LWqupK1UapM7MVnsYefNbyA76bcM8eFKlDy8RYhRZVndUYqg5P9mp+ZUM1xPnq66cBnE1CVIi Q2y2PuAY= X-Gm-Gg: AZFdTZcDbp/tLuAWGcvM80rm7ItocqL5uKP3wIYjVo44qLuqvqkvq6P/k5lWa4vO4Oy o7VKuQFRsuwcYBtzK2KxPHaB4a2sKyeFr/B6ztv56/+GQv18oPMubbc1n5kAbF/9JWAxWEmzi5f 4Peo/hINg0lCNpD7iJ15DXrTy1N06QUzPMBumKs8EHUDA93TCr8okw6TXfv5NcUpjP8THpPUFpG BVFXlTVK8wpGJ/u+sHH7Ms4HQNXkyxEl/s2w2dv2WV0YTN0lEO1rCsXCzJ+OEYCKDHxNyZEiP8Q W1vtLkojFh9dUpwlrsoZ2HKpPu7cSH0aSEU8TRdClEWbS2SbzejV8piJHf5WYaVy/Tw+ALaFnh+ 8lZ3WH2c09XAl8X7tIThX11p6vhTtNuPXe27gJY1uClrggi3gGBDhdcdD5Op0wd85GL6HAOE7R9 yRsnMFd/gCC435GVqVisOlH5fdDEfJQF/vSB7+zFaxkQDsgk94MDYc1U3FRWJrNGyS2Ahg57S3Z Oe2IJgVZpwLcQ00t7AIOhZg2jiLKsDYcs2Pv8KDqzKbpP3gBh7c+PIJh2vIEo99gHE94UPFPWBJ 9jr6LjoGcTFJGp1ZGx88HHaCxBZ6no1ciW/Ay8hOUIcFHLlUX7DsLdoFKJcowciLunZNcOkKDRs MSC1m3yrUL9IFAni/0qDO7OhpsPMCMCWzprhp X-Received: by 2002:a05:6808:50ac:b0:4d6:9133:cff6 with SMTP id 5614622812f47-57f2081b0d3mr4572521b6e.29.1796512292698; Sat, 05 Dec 2026 15:11:32 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f65febbsm4163964b6e.6.2026.12.05.15.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:11:31 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.12.y 12/15] io_uring/net: restore the cmsg buffer on recvmsg retry Date: Sat, 5 Dec 2026 23:11:04 +0000 Message-ID: <20261205231107.4023506-13-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261205231107.4023506-1-axboe@kernel.dk> References: <20261205231107.4023506-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 01a3ad67474b..6564d24e49c2 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1037,6 +1037,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; @@ -1074,6 +1076,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); @@ -1098,6 +1102,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); if (issue_flags & IO_URING_F_MULTISHOT) return IOU_ISSUE_SKIP_COMPLETE; -- 2.55.0