linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Matthew Wilcox <willy@infradead.org>,
	linux-kernel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH] io_uring: avoid page allocation warnings
Date: Tue, 30 Apr 2019 18:03:03 +0100	[thread overview]
Message-ID: <20190430170302.GD8314@lakrids.cambridge.arm.com> (raw)
In-Reply-To: <a1af3017-6572-e828-dc8a-a5c8458e6b5a@kernel.dk>

On Tue, Apr 30, 2019 at 10:21:03AM -0600, Jens Axboe wrote:
> On 4/30/19 8:59 AM, Mark Rutland wrote:
> > On Tue, Apr 30, 2019 at 07:18:10AM -0700, Matthew Wilcox wrote:
> >> On Tue, Apr 30, 2019 at 02:24:05PM +0100, Mark Rutland wrote:
> >>> In io_sqe_buffer_register() we allocate a number of arrays based on the
> >>> iov_len from the user-provided iov. While we limit iov_len to SZ_1G,
> >>> we can still attempt to allocate arrays exceeding MAX_ORDER.
> >>>
> >>> On a 64-bit system with 4KiB pages, for an iov where iov_base = 0x10 and
> >>> iov_len = SZ_1G, we'll calculate that nr_pages = 262145. When we try to
> >>> allocate a corresponding array of (16-byte) bio_vecs, requiring 4194320
> >>> bytes, which is greater than 4MiB. This results in SLUB warning that
> >>> we're trying to allocate greater than MAX_ORDER, and failing the
> >>> allocation.
> >>>
> >>> Avoid this by passing __GFP_NOWARN when allocating arrays for the
> >>> user-provided iov_len. We'll gracefully handle the failed allocation,
> >>> returning -ENOMEM to userspace.
> >>>
> >>> We should probably consider lowering the limit below SZ_1G, or reworking
> >>> the array allocations.
> >>
> >> I'd suggest that kvmalloc is probably our friend here ... we don't really
> >> want to return -ENOMEM to userspace for this case, I don't think.
> > 
> > Sure. I'll go verify that the uring code doesn't assume this memory is
> > physically contiguous.
> > 
> > I also guess we should be passing GFP_KERNEL_ACCOUNT rateh than a plain
> > GFP_KERNEL.
> 
> kvmalloc() is fine, the io_uring code doesn't care about the layout of
> the memory, it just uses it as an index.

I've just had a go at that, but when using kvmalloc() with or without
GFP_KERNEL_ACCOUNT I hit OOM and my system hangs within a few seconds with the
syzkaller prog below:

----
Syzkaller reproducer:
# {Threaded:false Collide:false Repeat:false RepeatTimes:0 Procs:1 Sandbox: Fault:false FaultCall:-1 FaultNth:0 EnableTun:false EnableNetDev:false EnableNetReset:false EnableCgroups:false EnableBinfmtMisc:false EnableCloseFds:false UseTmpDir:false HandleSegv:false Repro:false Trace:false}
r0 = io_uring_setup(0x378, &(0x7f00000000c0))
sendmsg$SEG6_CMD_SET_TUNSRC(0xffffffffffffffff, &(0x7f0000000240)={&(0x7f0000000000)={0x10, 0x0, 0x0, 0x40000000}, 0xc, 0x0, 0x1, 0x0, 0x0, 0x10}, 0x800)
io_uring_register$IORING_REGISTER_BUFFERS(r0, 0x0, &(0x7f0000000000), 0x1)
----

... I'm a bit worried that opens up a trivial DoS.

Thoughts?

Thanks,
Mark.

  reply	other threads:[~2019-04-30 17:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30 13:24 [PATCH] io_uring: avoid page allocation warnings Mark Rutland
2019-04-30 14:18 ` Matthew Wilcox
2019-04-30 14:59   ` Mark Rutland
2019-04-30 16:21     ` Jens Axboe
2019-04-30 17:03       ` Mark Rutland [this message]
2019-04-30 18:11         ` Jens Axboe
2019-05-01 10:30           ` Mark Rutland
2019-05-01 12:41             ` Jens Axboe
2019-05-01 15:09               ` Mark Rutland
2019-05-01 15:29                 ` Jens Axboe
2019-05-01 15:55                   ` Mark Rutland

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=20190430170302.GD8314@lakrids.cambridge.arm.com \
    --to=mark.rutland@arm.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).