Skip to content

Commit

Permalink
coredump: kill cn_escape(), introduce cn_esc_printf()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Colin Walters <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Lennart Poettering <[email protected]>
Cc: Lucas De Marchi <[email protected]>
Acked-by: Neil Horman <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Jul 3, 2013
1 parent 5fe9d8c commit 923bed0
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,21 @@ static int cn_printf(struct core_name *cn, const char *fmt, ...)
return ret;
}

static void cn_escape(char *str)
static int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
{
for (; *str; str++)
if (*str == '/')
*str = '!';
int cur = cn->used;
va_list arg;
int ret;

va_start(arg, fmt);
ret = cn_vprintf(cn, fmt, arg);
va_end(arg);

for (; cur < cn->used; ++cur) {
if (cn->corename[cur] == '/')
cn->corename[cur] = '!';
}
return ret;
}

static int cn_print_exe_file(struct core_name *cn)
Expand All @@ -113,12 +123,8 @@ static int cn_print_exe_file(struct core_name *cn)
int ret;

exe_file = get_mm_exe_file(current->mm);
if (!exe_file) {
char *commstart = cn->corename + cn->used;
ret = cn_printf(cn, "%s (path unknown)", current->comm);
cn_escape(commstart);
return ret;
}
if (!exe_file)
return cn_esc_printf(cn, "%s (path unknown)", current->comm);

pathbuf = kmalloc(PATH_MAX, GFP_TEMPORARY);
if (!pathbuf) {
Expand All @@ -132,9 +138,7 @@ static int cn_print_exe_file(struct core_name *cn)
goto free_buf;
}

cn_escape(path);

ret = cn_printf(cn, "%s", path);
ret = cn_esc_printf(cn, "%s", path);

free_buf:
kfree(pathbuf);
Expand Down Expand Up @@ -207,22 +211,16 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
break;
}
/* hostname */
case 'h': {
char *namestart = cn->corename + cn->used;
case 'h':
down_read(&uts_sem);
err = cn_printf(cn, "%s",
err = cn_esc_printf(cn, "%s",
utsname()->nodename);
up_read(&uts_sem);
cn_escape(namestart);
break;
}
/* executable */
case 'e': {
char *commstart = cn->corename + cn->used;
err = cn_printf(cn, "%s", current->comm);
cn_escape(commstart);
case 'e':
err = cn_esc_printf(cn, "%s", current->comm);
break;
}
case 'E':
err = cn_print_exe_file(cn);
break;
Expand Down

0 comments on commit 923bed0

Please sign in to comment.