linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* stack overflow in printk_all_partitions.
@ 2012-05-09 19:58 Dave Jones
  2012-05-14 21:03 ` [PATCH] block: fix buffer overflow when printing partition UUIDs Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Jones @ 2012-05-09 19:58 UTC (permalink / raw)
  To: Linux Kernel; +Cc: Szymon Gruszczynski, Fedora Kernel Team, Al Viro, Tejun Heo

Szymon (cc'd) reported this oops that prevents his machine booting
a 3.3.4 kernel.

[ 2.892504] Kernel panic - not syncing: stack-protector: Kernel stack corrupted in: ffffffff81b14c7e
[ 2.892506]
[ 2.892872] [<ffffffff815e226b>] panic+0xba/0x1c6
[ 2.892961] [<ffffffff81b14c7e>] ? printk_all_partitions+0x259/0x26xb
[ 2.893057] [<ffffffff810566bb>] __stack_chk_fail+0x1b/0x20
[ 2.893147] [<ffffffff81b15c7e>] printk_all_paritions+0x259/0x26xb
[ 2.893244] [<ffffffff81aedfe0>] mount_block_root+0x1bc/0x27f
[ 2.893336] [<ffffffff81aee0fa>] mount_root+0x57/0x5b
[ 2.893425] [<ffffffff81aee23b>] prepare_namespace+0x13d/0x176
[ 2.893522] [<ffffffff8107eec0>] ? release_tgcred.isra.4+0x330/0x30
[ 2.893616] [<ffffffff81aedd60>] kernel_init+0x155/0x15a
[ 2.893708] [<ffffffff81087b97>] ? schedule_tail+0x27/0xb0
[ 2.893800] [<ffffffff815f4d24>] kernel_thread_helper+0x5/0x10
[ 2.893893] [<ffffffff81aedc0b>] ? start_kernel+0x3c5/0x3c5
[ 2.893984] [<ffffffff815f4d20>] ? gs_change+0x13/0x13

His partition tables don't look anything out of the ordinary to me.
http://wklej.org/id/748085/

Any ideas what's going wrong here ?

original report at https://bugzilla.redhat.com/show_bug.cgi?id=819624,
though all pertinent info so far is captured above.

	Dave

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] block: fix buffer overflow when printing partition UUIDs
  2012-05-09 19:58 stack overflow in printk_all_partitions Dave Jones
@ 2012-05-14 21:03 ` Tejun Heo
  2012-05-15  6:22   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2012-05-14 21:03 UTC (permalink / raw)
  To: Dave Jones, Jens Axboe
  Cc: Linux Kernel, Szymon Gruszczynski, Fedora Kernel Team, Al Viro

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
---
 block/genhd.c         |   10 ++++++----
 include/linux/genhd.h |    6 ------
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index df9816e..9cf5583 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -743,7 +743,7 @@ void __init printk_all_partitions(void)
 		struct hd_struct *part;
 		char name_buf[BDEVNAME_SIZE];
 		char devt_buf[BDEVT_SIZE];
-		u8 uuid[PARTITION_META_INFO_UUIDLTH * 2 + 1];
+		char uuid_buf[PARTITION_META_INFO_UUIDLTH * 2 + 5];
 
 		/*
 		 * Don't show empty devices or things that have been
@@ -762,14 +762,16 @@ void __init printk_all_partitions(void)
 		while ((part = disk_part_iter_next(&piter))) {
 			bool is_part0 = part == &disk->part0;
 
-			uuid[0] = 0;
+			uuid_buf[0] = '\0';
 			if (part->info)
-				part_unpack_uuid(part->info->uuid, uuid);
+				snprintf(uuid_buf, sizeof(uuid_buf), "%pU",
+					 part->info->uuid);
 
 			printk("%s%s %10llu %s %s", is_part0 ? "" : "  ",
 			       bdevt_str(part_devt(part), devt_buf),
 			       (unsigned long long)part->nr_sects >> 1,
-			       disk_name(disk, part->partno, name_buf), uuid);
+			       disk_name(disk, part->partno, name_buf),
+			       uuid_buf);
 			if (is_part0) {
 				if (disk->driverfs_dev != NULL &&
 				    disk->driverfs_dev->driver != NULL)
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index e61d319..017a7fb 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)
 	}
 }
 
-static inline char *part_unpack_uuid(const u8 *uuid, char *out)
-{
-	sprintf(out, "%pU", uuid);
-	return out;
-}
-
 static inline int disk_max_parts(struct gendisk *disk)
 {
 	if (disk->flags & GENHD_FL_EXT_DEVT)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: fix buffer overflow when printing partition UUIDs
  2012-05-14 21:03 ` [PATCH] block: fix buffer overflow when printing partition UUIDs Tejun Heo
@ 2012-05-15  6:22   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2012-05-15  6:22 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Dave Jones, Linux Kernel, Szymon Gruszczynski, Fedora Kernel Team,
	Al Viro

On 05/14/2012 11:03 PM, Tejun Heo wrote:
> 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().

Ooops, thanks Tejun, applied for current branch.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-05-15  6:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-09 19:58 stack overflow in printk_all_partitions Dave Jones
2012-05-14 21:03 ` [PATCH] block: fix buffer overflow when printing partition UUIDs Tejun Heo
2012-05-15  6:22   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).