diff options
author | Oleg Nesterov <oleg@redhat.com> | 2013-07-03 18:08:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-03 19:08:02 -0400 |
commit | 923bed030ff6e20b5176e10da151fade83097891 (patch) | |
tree | 80de412a4f62fda39eea66fe2c2d0c7f09a30e89 /fs | |
parent | 5fe9d8ca21cc1517258fe448639392d5d542eec6 (diff) |
coredump: kill cn_escape(), introduce cn_esc_printf()
The usage of cn_escape() looks really annoying, imho this sequence needs a
wrapper. And it is buggy. If cn_printf() does expand_corename()
cn_escape() writes to the freed memory.
Introduce cn_esc_printf() which hopefully does this all right. It records
the index before cn_vprintf(), not "char *" which is no longer valid (in
general) after krealloc().
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Colin Walters <walters@verbum.org>
Cc: Denys Vlasenko <vda.linux@googlemail.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Lennart Poettering <mzxreary@0pointer.de>
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/coredump.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/fs/coredump.c b/fs/coredump.c index 2b1d1f54e630..90d7cee54347 100644 --- a/fs/coredump.c +++ b/fs/coredump.c | |||
@@ -99,11 +99,21 @@ static int cn_printf(struct core_name *cn, const char *fmt, ...) | |||
99 | return ret; | 99 | return ret; |
100 | } | 100 | } |
101 | 101 | ||
102 | static void cn_escape(char *str) | 102 | static int cn_esc_printf(struct core_name *cn, const char *fmt, ...) |
103 | { | 103 | { |
104 | for (; *str; str++) | 104 | int cur = cn->used; |
105 | if (*str == '/') | 105 | va_list arg; |
106 | *str = '!'; | 106 | int ret; |
107 | |||
108 | va_start(arg, fmt); | ||
109 | ret = cn_vprintf(cn, fmt, arg); | ||
110 | va_end(arg); | ||
111 | |||
112 | for (; cur < cn->used; ++cur) { | ||
113 | if (cn->corename[cur] == '/') | ||
114 | cn->corename[cur] = '!'; | ||
115 | } | ||
116 | return ret; | ||
107 | } | 117 | } |
108 | 118 | ||
109 | static int cn_print_exe_file(struct core_name *cn) | 119 | static int cn_print_exe_file(struct core_name *cn) |
@@ -113,12 +123,8 @@ static int cn_print_exe_file(struct core_name *cn) | |||
113 | int ret; | 123 | int ret; |
114 | 124 | ||
115 | exe_file = get_mm_exe_file(current->mm); | 125 | exe_file = get_mm_exe_file(current->mm); |
116 | if (!exe_file) { | 126 | if (!exe_file) |
117 | char *commstart = cn->corename + cn->used; | 127 | return cn_esc_printf(cn, "%s (path unknown)", current->comm); |
118 | ret = cn_printf(cn, "%s (path unknown)", current->comm); | ||
119 | cn_escape(commstart); | ||
120 | return ret; | ||
121 | } | ||
122 | 128 | ||
123 | pathbuf = kmalloc(PATH_MAX, GFP_TEMPORARY); | 129 | pathbuf = kmalloc(PATH_MAX, GFP_TEMPORARY); |
124 | if (!pathbuf) { | 130 | if (!pathbuf) { |
@@ -132,9 +138,7 @@ static int cn_print_exe_file(struct core_name *cn) | |||
132 | goto free_buf; | 138 | goto free_buf; |
133 | } | 139 | } |
134 | 140 | ||
135 | cn_escape(path); | 141 | ret = cn_esc_printf(cn, "%s", path); |
136 | |||
137 | ret = cn_printf(cn, "%s", path); | ||
138 | 142 | ||
139 | free_buf: | 143 | free_buf: |
140 | kfree(pathbuf); | 144 | kfree(pathbuf); |
@@ -207,22 +211,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm) | |||
207 | break; | 211 | break; |
208 | } | 212 | } |
209 | /* hostname */ | 213 | /* hostname */ |
210 | case 'h': { | 214 | case 'h': |
211 | char *namestart = cn->corename + cn->used; | ||
212 | down_read(&uts_sem); | 215 | down_read(&uts_sem); |
213 | err = cn_printf(cn, "%s", | 216 | err = cn_esc_printf(cn, "%s", |
214 | utsname()->nodename); | 217 | utsname()->nodename); |
215 | up_read(&uts_sem); | 218 | up_read(&uts_sem); |
216 | cn_escape(namestart); | ||
217 | break; | 219 | break; |
218 | } | ||
219 | /* executable */ | 220 | /* executable */ |
220 | case 'e': { | 221 | case 'e': |
221 | char *commstart = cn->corename + cn->used; | 222 | err = cn_esc_printf(cn, "%s", current->comm); |
222 | err = cn_printf(cn, "%s", current->comm); | ||
223 | cn_escape(commstart); | ||
224 | break; | 223 | break; |
225 | } | ||
226 | case 'E': | 224 | case 'E': |
227 | err = cn_print_exe_file(cn); | 225 | err = cn_print_exe_file(cn); |
228 | break; | 226 | break; |