Skip to content

Commit f15885c

Browse files
author
Ming Lei
committed
block: fix integer overflow in BLKSECDISCARD
CVE: CVE-2024-49994 JIRA: https://issues.redhat.com/browse/RHEL-64512 commit 697ba0b Author: Alexey Dobriyan <adobriyan@gmail.com> Date: Tue Sep 3 22:48:19 2024 +0300 block: fix integer overflow in BLKSECDISCARD I independently rediscovered commit 22d24a5 block: fix overflow in blk_ioctl_discard() but for secure erase. Same problem: uint64_t r[2] = {512, 18446744073709551104ULL}; ioctl(fd, BLKSECDISCARD, r); will enter near infinite loop inside blkdev_issue_secure_erase(): a.out: attempt to access beyond end of device loop0: rw=5, sector=3399043073, nr_sectors = 1024 limit=2048 bio_check_eod: 3286214 callbacks suppressed Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Link: https://lore.kernel.org/r/9e64057f-650a-46d1-b9f7-34af391536ef@p183 Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 7653375 commit f15885c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

block/ioctl.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
127127
return -EINVAL;
128128

129129
filemap_invalidate_lock(inode->i_mapping);
130-
err = truncate_bdev_range(bdev, mode, start, start + len - 1);
130+
err = truncate_bdev_range(bdev, mode, start, end - 1);
131131
if (err)
132132
goto fail;
133133

@@ -164,7 +164,7 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
164164
static int blk_ioctl_secure_erase(struct block_device *bdev, blk_mode_t mode,
165165
void __user *argp)
166166
{
167-
uint64_t start, len;
167+
uint64_t start, len, end;
168168
uint64_t range[2];
169169
int err;
170170

@@ -179,11 +179,12 @@ static int blk_ioctl_secure_erase(struct block_device *bdev, blk_mode_t mode,
179179
len = range[1];
180180
if ((start & 511) || (len & 511))
181181
return -EINVAL;
182-
if (start + len > bdev_nr_bytes(bdev))
182+
if (check_add_overflow(start, len, &end) ||
183+
end > bdev_nr_bytes(bdev))
183184
return -EINVAL;
184185

185186
filemap_invalidate_lock(bdev->bd_inode->i_mapping);
186-
err = truncate_bdev_range(bdev, mode, start, start + len - 1);
187+
err = truncate_bdev_range(bdev, mode, start, end - 1);
187188
if (!err)
188189
err = blkdev_issue_secure_erase(bdev, start >> 9, len >> 9,
189190
GFP_KERNEL);

0 commit comments

Comments
 (0)