From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379618; b=BAIZmeTPNVJjVTEdTlrYC+YHDgkMT4uqPV5Cgmb1ngyaY4rcHDo8tabJtuJldljPVw96 nBfc6mMfQnk1fUQNfbWj9uugyV1GG2bFdf6VpkR91J+INPGmyB6c2hTsBhoJ0klUtHneN PhGbKUl8qK3DT1/5QY1pZwY+1okt/1idnbNOdNYtjn73QREASpH3uO4wo/Rd7jXKA9xWE cU812zpkPdw19HntgayDFI50X0f7NccrpQHNhdmJMuWAECGpiksJd29BH3qJAPQH/ssWy Os1DJxjD667KP1/IaWVVJ1zxsK4V3oGFpW8NOeMjeOeeM0ScR3RabsVAiZvzVHqwUDQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379618; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=UOK9rSz8Z925B7l1stGTZEcZ4oPxekYi6RO+lk3QeHI=; b=l2i54ytZg0hDmxlseajr8sYMEp9CsUdzKJNJ1guC/zYqEGyo5Jlbg15V9uK5V7agyPP8 wWftXyOFciRSbfGsByfmUvfM7Dfd5/gkizt8KSBcZxjJq1mTWvksNSO5ZRf/PtwSrxoB7 TZardjMvQGvK7VjJyeXnZ5v4B6hgLBMmvAlU/dwDElmzA1zKZK+Z5yuF7tpnfp7H8ZhH4 RrCH+7MA2xeYxeFFUX4O26ej0qh7HUkB6XQ1AKOQRO9ovLFsfNlrCw3CaiEpf+f5bDYUc 5Zfl4gDmQ4lIf2Ahp9qL2cFwp1aWccsvElFFTfj3YxWDaZ0vHj15lk4zO3bC8gwLjRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=l6kYvjrD; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB923606A32C; Fri, 4 Dec 2026 10:20:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=l6kYvjrD Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67E1C1F00897; Fri, 4 Dec 2026 10:20:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379617; bh=UOK9rSz8Z925B7l1stGTZEcZ4oPxekYi6RO+lk3QeHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=l6kYvjrDh0LWd5wHl+tBQJcsLiEeyiINvtIs7plUoAaYx96avuXJCPqrMH7RWVta5 2QqswWd5JwF17zlIeV7VnkucV3S765q+y7qcvoEuMbbUGpQZZGf7Jlw+nYKx51BNzk 1v8FqAhg3Wp743R7adT91nxfQ6y63MknbOB0mlQU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Cheng Yongkang , Jens Axboe , Sasha Levin Subject: [PATCH 6.1 0021/1059] io_uring/rsrc: keep the old file when a file update fails Date: Fri, 4 Dec 2026 18:52:32 +0900 Message-ID: <20261204100644.583128155@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cheng Yongkang Commit e5a346e4309d720c47fe8331a00068608fad47dd upstream. __io_sqe_files_update() resets the slot before it calls fget() on the new fd. If fget() fails, the fd is an io_uring file, or the node allocation fails, the update stops and reports that entry as not done, but the old file has already been removed. Later requests that use the slot fail with -EBADF, and if the old file was registered with a tag, its tag CQE is posted as if it had been removed on purpose. Reset the slot only after the new file has been checked and its node allocated, as io_install_fixed_file() does. Removal with fd == -1 still resets the slot right away. Fixes: c3a31e605620 ("io_uring: add support for IORING_REGISTER_FILES_UPDATE") Cc: stable@vger.kernel.org Signed-off-by: Cheng Yongkang Link: https://patch.msgid.link/20261116044531.281978-1-teel4res@gmail.com Signed-off-by: Jens Axboe [axboe: 6.1 has no rsrc nodes for files, the old file is queued for removal with io_queue_rsrc_removal(), which can fail. Get and check the new file first, and only remove the old one once that has succeeded] Signed-off-by: Sasha Levin --- io_uring/rsrc.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index eb91f5b289244..485e6571172c3 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -438,7 +438,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, __s32 __user *fds = u64_to_user_ptr(up->data); struct io_rsrc_data *data = ctx->file_data; struct io_fixed_file *file_slot; - struct file *file; int fd, i, err = 0; unsigned int done; bool needs_switch = false; @@ -449,6 +448,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, return -EINVAL; for (done = 0; done < nr_args; done++) { + struct file *file = NULL; u64 tag = 0; if ((tags && copy_from_user(&tag, &tags[done], sizeof(tag))) || @@ -466,15 +466,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, i = array_index_nospec(up->offset + done, ctx->nr_user_files); file_slot = io_fixed_file_slot(&ctx->file_table, i); - if (file_slot->file_ptr) { - file = (struct file *)(file_slot->file_ptr & FFS_MASK); - err = io_queue_rsrc_removal(data, i, ctx->rsrc_node, file); - if (err) - break; - file_slot->file_ptr = 0; - io_file_bitmap_clear(&ctx->file_table, i); - needs_switch = true; - } if (fd != -1) { file = fget(fd); if (!file) { @@ -494,6 +485,21 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, err = -EBADF; break; } + } + if (file_slot->file_ptr) { + struct file *old = (struct file *)(file_slot->file_ptr & FFS_MASK); + + err = io_queue_rsrc_removal(data, i, ctx->rsrc_node, old); + if (err) { + if (file) + fput(file); + break; + } + file_slot->file_ptr = 0; + io_file_bitmap_clear(&ctx->file_table, i); + needs_switch = true; + } + if (file) { *io_get_tag_slot(data, i) = tag; io_fixed_file_set(file_slot, file); io_file_bitmap_set(&ctx->file_table, i); -- 2.53.0