public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Hao Xu <hao.xu@linux.dev>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>, Pavel Begunkov <asml.silence@gmail.com>
Subject: [PATCH 5.19 3/6] io_uring: openclose: fix bug of unexpected return value in IORING_CLOSE_FD_AND_FILE_SLOT mode
Date: Sat, 11 Jun 2022 20:22:21 +0800	[thread overview]
Message-ID: <20220611122224.941800-3-hao.xu@linux.dev> (raw)
In-Reply-To: <20220611122224.941800-1-hao.xu@linux.dev>

From: Hao Xu <howeyxu@tencent.com>

In IORING_CLOSE_FD_AND_FILE_SLOT mode, if we successfully close fixed
file but fails in close->fd >= fdt->max_fds check, cqe-res = 0 is
returned, which should be -EBADF.

Fixes: a7c41b4687f5 ("io_uring: let IORING_OP_FILES_UPDATE support choosing fixed file slots")
Signed-off-by: Hao Xu <howeyxu@tencent.com>
---
 io_uring/openclose.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/io_uring/openclose.c b/io_uring/openclose.c
index b35bf5f66dd9..4eb1f23e028a 100644
--- a/io_uring/openclose.c
+++ b/io_uring/openclose.c
@@ -248,7 +248,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags)
 	struct io_close *close = io_kiocb_to_cmd(req);
 	struct fdtable *fdt;
 	struct file *file;
-	int ret = -EBADF;
+	int ret;
 
 	if (close->file_slot) {
 		ret = io_close_fixed(req, issue_flags);
@@ -256,6 +256,7 @@ int io_close(struct io_kiocb *req, unsigned int issue_flags)
 			goto err;
 	}
 
+	ret = -EBADF;
 	spin_lock(&files->file_lock);
 	fdt = files_fdtable(files);
 	if (close->fd >= fdt->max_fds) {
-- 
2.25.1


  parent reply	other threads:[~2022-06-11 12:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-11 12:22 [PATCH for-5.20 1/6] io_uring: poll: remove unnecessary req->ref set Hao Xu
2022-06-11 12:22 ` [PATCH 5.19 2/6] io_uring: openclose: fix bug of closing wrong fixed file Hao Xu
2022-06-11 13:13   ` Pavel Begunkov
2022-06-12 17:47   ` Pavel Begunkov
2022-06-13  3:45     ` Hao Xu
2022-06-11 12:22 ` Hao Xu [this message]
2022-06-11 12:22 ` [PATCH for-5.20 4/6] io_uring: openclose: support separate return value for IORING_CLOSE_FD_AND_FILE_SLOT Hao Xu
2022-06-11 12:22 ` [PATCH for-5.20 5/6] io_uring: remove duplicate kbuf release Hao Xu
2022-06-11 12:29 ` [PATCH 5.19 6/6] io_uring: kbuf: fix bug of not consuming ring buffer in partial io case Hao Xu
2022-06-12 17:44 ` [PATCH for-5.20 1/6] io_uring: poll: remove unnecessary req->ref set Pavel Begunkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220611122224.941800-3-hao.xu@linux.dev \
    --to=hao.xu@linux.dev \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox