diff options
author | Tejun Heo <tj@kernel.org> | 2012-05-15 02:22:04 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-05-15 02:22:04 -0400 |
commit | 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 (patch) | |
tree | a9918d8c056adcd527b6cdf23ec9dc26e585efe9 | |
parent | 85fd0bc95bc76d129db0d0114c40665745bbba07 (diff) |
block: fix buffer overflow when printing partition UUIDs
6d1d8050b4bc8 "block, partition: add partition_meta_info to hd_struct"
added part_unpack_uuid() which assumes that the passed in buffer has
enough space for sprintfing "%pU" - 37 characters including '\0'.
Unfortunately, b5af921ec0233 "init: add support for root devices
specified by partition UUID" supplied 33 bytes buffer to the function
leading to the following panic with stackprotector enabled.
Kernel panic - not syncing: stack-protector: Kernel stack corrupted in: ffffffff81b14c7e
[<ffffffff815e226b>] panic+0xba/0x1c6
[<ffffffff81b14c7e>] ? printk_all_partitions+0x259/0x26xb
[<ffffffff810566bb>] __stack_chk_fail+0x1b/0x20
[<ffffffff81b15c7e>] printk_all_paritions+0x259/0x26xb
[<ffffffff81aedfe0>] mount_block_root+0x1bc/0x27f
[<ffffffff81aee0fa>] mount_root+0x57/0x5b
[<ffffffff81aee23b>] prepare_namespace+0x13d/0x176
[<ffffffff8107eec0>] ? release_tgcred.isra.4+0x330/0x30
[<ffffffff81aedd60>] kernel_init+0x155/0x15a
[<ffffffff81087b97>] ? schedule_tail+0x27/0xb0
[<ffffffff815f4d24>] kernel_thread_helper+0x5/0x10
[<ffffffff81aedc0b>] ? start_kernel+0x3c5/0x3c5
[<ffffffff815f4d20>] ? gs_change+0x13/0x13
Increase the buffer size, remove the dangerous part_unpack_uuid() and
use snprintf() directly from printk_all_partitions().
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Szymon Gruszczynski <sz.gruszczynski@googlemail.com>
Cc: Will Drewry <wad@chromium.org>
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | block/genhd.c | 10 | ||||
-rw-r--r-- | include/linux/genhd.h | 6 |
2 files changed, 6 insertions, 10 deletions
diff --git a/block/genhd.c b/block/genhd.c index df9816ede75b..9cf5583c90ff 100644 --- a/block/genhd.c +++ b/block/genhd.c | |||
@@ -743,7 +743,7 @@ void __init printk_all_partitions(void) | |||
743 | struct hd_struct *part; | 743 | struct hd_struct *part; |
744 | char name_buf[BDEVNAME_SIZE]; | 744 | char name_buf[BDEVNAME_SIZE]; |
745 | char devt_buf[BDEVT_SIZE]; | 745 | char devt_buf[BDEVT_SIZE]; |
746 | u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1]; | 746 | char uuid_buf[PARTITION_META_INFO_UUIDLTH * 2 + 5]; |
747 | 747 | ||
748 | /* | 748 | /* |
749 | * Don't show empty devices or things that have been | 749 | * Don't show empty devices or things that have been |
@@ -762,14 +762,16 @@ void __init printk_all_partitions(void) | |||
762 | while ((part = disk_part_iter_next(&piter))) { | 762 | while ((part = disk_part_iter_next(&piter))) { |
763 | bool is_part0 = part == &disk->part0; | 763 | bool is_part0 = part == &disk->part0; |
764 | 764 | ||
765 | uuid[0] = 0; | 765 | uuid_buf[0] = '\0'; |
766 | if (part->info) | 766 | if (part->info) |
767 | part_unpack_uuid(part->info->uuid, uuid); | 767 | snprintf(uuid_buf, sizeof(uuid_buf), "%pU", |
768 | part->info->uuid); | ||
768 | 769 | ||
769 | printk("%s%s %10llu %s %s", is_part0 ? "" : " ", | 770 | printk("%s%s %10llu %s %s", is_part0 ? "" : " ", |
770 | bdevt_str(part_devt(part), devt_buf), | 771 | bdevt_str(part_devt(part), devt_buf), |
771 | (unsigned long long)part->nr_sects >> 1, | 772 | (unsigned long long)part->nr_sects >> 1, |
772 | disk_name(disk, part->partno, name_buf), uuid); | 773 | disk_name(disk, part->partno, name_buf), |
774 | uuid_buf); | ||
773 | if (is_part0) { | 775 | if (is_part0) { |
774 | if (disk->driverfs_dev != NULL && | 776 | if (disk->driverfs_dev != NULL && |
775 | disk->driverfs_dev->driver != NULL) | 777 | disk->driverfs_dev->driver != NULL) |
diff --git a/include/linux/genhd.h b/include/linux/genhd.h index e61d3192448e..017a7fb5a1fc 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h | |||
@@ -222,12 +222,6 @@ static inline void part_pack_uuid(const u8 *uuid_str, u8 *to) | |||
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | static inline char *part_unpack_uuid(const u8 *uuid, char *out) | ||
226 | { | ||
227 | sprintf(out, "%pU", uuid); | ||
228 | return out; | ||
229 | } | ||
230 | |||
231 | static inline int disk_max_parts(struct gendisk *disk) | 225 | static inline int disk_max_parts(struct gendisk *disk) |
232 | { | 226 | { |
233 | if (disk->flags & GENHD_FL_EXT_DEVT) | 227 | if (disk->flags & GENHD_FL_EXT_DEVT) |