From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: linux-cifs@vger.kernel.org, "Aurélien Aptel" <aaptel@suse.com>,
liujiawen10@huawei.com, "Steve French" <smfrench@gmail.com>,
pshilov@microsoft.com, lsahlber@redhat.com, kdsouza@redhat.com,
ab@samba.org, palcantara@suse.de
Cc: <dujin1@huawei.com>, Mingfangsen <mingfangsen@huawei.com>,
zhangsaisai <zhangsaisai@huawei.com>
Subject: [PATCH cifs-utils v2] mount.cifs.c: fix memory leaks in main func
Date: Tue, 6 Aug 2019 10:35:29 +0800 [thread overview]
Message-ID: <0f780b18-0b1c-e2ff-31b1-1d697becd142@huawei.com> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 1958 bytes --]
From: Jiawen Liu <liujiawen10@huawei.com>
In mount.cifs module, orgoptions and mountpoint in the main func
point to the memory allocated by func realpath and strndup respectively.
However, they are not freed before the main func returns so that the
memory leaks occurred.
The memory leak problem is reported by LeakSanitizer tool.
LeakSanitizer url: "https://github.com/google/sanitizers"
Here I free the pointers orgoptions and mountpoint before main
func returns.
Fixes£º7549ad5e7126 ("memory leaks: caused by func realpath and strndup")
Signed-off-by: Jiawen Liu <liujiawen10@huawei.com>
Reported-by: Jin Du <dujin1@huawei.com>
Reviewed-by: Saisai Zhang <zhangsaisai@huawei.com>
Reviewed-by: Aur¨¦lien Aptel <aaptel@suse.com>
---
v1->v2:
- free orgoptions in main func as suggested by Aur¨¦lien Aptel
- free mountpoint in acquire_mountpoint func as suggested by Aur¨¦lien Aptel
mount.cifs.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/mount.cifs.c b/mount.cifs.c
index ae7a899..656d353 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -1891,7 +1891,10 @@ restore_privs:
uid_t __attribute__((unused)) uignore = setfsuid(oldfsuid);
gid_t __attribute__((unused)) gignore = setfsgid(oldfsgid);
}
-
+
+ if (rc) {
+ free(*mountpointp);
+ }
return rc;
}
@@ -1994,8 +1997,10 @@ int main(int argc, char **argv)
/* chdir into mountpoint as soon as possible */
rc = acquire_mountpoint(&mountpoint);
- if (rc)
+ if (rc) {
+ free(orgoptions);
return rc;
+ }
/*
* mount.cifs does privilege separation. Most of the code to handle
@@ -2014,6 +2019,8 @@ int main(int argc, char **argv)
/* child */
rc = assemble_mountinfo(parsed_info, thisprogram, mountpoint,
orig_dev, orgoptions);
+ free(orgoptions);
+ free(mountpoint);
return rc;
} else {
/* parent */
@@ -2149,5 +2156,6 @@ mount_exit:
}
free(options);
free(orgoptions);
+ free(mountpoint);
return rc;
}
--
2.7.4
next reply other threads:[~2019-08-06 2:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-06 2:35 Zhiqiang Liu [this message]
2019-08-06 16:49 ` [PATCH cifs-utils v2] mount.cifs.c: fix memory leaks in main func Pavel Shilovsky
2019-08-07 21:44 ` Pavel Shilovsky
2019-08-08 1:06 ` Zhiqiang Liu
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=0f780b18-0b1c-e2ff-31b1-1d697becd142@huawei.com \
--to=liuzhiqiang26@huawei.com \
--cc=aaptel@suse.com \
--cc=ab@samba.org \
--cc=dujin1@huawei.com \
--cc=kdsouza@redhat.com \
--cc=linux-cifs@vger.kernel.org \
--cc=liujiawen10@huawei.com \
--cc=lsahlber@redhat.com \
--cc=mingfangsen@huawei.com \
--cc=palcantara@suse.de \
--cc=pshilov@microsoft.com \
--cc=smfrench@gmail.com \
--cc=zhangsaisai@huawei.com \
/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).