From: Ming Lei <ming.lei@redhat.com>
To: Mauricio Faria de Oliveira <mfo@canonical.com>
Cc: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Mikulas Patocka <mpatocka@redhat.com>
Subject: Re: [PATCH] block: check for page size in queue_logical_block_size()
Date: Mon, 1 Jun 2020 15:34:40 +0800 [thread overview]
Message-ID: <20200601073440.GD1181806@T590> (raw)
In-Reply-To: <20200601005520.420719-1-mfo@canonical.com>
On Sun, May 31, 2020 at 09:55:20PM -0300, Mauricio Faria de Oliveira wrote:
> It's possible for a block driver to set logical block size to
> a value greater than page size incorrectly; e.g. bcache takes
> the value from the superblock, set by the user w/ make-bcache.
>
> This causes a BUG/NULL pointer dereference in the path:
>
> __blkdev_get()
> -> set_init_blocksize() // set i_blkbits based on ...
> -> bdev_logical_block_size()
> -> queue_logical_block_size() // ... this value
> -> bdev_disk_changed()
> ...
> -> blkdev_readpage()
> -> block_read_full_page()
> -> create_page_buffers() // size = 1 << i_blkbits
> -> create_empty_buffers() // give size/take pointer
> -> alloc_page_buffers() // return NULL
> .. BUG!
>
> Because alloc_page_buffers() is called with size > PAGE_SIZE,
> thus it initializes head = NULL, skips the loop, return head;
> then create_empty_buffers() gets (and uses) the NULL pointer.
>
> This has been around longer than commit ad6bf88a6c19 ("block:
> fix an integer overflow in logical block size"); however, it
> increased the range of values that can trigger the issue.
>
> Previously only 8k/16k/32k (on x86/4k page size) would do it,
> as greater values overflow unsigned short to zero, and queue_
> logical_block_size() would then use the default of 512.
>
> Now the range with unsigned int is much larger, and one user
> with an (incorrect) 512k value, which happened to be zero'ed
> previously and work fine, hits the issue -- the zero is gone,
> and queue_logical_block_size() does return 512k (> PAGE_SIZE)
There is only very limited such potential users(loop, virtio-blk,
xen-blkfront), so could you fix the user instead of working around
queue_logical_block_size()?
thanks,
Ming
next prev parent reply other threads:[~2020-06-01 7:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-01 0:55 [PATCH] block: check for page size in queue_logical_block_size() Mauricio Faria de Oliveira
2020-06-01 7:34 ` Ming Lei [this message]
2020-06-01 13:47 ` Mauricio Faria de Oliveira
2020-06-03 11:33 ` Mauricio Faria de Oliveira
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=20200601073440.GD1181806@T590 \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mfo@canonical.com \
--cc=mpatocka@redhat.com \
/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