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=1796379502; b=MAgU6BBVnjCAwmQ0BOeiBLmIFAX0LY7lsSSpdnZWHuSpr8m9SYbKYNWQljnqBAN8Xik9 Z/2RzOL/dKop5zjBV/OHNlYZtmjuG1F5jyRmlqm11i3UmYv3iPWm/GLKSLuekaMC059dy Y7YQH5W631MSvQQ+yzcuqyEzji5yI0BlWWcD58QQVhH1OhRurAElzhTQFrUehCYC44iXL JV+8i/SlKWCgJ74z9t20Jt4WbfJT0kAtVn106SMOQ1OILmYXNrXAr4ETxzGu+xFTwP9xw R4p+la/dLOigaSbo89p1hKovGG87qT9UUs+WyMw8gfz56U8eQVlb2ly0UxMfqFt6lNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379502; 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=sfCsYY40d3V/PYcjycntHZpV0bRFOk4N5L7YVXqV08c=; b=Vh75n9fIKe/TTqIZ4+rQ808hhnzqQG+KRrNzX7G4BhEMgt7alqU9LZpFJ2jCVPDS9P4F XPH/BC3/BXu/7AWOo+fYaXlYfCicwadvN1Ygbln4EBMS63j9sSWfQB2fjjfcAL54i2pQK k81bOZaZp0RhH9+ejAnzd5OJIzLF22VSXLjo0FYmgz+iUYD5qzrMgd7StoAUzeu3Y/PZZ RhUpmzYS3bhz1GZBvvvM+5+apWFxPkY/Ncj2cGgolUhfOUPqQtCdQ/sYiP5+MDuKATVqT N+B59Px3o+hIvQiJZ3jWAIYLQoPUbvDcE+YRohQbvtmsJiW7JV7W4irT2oRssv1cQ2w== 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=KASiN3Xf; 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 3E959606A32C; Fri, 4 Dec 2026 10:18:22 +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=KASiN3Xf Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE3B01F000CE; Fri, 4 Dec 2026 10:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379502; bh=sfCsYY40d3V/PYcjycntHZpV0bRFOk4N5L7YVXqV08c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KASiN3XfL0JjZa31RC9lsIG+h6Kd5yVdi2uq+XEJ5Fu4bn2byZhsyGdq22M7ptvv8 7T+89GctQDvR01iPp/VA5SY+hYcT13cudhCbpjW5UhwwlqBomr2w/IPbW+eQ9PlwK6 TKYGWCP4oOxyrtyp/pgCBE3FYlUzo8MPfiA4uNms= 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.6 0020/1167] io_uring/rsrc: keep the old file when a file update fails Date: Fri, 4 Dec 2026 18:50:47 +0900 Message-ID: <20261204100702.571584215@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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.6 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 | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index ba1dedaaa7c42..0cc498a0673dd 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -369,6 +369,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))) || @@ -386,17 +387,8 @@ 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) { - err = io_queue_rsrc_removal(data, i, - io_slot_file(file_slot)); - if (err) - break; - file_slot->file_ptr = 0; - io_file_bitmap_clear(&ctx->file_table, i); - } if (fd != -1) { - struct file *file = fget(fd); - + file = fget(fd); if (!file) { err = -EBADF; break; @@ -409,6 +401,19 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, err = -EBADF; break; } + } + if (file_slot->file_ptr) { + err = io_queue_rsrc_removal(data, i, + io_slot_file(file_slot)); + if (err) { + if (file) + fput(file); + break; + } + file_slot->file_ptr = 0; + io_file_bitmap_clear(&ctx->file_table, i); + } + 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