linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Ming Lei <ming.lei@redhat.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	syzbot+8fede7e30c7cee0de139@syzkaller.appspotmail.com
Subject: Re: [PATCH V2] block: not create too many partitions
Date: Sat, 27 Mar 2021 08:07:38 -0700	[thread overview]
Message-ID: <bd40894d-cad5-c4be-0502-87a9567ba6cf@acm.org> (raw)
In-Reply-To: <20210327071309.553557-1-ming.lei@redhat.com>

On 3/27/21 12:13 AM, Ming Lei wrote:
> Commit a33df75c6328 ("block: use an xarray for disk->part_tbl") drops
> check on max supported partitions number, and allows partition with
> bigger partition number to be added. However, ->bd_partno is defined
> as u8, so partition index of xarray table may not match with ->bd_partno.
> Then delete_partition() may delete one unmatched partition, and caused
> use-after-free.
> 
> Cc: Bart Van Assche <bvanassche@acm.org>
> Reported-by: syzbot+8fede7e30c7cee0de139@syzkaller.appspotmail.com
> Fixes: a33df75c6328 ("block: use an xarray for disk->part_tbl")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> V2:
> 	- don't check disk_max_parts() which is supposed to not zero
> 
>  block/partitions/core.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/block/partitions/core.c b/block/partitions/core.c
> index 1a7558917c47..46f055bc7ecb 100644
> --- a/block/partitions/core.c
> +++ b/block/partitions/core.c
> @@ -322,6 +322,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
>  	const char *dname;
>  	int err;
>  
> +	/*
> +	 * disk_max_parts() won't be zero, either GENHD_FL_EXT_DEVT is set
> +	 * or 'minors' is passed to alloc_disk().
> +	 */
> +	if (partno >= disk_max_parts(disk))
> +		return ERR_PTR(-EINVAL);
> +
>  	/*
>  	 * Partitions are not supported on zoned block devices that are used as
>  	 * such.
> 

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

Thanks!

Bart.

      parent reply	other threads:[~2021-03-27 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-27  7:13 [PATCH V2] block: not create too many partitions Ming Lei
2021-03-27 14:56 ` Jens Axboe
2021-03-27 15:07 ` Bart Van Assche [this message]

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=bd40894d-cad5-c4be-0502-87a9567ba6cf@acm.org \
    --to=bvanassche@acm.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=syzbot+8fede7e30c7cee0de139@syzkaller.appspotmail.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;
as well as URLs for NNTP newsgroup(s).