diff options
author | Eric Dumazet <edumazet@google.com> | 2014-04-19 13:15:07 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-19 16:23:31 -0400 |
commit | 404ca80eb5c2727d78cd517d12108b040c522e12 (patch) | |
tree | 0ff760410325ec53b260f16d844969965921c793 | |
parent | 6d4596905b65bf4c63c1a008f50bf385fa49f19b (diff) |
coredump: fix va_list corruption
A va_list needs to be copied in case it needs to be used twice.
Thanks to Hugh for debugging this issue, leading to various panics.
Tested:
lpq84:~# echo "|/foobar12345 %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h" >/proc/sys/kernel/core_pattern
'produce_core' is simply : main() { *(int *)0 = 1;}
lpq84:~# ./produce_core
Segmentation fault (core dumped)
lpq84:~# dmesg | tail -1
[ 614.352947] Core dump to |/foobar12345 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 lpq84 (null) pipe failed
Notice the last argument was replaced by a NULL (we were lucky enough to
not crash, but do not try this on your production machine !)
After fix :
lpq83:~# echo "|/foobar12345 %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h %h" >/proc/sys/kernel/core_pattern
lpq83:~# ./produce_core
Segmentation fault
lpq83:~# dmesg | tail -1
[ 740.800441] Core dump to |/foobar12345 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 lpq83 pipe failed
Fixes: 5fe9d8ca21cc ("coredump: cn_vprintf() has no reason to call vsnprintf() twice")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Diagnosed-by: Hugh Dickins <hughd@google.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: stable@vger.kernel.org # 3.11+
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/coredump.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/coredump.c b/fs/coredump.c index e3ad709a4232..0b2528fb640e 100644 --- a/fs/coredump.c +++ b/fs/coredump.c | |||
@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size) | |||
73 | static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg) | 73 | static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg) |
74 | { | 74 | { |
75 | int free, need; | 75 | int free, need; |
76 | va_list arg_copy; | ||
76 | 77 | ||
77 | again: | 78 | again: |
78 | free = cn->size - cn->used; | 79 | free = cn->size - cn->used; |
79 | need = vsnprintf(cn->corename + cn->used, free, fmt, arg); | 80 | |
81 | va_copy(arg_copy, arg); | ||
82 | need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy); | ||
83 | va_end(arg_copy); | ||
84 | |||
80 | if (need < free) { | 85 | if (need < free) { |
81 | cn->used += need; | 86 | cn->used += need; |
82 | return 0; | 87 | return 0; |