All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring: disallow  modification of rsrc_data during quiesce
@ 2022-02-22 16:17 Dylan Yudaken
  2022-02-22 16:57 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Dylan Yudaken @ 2022-02-22 16:17 UTC (permalink / raw)
  To: Jens Axboe, Pavel Begunkov, io-uring
  Cc: kernel-team, Dylan Yudaken, syzbot+ca8bf833622a1662745b

io_rsrc_ref_quiesce will unlock the uring while it waits for references to
the io_rsrc_data to be killed.
There are other places to the data that might add references to data via
calls to io_rsrc_node_switch.
There is a race condition where this reference can be added after the
completion has been signalled. At this point the io_rsrc_ref_quiesce call
will wake up and relock the uring, assuming the data is unused and can be
freed - although it is actually being used.

To fix this check in io_rsrc_ref_quiesce if a resource has been revived.

Reported-by: syzbot+ca8bf833622a1662745b@syzkaller.appspotmail.com
Fixes: b36a2050040b ("io_uring: fix bug in slow unregistering of nodes")
Signed-off-by: Dylan Yudaken <dylany@fb.com>
---
 fs/io_uring.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 77b9c7e4793b..02086e8e0dec 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7924,7 +7924,15 @@ static __cold int io_rsrc_ref_quiesce(struct io_rsrc_data *data,
 		ret = wait_for_completion_interruptible(&data->done);
 		if (!ret) {
 			mutex_lock(&ctx->uring_lock);
-			break;
+			if (atomic_read(&data->refs) > 0) {
+				/*
+				 * it has been revived by another thread while
+				 * we were unlocked
+				 */
+				mutex_unlock(&ctx->uring_lock);
+			} else {
+				break;
+			}
 		}
 
 		atomic_inc(&data->refs);

base-commit: cfb92440ee71adcc2105b0890bb01ac3cddb8507
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] io_uring: disallow modification of rsrc_data during quiesce
  2022-02-22 16:17 [PATCH] io_uring: disallow modification of rsrc_data during quiesce Dylan Yudaken
@ 2022-02-22 16:57 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2022-02-22 16:57 UTC (permalink / raw)
  To: Dylan Yudaken, Pavel Begunkov, io-uring
  Cc: syzbot+ca8bf833622a1662745b, kernel-team

On Tue, 22 Feb 2022 08:17:51 -0800, Dylan Yudaken wrote:
> io_rsrc_ref_quiesce will unlock the uring while it waits for references to
> the io_rsrc_data to be killed.
> There are other places to the data that might add references to data via
> calls to io_rsrc_node_switch.
> There is a race condition where this reference can be added after the
> completion has been signalled. At this point the io_rsrc_ref_quiesce call
> will wake up and relock the uring, assuming the data is unused and can be
> freed - although it is actually being used.
> 
> [...]

Applied, thanks!

[1/1] io_uring: disallow modification of rsrc_data during quiesce
      commit: 80912cef18f16f8fe59d1fb9548d4364342be360

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-22 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 16:17 [PATCH] io_uring: disallow modification of rsrc_data during quiesce Dylan Yudaken
2022-02-22 16:57 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.