diff options
author | Greg Pearson <greg.pearson@hp.com> | 2014-02-10 17:25:36 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-02-10 19:01:40 -0500 |
commit | 38dfac843cb6d7be1874888839817404a15a6b3c (patch) | |
tree | 6dbd4b077fe973c6a54f549ce2e4ba4ab4b00635 /fs/proc | |
parent | a3eb7fbb41eb8d6e22d491741b8c5d5aa6cb069a (diff) |
vmcore: prevent PT_NOTE p_memsz overflow during header update
Currently, update_note_header_size_elf64() and
update_note_header_size_elf32() will add the size of a PT_NOTE entry to
real_sz even if that causes real_sz to exceeds max_sz. This patch
corrects the while loop logic in those routines to ensure that does not
happen and prints a warning if a PT_NOTE entry is dropped. If zero
PT_NOTE entries are found or this condition is encountered because the
only entry was dropped, a warning is printed and an error is returned.
One possible negative side effect of exceeding the max_sz limit is an
allocation failure in merge_note_headers_elf64() or
merge_note_headers_elf32() which would produce console output such as
the following while booting the crash kernel.
vmalloc: allocation failure: 14076997632 bytes
swapper/0: page allocation failure: order:0, mode:0x80d2
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.10.0-gbp1 #7
Call Trace:
dump_stack+0x19/0x1b
warn_alloc_failed+0xf0/0x160
__vmalloc_node_range+0x19e/0x250
vmalloc_user+0x4c/0x70
merge_note_headers_elf64.constprop.9+0x116/0x24a
vmcore_init+0x2d4/0x76c
do_one_initcall+0xe2/0x190
kernel_init_freeable+0x17c/0x207
kernel_init+0xe/0x180
ret_from_fork+0x7c/0xb0
Kdump: vmcore not initialized
kdump: dump target is /dev/sda4
kdump: saving to /sysroot//var/crash/127.0.0.1-2014.01.28-13:58:52/
kdump: saving vmcore-dmesg.txt
Cannot open /proc/vmcore: No such file or directory
kdump: saving vmcore-dmesg.txt failed
kdump: saving vmcore
kdump: saving vmcore failed
This type of failure has been seen on a four socket prototype system
with certain memory configurations. Most PT_NOTE sections have a single
entry similar to:
n_namesz = 0x5
n_descsz = 0x150
n_type = 0x1
Occasionally, a second entry is encountered with very large n_namesz and
n_descsz sizes:
n_namesz = 0x80000008
n_descsz = 0x510ae163
n_type = 0x80000008
Not yet sure of the source of these extra entries, they seem bogus, but
they shouldn't cause crash dump to fail.
Signed-off-by: Greg Pearson <greg.pearson@hp.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r-- | fs/proc/vmcore.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 2ca7ba047f04..88d4585b30f1 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c | |||
@@ -468,17 +468,24 @@ static int __init update_note_header_size_elf64(const Elf64_Ehdr *ehdr_ptr) | |||
468 | return rc; | 468 | return rc; |
469 | } | 469 | } |
470 | nhdr_ptr = notes_section; | 470 | nhdr_ptr = notes_section; |
471 | while (real_sz < max_sz) { | 471 | while (nhdr_ptr->n_namesz != 0) { |
472 | if (nhdr_ptr->n_namesz == 0) | ||
473 | break; | ||
474 | sz = sizeof(Elf64_Nhdr) + | 472 | sz = sizeof(Elf64_Nhdr) + |
475 | ((nhdr_ptr->n_namesz + 3) & ~3) + | 473 | ((nhdr_ptr->n_namesz + 3) & ~3) + |
476 | ((nhdr_ptr->n_descsz + 3) & ~3); | 474 | ((nhdr_ptr->n_descsz + 3) & ~3); |
475 | if ((real_sz + sz) > max_sz) { | ||
476 | pr_warn("Warning: Exceeded p_memsz, dropping PT_NOTE entry n_namesz=0x%x, n_descsz=0x%x\n", | ||
477 | nhdr_ptr->n_namesz, nhdr_ptr->n_descsz); | ||
478 | break; | ||
479 | } | ||
477 | real_sz += sz; | 480 | real_sz += sz; |
478 | nhdr_ptr = (Elf64_Nhdr*)((char*)nhdr_ptr + sz); | 481 | nhdr_ptr = (Elf64_Nhdr*)((char*)nhdr_ptr + sz); |
479 | } | 482 | } |
480 | kfree(notes_section); | 483 | kfree(notes_section); |
481 | phdr_ptr->p_memsz = real_sz; | 484 | phdr_ptr->p_memsz = real_sz; |
485 | if (real_sz == 0) { | ||
486 | pr_warn("Warning: Zero PT_NOTE entries found\n"); | ||
487 | return -EINVAL; | ||
488 | } | ||
482 | } | 489 | } |
483 | 490 | ||
484 | return 0; | 491 | return 0; |
@@ -648,17 +655,24 @@ static int __init update_note_header_size_elf32(const Elf32_Ehdr *ehdr_ptr) | |||
648 | return rc; | 655 | return rc; |
649 | } | 656 | } |
650 | nhdr_ptr = notes_section; | 657 | nhdr_ptr = notes_section; |
651 | while (real_sz < max_sz) { | 658 | while (nhdr_ptr->n_namesz != 0) { |
652 | if (nhdr_ptr->n_namesz == 0) | ||
653 | break; | ||
654 | sz = sizeof(Elf32_Nhdr) + | 659 | sz = sizeof(Elf32_Nhdr) + |
655 | ((nhdr_ptr->n_namesz + 3) & ~3) + | 660 | ((nhdr_ptr->n_namesz + 3) & ~3) + |
656 | ((nhdr_ptr->n_descsz + 3) & ~3); | 661 | ((nhdr_ptr->n_descsz + 3) & ~3); |
662 | if ((real_sz + sz) > max_sz) { | ||
663 | pr_warn("Warning: Exceeded p_memsz, dropping PT_NOTE entry n_namesz=0x%x, n_descsz=0x%x\n", | ||
664 | nhdr_ptr->n_namesz, nhdr_ptr->n_descsz); | ||
665 | break; | ||
666 | } | ||
657 | real_sz += sz; | 667 | real_sz += sz; |
658 | nhdr_ptr = (Elf32_Nhdr*)((char*)nhdr_ptr + sz); | 668 | nhdr_ptr = (Elf32_Nhdr*)((char*)nhdr_ptr + sz); |
659 | } | 669 | } |
660 | kfree(notes_section); | 670 | kfree(notes_section); |
661 | phdr_ptr->p_memsz = real_sz; | 671 | phdr_ptr->p_memsz = real_sz; |
672 | if (real_sz == 0) { | ||
673 | pr_warn("Warning: Zero PT_NOTE entries found\n"); | ||
674 | return -EINVAL; | ||
675 | } | ||
662 | } | 676 | } |
663 | 677 | ||
664 | return 0; | 678 | return 0; |