[PATCH] fs/binfmt_elf: Fix memleak in load_elf_binary

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When arch_setup_additional_pages() fails, interp_elf_ex may
not have been freed, which leads to memleak.  It's the same
when create_elf_tables() fails.

Signed-off-by: Dinghao Liu <dinghao.liu@xxxxxxxxxx>
---
 fs/binfmt_elf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 13d053982dd7..984c30684e49 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1204,6 +1204,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
 		fput(interpreter);
 
 		kfree(interp_elf_ex);
+		interp_elf_ex = NULL;
 		kfree(interp_elf_phdata);
 	} else {
 		elf_entry = e_entry;
@@ -1219,14 +1220,18 @@ static int load_elf_binary(struct linux_binprm *bprm)
 
 #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES
 	retval = arch_setup_additional_pages(bprm, !!interpreter);
-	if (retval < 0)
+	if (retval < 0) {
+		kfree(interp_elf_ex);
 		goto out;
+	}
 #endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */
 
 	retval = create_elf_tables(bprm, elf_ex,
 			  load_addr, interp_load_addr, e_entry);
-	if (retval < 0)
+	if (retval < 0) {
+		kfree(interp_elf_ex);
 		goto out;
+	}
 
 	mm = current->mm;
 	mm->end_code = end_code;
-- 
2.17.1




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux