From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: lixiaokeng <lixiaokeng@huawei.com>, <axboe@kernel.dk>,
<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: linfeilong <linfeilong@huawei.com>
Subject: Re: [PATCH] brd: fix integer overflow in brd_check_and_reset_par
Date: Thu, 1 Apr 2021 17:06:52 +0800 [thread overview]
Message-ID: <ce64c4a2-e90a-97f9-6334-74912dbcb958@huawei.com> (raw)
In-Reply-To: <99e9da32-9372-ada2-8197-26602fe242c8@huawei.com>
friendly ping.
On 2021/3/25 19:45, lixiaokeng wrote:
> The max_part may overflow. For example,
>
> modprobe brd rd_nr=3 rd_size=102400 max_part=1073741824(2^30)
>
> Expected result
> NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
> ram0 1:0 0 100M 0 disk
> ram1 1:256 0 100M 0 disk
> ram2 1:512 0 100M 0 disk
>
> Actual result
> NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
> ram0 259:0 0 100M 0 disk
> ram1 259:1 0 100M 0 disk
> ram2 259:2 0 100M 0 disk
>
> Fix it.
>
> Signed-off-by: Lixiaokeng <lixiaokeng@huawei.com>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> ---
> drivers/block/brd.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/block/brd.c b/drivers/block/brd.c
> index c43a6ab4b1f3..c91831cd5d2a 100644
> --- a/drivers/block/brd.c
> +++ b/drivers/block/brd.c
> @@ -457,21 +457,19 @@ static void brd_del_one(struct brd_device *brd)
>
> static inline void brd_check_and_reset_par(void)
> {
> - if (unlikely(!max_part))
> + if (unlikely(max_part <= 0))
> max_part = 1;
>
> /*
> * make sure 'max_part' can be divided exactly by (1U << MINORBITS),
> * otherwise, it is possiable to get same dev_t when adding partitions.
> */
> - if ((1U << MINORBITS) % max_part != 0)
> - max_part = 1UL << fls(max_part);
> -
> if (max_part > DISK_MAX_PARTS) {
> pr_info("brd: max_part can't be larger than %d, reset max_part = %d.\n",
> DISK_MAX_PARTS, DISK_MAX_PARTS);
> max_part = DISK_MAX_PARTS;
> - }
> + } else if ((1U << MINORBITS) % max_part != 0)
> + max_part = 1UL << fls(max_part);
> }
>
> static int __init brd_init(void)
prev parent reply other threads:[~2021-04-01 9:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 11:45 lixiaokeng
2021-04-01 9:06 ` Zhiqiang Liu [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=ce64c4a2-e90a-97f9-6334-74912dbcb958@huawei.com \
--to=liuzhiqiang26@huawei.com \
--cc=axboe@kernel.dk \
--cc=linfeilong@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixiaokeng@huawei.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
all inboxes | Powered by JetHome®