From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512318; b=gar23sPkVydzOIB8VBHrGWBKggUAzKYMYZCT2LpNpF7oZ72npDIoOoqo2aXLScJCaM9+ NXV0wEQyafeF/Vu+qlOvlCdGiYZ+PeFRhmigC8Eir9cZ+ITlFrForWaa8pGxrauaJzSVG WBKxUCboQYuO9IkChdOE4qt3FzFgM/I8Sm+CE2xFojuvDOZ3ynld57qHiy5K/aYUJnjqs rNR27JA+VLjTuw5P0ZjWCzxwGc3ndnll5wfrm/pxscZEAS0AHAxv8gaDerUJ7SMi86itP 4q+Scx3uCPHCXBxTT8IlL9AbbLFbidgXsZy5QuyD2tG3ITv+kxVLB1bd5HivwELgQlA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512318; 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=Qfr7oN8Sq8ILCDwNimOd1tVC9706wWphve4VsmXFZR0=; b=e8f9JZKuhzolrMPO9vk0sJACYi5MDs7KRenQSkb14jLwiFXkzsLdTQemgufek2n2r2QM 3I5JVQbsk1WS9QfbsLVgZNrz6qV+laewzSRZCD9q+t83fyAnSSQc0vs/69jBTUXTRSei7 egiM93dY83ikkkJqkzCIfA2Is29qhmMhbIsCJll71+eyqvZH3rzhJKoZf6tDi22ziZaji CB837kUAKCR2091ezCGK01YA4pztgwk/OiwTa5WW2tychrnUtxoD1nmAIfWUBiD3/Wi+H 9St/fKsTgsFVgEjiEvwJti2wwTk6vzt+AE6fbfMqmclXok7vlO7866U4UyC8e6zIqsA== 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=uANvPWnN; arc=none smtp.remote-ip=209.85.160.46 Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.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 449AE606A322 for ; Sat, 5 Dec 2026 23:11:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 449AE606A322 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=uANvPWnN Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-43bf9548df4so2096902fac.0 for ; Sat, 05 Dec 2026 15:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512316; x=1797117116; 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=Qfr7oN8Sq8ILCDwNimOd1tVC9706wWphve4VsmXFZR0=; b=uANvPWnNBjKw7pqNyQ73fMipW3fIMwNOtBLWu1XDfIvq8p5XW6mJDDQZV903u59/XL tYWgidtY6GcprF84rnWwqVYKs/p9lhXXnm8J9X6fZ8FGC11g4qMib1g3VA0ONr/FZnvm laOZuUJmHh7M3n0uSMsheqdEA57Y4ZwXYelgbeyp+FBrDIrS3J8wjEskAPr4G6Hr1QOv GP4IulMsOjz1ZtSo7EPHdPKbd2uxSplVKg+8MjtBcu01kWBPciPmgXJmWtZ4rvKYvOKq KxzKWOpmgLOixYAEMB8evhv5aS9hIpE8trXPdzqiMOBZqEMyN9kQJShX48udp4PcBAwC 0NAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512316; x=1797117116; 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=Qfr7oN8Sq8ILCDwNimOd1tVC9706wWphve4VsmXFZR0=; b=jMkBTtHHXK5FBE/MrFZEttVTSpcWpWg/E5CsQNrG+u1vTRdlnQtHCyYOTT2BnDuoEh PMTisZmAPKR4Qyi4iwP7oJTsB/L20i/A0cpPE5L+uWBLaQ3r5Z+jivnw40anhChr1RQ4 8Z5VCMLxDpyPLpJFg2o+bLIFHNS2xHQFhDfwOJX6U1+rtIdNoa0hyWVuCGCJ8pWlYRTT pBVdiRQak66W5cE6/U8JbdCZbV3KWAKjKEgEgTLx9LC3B7rIFkMGiUiXtYvemTtX8QY2 ANmpfIMSqhWZCGrWa41+gBEUSetWIETckQhJyaNdUTinXYUwE5DmDMtJd2w6ns8SvXps 6K/g== X-Gm-Message-State: APuU4Z9y1Xt8AaSA3/rAvYlz95EoIzSuujUqWcHB1/D5fYmUjUHdnTw+ 4Wf3Lehi2qKBpfPqLebi+3F9NHfhw7wTEFfOJvMdSzIPJusfPULGWhwgvovQRxqLPlLGcjGMvXN X2fPRQv0= X-Gm-Gg: AZFdTZe5KWgmJyWaxhcxSzEKthKnDLxRXbba/cnm6Tby2oqS5LIYpPFt//e7EnXNLea 4k5PcbGa0TPTUb+rl1C4ItD6XnUI2ulPUHX7YL3sN6oqNFZuzawRYoIRgApOfZzrOlBlOZl96jK vr0SasKrKGeh2HwseNacO4t0Cd6hmpOjF3duz+lCHnKJTwyWNS6qmulp8CiAClgr01yqTnTJwsx IhBUiKj1Na3mdXLSKucVQnHViUWVUIfrhRs1bCW1rveKpAZ2XWrGGSMR34UQIDdzvwbFD9mOn/r Sq2ABczSZgAPlHtPvwtRqxds2D7GkOBCEdu+ll0H6/LfE7W34UQB63icfi9Dz+UVZhm5yfKI+7h rSD5aOPrQ0uTsKaw4Rt6gGtkWhN3lIRIqIBUvoS4B5UpbEWhBKzi9GjKPuL/WZrfo3qrYkUOB4E IDlrvHcnLqbj6utyh2uLtsa01dYcjlD4rncDb4GYf5+K7C8Dho6Y6P0LJBWd6V+LOcDI9MAoTg4 WFvdlxHbkO+VtxoiT2uAO3AcccV1JoOKlcH9yuFdBHvpuWtGa+dlyouy+HyHsuG9uTXE8+bzrql XGfWJGd62DXIndVp7AvQyCxg0sHPy0JFgPptMgs0651UtHfL/rfQn44lUmEcJrJq/taLDokew5v i9yG9gRDweAe29M7PD7ijlG81rOy6MFs+2ikASasdjfvzGx+1auljy5cjqA== X-Received: by 2002:a05:6808:179b:b0:4f5:20:d847 with SMTP id 5614622812f47-57f207a5e2cmr5659188b6e.36.1796512316310; Sat, 05 Dec 2026 15:11:56 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f6fe2ecsm4086916b6e.14.2026.12.05.15.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:11:55 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.18.y 03/14] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Date: Sat, 5 Dec 2026 23:11:36 +0000 Message-ID: <20261205231147.4095031-4-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: 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 2f70f2cf62e87b908f301fd78b2d01308cbf2ea4 upstream. A bundle receive with MSG_WAITALL can hit a NULL pointer dereference in io_net_kbuf_can_retry(), or share ring provided buffers with another request of the buffer group, if another reader of the socket takes the data that the receive is about to append. The buffer list is only known within the issue that selected from it, so io_recv() has to commit or recycle ring provided buffers before it returns IOU_RETRY. On -EAGAIN it calls io_kbuf_recycle(), which does nothing if REQ_F_BL_NO_RECYCLE is set. A partial transfer sets that flag for the buffer that holds the data, and nothing ever clears it. That was fine while only a multishot receive selected more than once, as multishot excludes MSG_WAITALL. But since commit 7c71a0af81ba ("io_uring/net: improve recv bundles") any bundle receive can put its buffers and select new ones, and the stale flag covers these too: io_recv() partial transfer io_net_kbuf_recyle() sets the flag, commits the buffer return IOU_RETRY io_recv() fills the buffer, msg_inq > 1 io_recv_finish() io_put_kbufs() leaves the flag set io_buffers_peek() sets REQ_F_BUFFERS_COMMIT sock_recvmsg() -EAGAIN, the data is gone io_kbuf_recycle() does nothing return IOU_RETRY buffers mapped, but not committed io_recv() sel.buf_list is NULL, no selection sock_recvmsg() partial transfer io_net_kbuf_can_retry() reads bl->flags The fix used here is to clear the flag when the request puts the buffers that the flag was set for. Fixes: 7c71a0af81ba ("io_uring/net: improve recv bundles") Signed-off-by: Chris Mason Signed-off-by: Jens Axboe --- io_uring/kbuf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 6659f56e91fc..1f95b64731dd 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -413,6 +413,9 @@ unsigned int __io_put_kbufs(struct io_kiocb *req, struct io_buffer_list *bl, ret = IORING_CQE_F_BUFFER | (req->buf_index << IORING_CQE_BUFFER_SHIFT); + /* only covers the buffer(s) being put, not a later selection */ + req->flags &= ~REQ_F_BL_NO_RECYCLE; + if (unlikely(!(req->flags & REQ_F_BUFFER_RING))) { io_kbuf_drop_legacy(req); return ret; -- 2.55.0