Skip to content

Commit 5fabcb4

Browse files
committed
genhd: check for int overflow in disk_expand_part_tbl()
We can get here from blkdev_ioctl() -> blkpg_ioctl() -> add_partition() with a user passed in partno value. If we pass in 0x7fffffff, the new target in disk_expand_part_tbl() overflows the 'int' and we access beyond the end of ptbl->part[] and even write to it when we do the rcu_assign_pointer() to assign the new partition. Reported-by: David Ramos <[email protected]> Cc: [email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 7c7f2f2 commit 5fabcb4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

block/genhd.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,16 @@ int disk_expand_part_tbl(struct gendisk *disk, int partno)
10701070
struct disk_part_tbl *old_ptbl = disk->part_tbl;
10711071
struct disk_part_tbl *new_ptbl;
10721072
int len = old_ptbl ? old_ptbl->len : 0;
1073-
int target = partno + 1;
1073+
int i, target;
10741074
size_t size;
1075-
int i;
1075+
1076+
/*
1077+
* check for int overflow, since we can get here from blkpg_ioctl()
1078+
* with a user passed 'partno'.
1079+
*/
1080+
target = partno + 1;
1081+
if (target < 0)
1082+
return -EINVAL;
10761083

10771084
/* disk_max_parts() is zero during initialization, ignore if so */
10781085
if (disk_max_parts(disk) && target > disk_max_parts(disk))

0 commit comments

Comments
 (0)