mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: zhongjinghua <zhongjinghua@huaweicloud.com>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	axboe@kernel.dk
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	zhongjinghua@huawei.com, yi.zhang@huawei.com,
	"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] block: Fix minor range check in device_add_disk()
Date: Mon, 30 Oct 2023 17:26:51 +0800	[thread overview]
Message-ID: <df52b8a2-dff1-3973-b2bf-ca915c3f44d3@huaweicloud.com> (raw)
In-Reply-To: <26bafe93-345d-2696-8ee7-7d1baa0e7eb7@huaweicloud.com>

Hi,

在 2023/10/26 16:52, zhongjinghua 写道:
> 
> 在 2023/10/25 18:06, Tetsuo Handa 写道:
>> On 2023/10/25 17:46, Zhong Jinghua wrote:
>>> Checks added in patch:
>>> commit e338924bd05d ("block: check minor range in device_add_disk()")
>>> ignore the problem of first_minore < 0 and disk->minors < 0.
>> What is the problem of first_minor < 0 or disk->minors < 0 ?
>> Are negative values legal/illegal ?
> 
> These two values are used as the secondary device number and the maximum 
> number of partitions, which is illegal if negative. Then first_minore 
> and disk->minors are signed numbers, and the sum may be less than 
> MINORMASK to bypass the check.

Let me complement it, first_minor and minors can be set by driver, and
driver allow set them throuhh ioctl/sysfs from user parameters, for
example:

If user pass in -1, and each disk support 8 partitions, driver will
usually set:

disk->first_minor = -1 * 8 = -8;
disk->minors = 8;

Then first_minor + minors = 0, then the following condition can't detect
this case:

if (disk->first_minor + disk->minors > MINORMASK + 1)

By the way, we never limit how first_minor and minors is set by driver,
and it's illegal if driver set first_minor = -4, and minors = 8.

Thanks,
Kuai

> 
> .
> 


  reply	other threads:[~2023-10-30  9:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25  8:46 Zhong Jinghua
2023-10-25 10:06 ` Tetsuo Handa
2023-10-26  8:52   ` zhongjinghua
2023-10-30  9:26     ` Yu Kuai [this message]
2023-10-30  9:32       ` zhongjinghua

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=df52b8a2-dff1-3973-b2bf-ca915c3f44d3@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    --cc=zhongjinghua@huawei.com \
    --cc=zhongjinghua@huaweicloud.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®