Linux-Fsdevel Archive on lore.kernel.org
 help / color / Atom feed
From: Palash Oswal <hello@oswalpalash.com>
To: Jens Axboe <axboe@kernel.dk>,
	Pavel Begunkov <asml.silence@gmail.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Palash Oswal <hello@oswalpalash.com>
Subject: [PATCH] io_uring: check ctx->sq_data before io_sq_offload_start
Date: Mon, 19 Apr 2021 18:06:31 +0530
Message-ID: <20210419123630.62212-1-hello@oswalpalash.com> (raw)
In-Reply-To: https://lore.kernel.org/io-uring/d346085f-8b9b-d620-1e0c-aa78fee8db13@gmail.com

syzkaller identified KASAN: null-ptr-deref Read in io_uring_create
bug on the stable 5.11-y tree.

BUG: KASAN: null-ptr-deref in io_sq_offload_start fs/io_uring.c:8254 [inline]
BUG: KASAN: null-ptr-deref in io_disable_sqo_submit fs/io_uring.c:8999 [inline]
BUG: KASAN: null-ptr-deref in io_uring_create+0x1275/0x22f0 fs/io_uring.c:9824
Read of size 8 at addr 0000000000000068 by task syz-executor.0/4350

A simple reproducer for this bug is:

int main(void)
{
  syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
  intptr_t res = 0;
  pid_t parent = getpid();
  *(uint32_t*)0x20000084 = 0;
  *(uint32_t*)0x20000088 = 0x42;
  *(uint32_t*)0x2000008c = 0;
  *(uint32_t*)0x20000090 = 0;
  *(uint32_t*)0x20000098 = -1;
  *(uint32_t*)0x2000009c = 0;
  *(uint32_t*)0x200000a0 = 0;
  *(uint32_t*)0x200000a4 = 0;
  if (fork() == 0) {
    kill(parent,SIGKILL);
    exit(0);
  }
  res = syscall(__NR_io_uring_setup, 0x7994, 0x20000080ul);
  return 0;
}

Due to the SIGKILL sent to the process before io_uring_setup
completes, ctx->sq_data is NULL. Therefore, io_sq_offload_start
does a null pointer dereferenced read. More details on this bug
are in [1]. Discussion for this patch happened in [2].

[1] https://oswalpalash.com/exploring-null-ptr-deref-io-uring-submit
[2] https://lore.kernel.org/io-uring/a08121be-f481-e9f8-b28d-3eb5d4f
a5b76@gmail.com/

Signed-off-by: Palash Oswal <hello@oswalpalash.com>
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 95b4a89dad4e..82a89ff315a4 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -8995,7 +8995,7 @@ static void io_disable_sqo_submit(struct io_ring_ctx *ctx)
 {
 	mutex_lock(&ctx->uring_lock);
 	ctx->sqo_dead = 1;
-	if (ctx->flags & IORING_SETUP_R_DISABLED)
+	if (ctx->flags & IORING_SETUP_R_DISABLED && ctx->sq_data)
 		io_sq_offload_start(ctx);
 	mutex_unlock(&ctx->uring_lock);
 

base-commit: 2aa8861eab092599ad566c5b20d7452d9ec0ca8e
-- 
2.27.0


             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 12:36 Palash Oswal [this message]
2021-04-19 17:56 ` Jens Axboe

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=20210419123630.62212-1-hello@oswalpalash.com \
    --to=hello@oswalpalash.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

Linux-Fsdevel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-fsdevel/0 linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ https://lore.kernel.org/linux-fsdevel \
		linux-fsdevel@vger.kernel.org
	public-inbox-index linux-fsdevel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fsdevel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git