From: Dinghao Liu <dinghao.liu@zju.edu.cn>
To: dinghao.liu@zju.edu.cn, kjlu@umn.edu
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fs/binfmt_elf: Fix memleak in load_elf_binary
Date: Thu, 27 Aug 2020 19:46:39 +0800 [thread overview]
Message-ID: <20200827114639.31298-1-dinghao.liu@zju.edu.cn> (raw)
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@zju.edu.cn>
---
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
reply other threads:[~2020-08-27 12:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200827114639.31298-1-dinghao.liu@zju.edu.cn \
--to=dinghao.liu@zju.edu.cn \
--cc=kjlu@umn.edu \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).