Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

block: fix buffer overflow when printing partition UUIDs

commit 05c69d2 upstream.

6d1d805 "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, b5af921 "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>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
  • Loading branch information...
commit 9fd246e048bbd8569a84b412382cd299e0313a62 1 parent 6609c1c
authored May 15, 2012 Ben Hutchings committed May 31, 2012
10  block/genhd.c
@@ -744,7 +744,7 @@ void __init printk_all_partitions(void)
744 744
 		struct hd_struct *part;
745 745
 		char name_buf[BDEVNAME_SIZE];
746 746
 		char devt_buf[BDEVT_SIZE];
747  
-		u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
  747
+		char uuid_buf[PARTITION_META_INFO_UUIDLTH * 2 + 5];
748 748
 
749 749
 		/*
750 750
 		 * Don't show empty devices or things that have been
@@ -763,14 +763,16 @@ void __init printk_all_partitions(void)
763 763
 		while ((part = disk_part_iter_next(&piter))) {
764 764
 			bool is_part0 = part == &disk->part0;
765 765
 
766  
-			uuid[0] = 0;
  766
+			uuid_buf[0] = '\0';
767 767
 			if (part->info)
768  
-				part_unpack_uuid(part->info->uuid, uuid);
  768
+				snprintf(uuid_buf, sizeof(uuid_buf), "%pU",
  769
+					 part->info->uuid);
769 770
 
770 771
 			printk("%s%s %10llu %s %s", is_part0 ? "" : "  ",
771 772
 			       bdevt_str(part_devt(part), devt_buf),
772 773
 			       (unsigned long long)part->nr_sects >> 1,
773  
-			       disk_name(disk, part->partno, name_buf), uuid);
  774
+			       disk_name(disk, part->partno, name_buf),
  775
+			       uuid_buf);
774 776
 			if (is_part0) {
775 777
 				if (disk->driverfs_dev != NULL &&
776 778
 				    disk->driverfs_dev->driver != NULL)
6  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 225
 static inline int disk_max_parts(struct gendisk *disk)
232 226
 {
233 227
 	if (disk->flags & GENHD_FL_EXT_DEVT)

0 notes on commit 9fd246e

Please sign in to comment.
Something went wrong with that request. Please try again.