public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: syzbot <[email protected]>,
	[email protected], [email protected],
	[email protected], [email protected],
	[email protected],
	Matthew Wilcox <[email protected]>
Cc: [email protected]
Subject: Re: KASAN: use-after-free Read in __io_uring_files_cancel
Date: Fri, 9 Oct 2020 14:10:49 +0300	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

On 09/10/2020 11:02, syzbot wrote:
> Hello,
> 
> syzbot found the following issue on:
> 
> HEAD commit:    e4fb79c7 Add linux-next specific files for 20201008
> git tree:       linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=1592ee1b900000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=568d41fe4341ed0f
> dashboard link: https://syzkaller.appspot.com/bug?extid=77efce558b2b9e6b6405
> compiler:       gcc (GCC) 10.1.0-syz 20200507
> 
> Unfortunately, I don't have any reproducer for this issue yet.
> 
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: [email protected]
> 
> ==================================================================
> BUG: KASAN: use-after-free in xas_next_entry include/linux/xarray.h:1630 [inline]
> BUG: KASAN: use-after-free in __io_uring_files_cancel+0x417/0x440 fs/io_uring.c:8681
> Read of size 1 at addr ffff888033631880 by task syz-executor.1/8477
> 
> CPU: 1 PID: 8477 Comm: syz-executor.1 Not tainted 5.9.0-rc8-next-20201008-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
>  __dump_stack lib/dump_stack.c:77 [inline]
>  dump_stack+0x198/0x1fb lib/dump_stack.c:118
>  print_address_description.constprop.0.cold+0xae/0x497 mm/kasan/report.c:385
>  __kasan_report mm/kasan/report.c:545 [inline]
>  kasan_report.cold+0x1f/0x37 mm/kasan/report.c:562
>  xas_next_entry include/linux/xarray.h:1630 [inline]
>  __io_uring_files_cancel+0x417/0x440 fs/io_uring.c:8681
>  io_uring_files_cancel include/linux/io_uring.h:35 [inline]
>  exit_files+0xe4/0x170 fs/file.c:456
>  do_exit+0xae9/0x2930 kernel/exit.c:801
>  do_group_exit+0x125/0x310 kernel/exit.c:903
>  get_signal+0x428/0x1f00 kernel/signal.c:2757
>  arch_do_signal+0x82/0x2470 arch/x86/kernel/signal.c:811
>  exit_to_user_mode_loop kernel/entry/common.c:161 [inline]
>  exit_to_user_mode_prepare+0x194/0x1f0 kernel/entry/common.c:192
>  syscall_exit_to_user_mode+0x7a/0x2c0 kernel/entry/common.c:267
>  entry_SYSCALL_64_after_hwframe+0x44/0xa9

It seems this fails on "node->shift" in xas_next_entry(), that would
mean that the node itself was freed while we're iterating on it.

__io_uring_files_cancel() iterates with xas_next_entry() and creates
XA_STATE once by hand, but it also removes entries in the loop with
io_uring_del_task_file() -> xas_store(&xas, NULL); without updating
the iterating XA_STATE. Could it be the problem? See a diff below

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 824ed4e01562..356313c7aec2 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8617,10 +8617,9 @@ static int io_uring_add_task_file(struct file *file)
 /*
  * Remove this io_uring_file -> task mapping.
  */
-static void io_uring_del_task_file(struct file *file)
+static void io_uring_del_task_file(struct file *file, struct xa_state *xas)
 {
 	struct io_uring_task *tctx = current->io_uring;
-	XA_STATE(xas, &tctx->xa, (unsigned long) file);
 
 	if (tctx->last == file)
 		tctx->last = NULL;
@@ -8643,7 +8642,7 @@ static void __io_uring_attempt_task_drop(struct file *file)
 	rcu_read_unlock();
 
 	if (old == file)
-		io_uring_del_task_file(file);
+		io_uring_del_task_file(file, &xas);
 }
 
 /*
@@ -8687,7 +8686,7 @@ void __io_uring_files_cancel(struct files_struct *files)
 
 		io_uring_cancel_task_requests(ctx, files);
 		if (files)
-			io_uring_del_task_file(file);
+			io_uring_del_task_file(file, &xas);
 	} while (1);
 }

-- 
Pavel Begunkov

  reply	other threads:[~2020-10-09 11:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09  8:02 KASAN: use-after-free Read in __io_uring_files_cancel syzbot
2020-10-09 11:10 ` Pavel Begunkov [this message]
2020-10-09 12:12   ` Matthew Wilcox
2020-10-09 12:28     ` Pavel Begunkov
2020-10-09 12:35       ` Matthew Wilcox
2020-10-09 12:48         ` 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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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