fs/binfmt_elf.c: fix a wrong free
Subsystems (2)
PATCH 1/1 fs/binfmt_elf.c: fix a wrong free
Fix a wrong free in fs/binfmt_elf.c::elf_core_dump().
--- fs/binfmt_elf.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/binfmt_elf.c +1 -1
@@ -2032,10 +2032,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un end_coredump:set_fs (fs); +free_note_info (&info); cleanup:kfree (elf); -free_note_info (&info);return has_dumped; }
Signature · 1 line
1.5.4.1
Quoted 15 lines · WANG Cong
Fix a wrong free in fs/binfmt_elf.c::elf_core_dump().
Signed-off-by WANG Cong <[email protected]>Cc Alexander Viro <[email protected]>Cc Eric Youngdale <[email protected]>--- fs/binfmt_elf.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)fs/binfmt_elf.c +0
-0
fs/binfmt_elf.c static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un · line 2040
Quoted 10 lines
fs/binfmt_elf.c +1
-1@@ -2032,10 +2032,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un end_coredump:set_fs (fs); +free_note_info (&info); cleanup:kfree (elf); -free_note_info (&info);return has_dumped; }
Looks like fill_note_info() requires that you call free_note_info() if it fails; otherwise we'll leak memory. So perhaps something like the following totally untested patch?
Pekka
fs/binfmt_elf.c +4 -2
@@ -1917,7 +1917,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un*/ if (!fill_note_info (elf, segs +1 ,/* including notes section */ &info, signr, regs)) - goto cleanup; + goto cleanup_note; has_dumped =1 ; current->flags |=PF_DUMPCORE ;
@@ -2033,9 +2033,11 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un end_coredump:set_fs (fs); +cleanup_note: +free_note_info (&info); + cleanup:kfree (elf); -free_note_info (&info);return has_dumped; }
Quoted 21 lines · Pekka J Enberg
Quoted 20 lines · WANG Cong
Fix a wrong free in fs/binfmt_elf.c::elf_core_dump().
Signed-off-by WANG Cong <[email protected]>Cc Alexander Viro <[email protected]>Cc Eric Youngdale <[email protected]>--- fs/binfmt_elf.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)fs/binfmt_elf.c +1
-0@@ -2032,10 +2032,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un end_coredump:set_fs (fs); +free_note_info (&info);
Quoted 10 lines
fs/binfmt_elf.c static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un · line 2040
Quoted 5 lines
fs/binfmt_elf.c +0
-1cleanup:kfree (elf); -free_note_info (&info);return has_dumped; }Looks like
fill_note_info()requires that you callfree_note_info()if it fails; otherwise we'll leak memory. So perhaps something like the following totally untested patch?
Hi, Pekka!
Thanks for your comments. Yes, it seems that fill_note_info() is ugly. :-) How about the below one?
---
fs/binfmt_elf.c +3 -2
@@ -1900,7 +1900,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un/* alloc memory for large data structures: too large to be on stack */ elf =kmalloc (sizeof (*elf),GFP_KERNEL );if (!elf) - goto cleanup; + goto ret; segs = current->mm->map_count;#ifdef ELF_CORE_EXTRA_PHDRS
@@ -2034,8 +2034,9 @@ end_coredump:set_fs (fs); cleanup: -kfree (elf);free_note_info (&info); +kfree (elf); +ret:return has_dumped; }
Quoted 22 lines · WANG Cong
Hi, Pekka!
Thanks for your comments. Yes, it seems that
fill_note_info()is ugly. :-) How about the below one?Signed-off-by WANG Cong <[email protected]>---
fs/binfmt_elf.c +1
-1@@ -1900,7 +1900,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un/* alloc memory for large data structures: too large to be on stack */ elf =kmalloc (sizeof (*elf),GFP_KERNEL );if (!elf) - goto cleanup; + goto ret; segs = current->mm->map_count;#ifdef ELF_CORE_EXTRA_PHDRS
fs/binfmt_elf.c end_coredump: · line 2040
Quoted 8 lines
fs/binfmt_elf.c +2
-1@@ -2034,8 +2034,9 @@ end_coredump:set_fs (fs); cleanup: -kfree (elf);free_note_info (&info); +kfree (elf); +ret:return has_dumped;
Looks good although 'ret' is usually reserved for the variable that contains the return value so you might want to consider using the more idiomatic 'out' as the label name.
Pekka
Quoted 4 lines · Pekka Enberg
Looks good although 'ret' is usually reserved for the variable that contains the return value so you might want to consider using the more idiomatic 'out' as the label name.
Thanks. Done.
---
fs/binfmt_elf.c +3 -2
@@ -1900,7 +1900,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un/* alloc memory for large data structures: too large to be on stack */ elf =kmalloc (sizeof (*elf),GFP_KERNEL );if (!elf) - goto cleanup; + goto out; segs = current->mm->map_count;#ifdef ELF_CORE_EXTRA_PHDRS
@@ -2034,8 +2034,9 @@ end_coredump:set_fs (fs); cleanup: -kfree (elf);free_note_info (&info); +kfree (elf); +out:return has_dumped; }