From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512277; b=xsbzWUbtpzouej1K8gjlZFVTUX6x5ZouZL4Se8od6oYPbFPqifa3FlWaheN3Ojbi4r5/ s3ajVIojiq1bf01CfcB9POyTTNlZ56j1wJHexz8D2GVDt9G/CODYmvluAlofYWEDkaBqC Rmsv7V+IzmG6UlLYV85wqFebo0OmwGkaWJcdrJrNYrs7RpmDZMjgHJ4PW4egRBSRvFlj/ AEpsBOJUkpogH1+2h/oFqBIOhFsTGhAzcIh4MKZxuKkXzsrTb5DobIYYBzbhDwlR/Mk74 mxyG9sMuVREKdg431BhNStw26e5u7l7I8OB8Y+MM4WBtCK0iLkRX1klNhpi8BVz6w1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512277; 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=DmiAVdiLRdqwGzsP7E52+pX1E9Sri7M3/TYLQ2RxGHE=; b=11jaiOmCjVFyXRsOeKTQU5aO2KlEohJxOzClQRP/v525lNwrWOglmJudUKX6jDQgIh9A NZzlNfO99cSv6uMO1dC0MRA64UQRn4rHkCdcHkBSZs/mwh2pQIT6gCOipCvfyD4wOTRZS +Zqjo2agx8o5FKVoiNXZX1Yo63EZcNY8ecui6WT6X+gTi07yXrgw0cEdg/rqCuJSe79Ek ok7HeNvqP2ly9zSxeoG3ZTRAbIiDzjfQR2jx8m3TpguTjnuQxLNvbT46PQ86lkmUNozRJ wikrMLI4gY6brcHN4cFiTSRUdwj3cPuR+G/AwySOpfYPBmPHEvXX1ItvQF8dnDILymw== 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=Q8Xn0PIq; arc=none smtp.remote-ip=209.85.210.47 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (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 D001E606A322 for ; Sat, 5 Dec 2026 23:11:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D001E606A322 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=Q8Xn0PIq Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-8253bc5a613so1480754a34.0 for ; Sat, 05 Dec 2026 15:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.dk; s=google; t=1796512276; x=1797117076; 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=DmiAVdiLRdqwGzsP7E52+pX1E9Sri7M3/TYLQ2RxGHE=; b=Q8Xn0PIq65tT8ox93jI1oNCE5jGE7S2WtTNCiPhdOvEgq0D0LDKQtFbHubbPezAW5H zSfkbe3rm0dIxb4FOKDIyKVFhAoikIO0+41vtY629qVK7FfLrt5SQrQgEQA82E2gqq0M 0X2eT4WSmCA2O3z+bfOaY/3vbgX9TLRju+7wF6KmKVHwq4oZ+IfBpjWwy8bgoygvPEev j9vRjB2paftYnDEhkwlNch78Ct89k+b8cV57InzbTH826U2wZNeXYGtlzp1XVD9k3gKJ jiV7rluc2naOkj2x7wyRfx0YoFRXIECXzfB262U3ved7ejcHB4gw/kDa8znT2U3rayex 8SbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512276; x=1797117076; 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=DmiAVdiLRdqwGzsP7E52+pX1E9Sri7M3/TYLQ2RxGHE=; b=koUfAS4IWijC8Ag+Cs/kbKSTsbi32f4qZzMXF1YZ6wZEH1m6/SevbxYw0l+zDaKbFP pxo1waf1QKpVy+2RD3KMQC1uQFRF0q1Nl+Gmj65k39p663KmhP1uLmh+o5gse8NQAgzb As3/vGz+Mita0XFRogwmlyfzeI3mu1iYWJ4EMiVA+pMVOAg2NsLgA46lJtrv1WYxmT9J 2IKMN94Ta1dufhGhVwf6BDp6VmOEkMmUQu40DPJouP8doBjYUvyoUXLl+vBdygd8j/Xc sQr9FwoQ20pot1KYt8/h5aoSfXuzglnZyhIw1byOmKFb1/FYmGIkpW/hoSXbT7xeq3RD yETw== X-Gm-Message-State: APuU4Z9/42yAfzE8AJdiZV9KOM6MZePcgMQPyHspgB7uWM0ycQP7Ccxv Oi6KmsgyoP69v5vRiwbOriFh4ZIxOQ5TIjmk37GbI+uGJMonw5V4ifqyRdfb7AnXrbpBaCV39ku Jrm309Kw= X-Gm-Gg: AZFdTZcUFaP1U+pfx92m7zO1+FDnr0KMI18MwuDuowlUoDXfep/qfF3MlAsH2MpvGyt QxhtJ3jEABgOf7Y7QsSKLSSmaAJ0JBFNiLnP8+sVy1HYZEC8UCffcohtp29R06OlDTFJSqvj+ZM Xtdj75xvLFQU9Lj/nOYmeKu/+j0xAm0/9FW/vWrTrFMQQhwNs/qrdyLYkgaq6AGTyEF8FNULxrl cXUlaa3MRmFBVq1PfNpwZ23y95qGtLQN/kdWZ1CkNXFMEvkX6WjlwRdnPsLtIJ1EYBlTG/Aidgo RO1EwVcThAGEoAaHUv4yvUcyLU8MwBqnoTCjaCzdmpcgpfEaEG0euyWzTN79F7fakZAXBsjT3Mq 3+xxpB24aJcIv+99KlGsWiu0914kCayk4Corfmjb8EsId9r02VRWGY2kfbdBtQo8gPXrQT7S1Mu 1jKXXqKRtaEq9fOVxAoisMKIRfugHqgZMeqRaWW5Cv20rTB+3uLE/64sXyLixroyemKfWx0/bbn wtgkkeEgG4ue7SqeuXCs5ceUcBovgmvwWD/VSlfTu4nQ6g8OqYeoC+gXYrsCxR4jaxSqBDgaSYm zqV5AUUPxNykywR4eKvbYnxzRYDRxNl+gXgZ3GO7H+OU5q23AN9xiw1Ds9Gy3ew5fuRwtWcjFXl p0P4JSTOtHdBfvleCu8/2XTjW6FqR5hz+TZVN X-Received: by 2002:a05:6808:13d6:b0:574:93c0:5ae7 with SMTP id 5614622812f47-57f207524abmr5726568b6e.12.1796512275793; Sat, 05 Dec 2026 15:11:15 -0800 (PST) Received: from r7625 ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-57f1f65febbsm4163964b6e.6.2026.12.05.15.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 15:11:15 -0800 (PST) From: Jens Axboe To: stable@vger.kernel.org Cc: io-uring@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH 6.12.y 03/15] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Date: Sat, 5 Dec 2026 23:10:55 +0000 Message-ID: <20261205231107.4023506-4-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: 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 9d6b7c433eea..22c0da122827 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -403,6 +403,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