From: zhongjinghua <zhongjinghua@huawei.com>
To: Christoph Hellwig <hch@infradead.org>,
Zhong Jinghua <zhongjinghua@huaweicloud.com>
Cc: <axboe@kernel.dk>, <linux-block@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <yi.zhang@huawei.com>,
<yukuai3@huawei.com>, <chengzhihao1@huawei.com>,
<yangerkun@huawei.com>
Subject: Re: [PATCH -next] block: Fix the partition start may overflow in add_partition()
Date: Thu, 25 May 2023 22:12:11 +0800 [thread overview]
Message-ID: <5ec837a5-4e54-b5a2-fd53-a6d7845fb5d7@huawei.com> (raw)
In-Reply-To: <ZG8igEyXrFa4j/gf@infradead.org>
在 2023/5/25 16:55, Christoph Hellwig 写道:
> On Mon, May 22, 2023 at 03:06:15PM +0800, Zhong Jinghua wrote:
>> + if (p.start < 0 || p.length <= 0 || p.start + p.length < 0)
>> + return -EINVAL;
>> +
>> start = p.start >> SECTOR_SHIFT;
>> length = p.length >> SECTOR_SHIFT;
>>
>> + /* length may be equal to 0 after right shift */
>> + if (!length || start + length > get_capacity(bdev->bd_disk))
>> + return -EINVAL;
> While we're at it, shouldn't these be switched to use
> check_add_overflow?
However, using check_add_overflow requires the introduction of an
additional local variable for the third parameter, which does not make
much difference to the current check. Is it worth it?
e.g:
diff --git a/block/ioctl.c b/block/ioctl.c
index 3223ea862523..9a40e8f864cb 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -18,7 +18,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,
{
struct gendisk *disk = bdev->bd_disk;
struct blkpg_partition p;
- long long start, length;
+ long long start, length, tmp_check;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
@@ -33,7 +33,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,
if (op == BLKPG_DEL_PARTITION)
return bdev_del_partition(disk, p.pno);
- if (p.start < 0 || p.length <= 0 || p.start + p.length < 0)
+ if (p.start < 0 || p.length <= 0 || check_add_overflow(p.start,
p.length, &tmp_check))
return -EINVAL;
start = p.start >> SECTOR_SHIFT;
Or do you have a better idea?
prev parent reply other threads:[~2023-05-25 14:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-22 7:06 Zhong Jinghua
2023-05-25 2:14 ` Yu Kuai
2023-05-25 2:27 ` Yu Kuai
2023-05-25 8:55 ` Christoph Hellwig
2023-05-25 13:20 ` zhongjinghua
2023-05-25 14:12 ` zhongjinghua [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=5ec837a5-4e54-b5a2-fd53-a6d7845fb5d7@huawei.com \
--to=zhongjinghua@huawei.com \
--cc=axboe@kernel.dk \
--cc=chengzhihao1@huawei.com \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai3@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®