lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <5ec837a5-4e54-b5a2-fd53-a6d7845fb5d7@huawei.com>
Date:   Thu, 25 May 2023 22:12:11 +0800
From:   zhongjinghua <zhongjinghua@...wei.com>
To:     Christoph Hellwig <hch@...radead.org>,
        Zhong Jinghua <zhongjinghua@...weicloud.com>
CC:     <axboe@...nel.dk>, <linux-block@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>, <yi.zhang@...wei.com>,
        <yukuai3@...wei.com>, <chengzhihao1@...wei.com>,
        <yangerkun@...wei.com>
Subject: Re: [PATCH -next] block: Fix the partition start may overflow in
 add_partition()


在 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?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ