linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] smack: fix two memory leaks in smack_add_opt
@ 2018-12-22 12:27 Colin King
  2018-12-22 19:34 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2018-12-22 12:27 UTC (permalink / raw)
  To: Al Viro, Casey Schaufler, James Morris, Serge E . Hallyn,
	linux-security-module
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently if s is null or when returning via the error exit label
out_opt_err leaks of the allocated opts can occur. Fix the leak
on the null s case by checking s is null before the allocation. Fix
the leak on the exit path by checking if opts was allocated by
kfree'ing opts.

Detected by CoverityScan, CID#1475953 ("Resource leak")

Fixes: b2130173efae ("smack: take the guts of smack_parse_opts_str() into a new helper")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 security/smack/smack_lsm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 84f72116a027..b5dc520adaa2 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -604,13 +604,13 @@ static int smack_add_opt(int token, const char *s, void **mnt_opts)
 {
 	struct smack_mnt_opts *opts = *mnt_opts;
 
+	if (!s)
+		return -ENOMEM;
 	if (!opts) {
 		opts = kzalloc(sizeof(struct smack_mnt_opts), GFP_KERNEL);
 		if (!opts)
 			return -ENOMEM;
 	}
-	if (!s)
-		return -ENOMEM;
 
 	switch (token) {
 	case Opt_fsdefault:
@@ -644,6 +644,8 @@ static int smack_add_opt(int token, const char *s, void **mnt_opts)
 
 out_opt_err:
 	pr_warn("Smack: duplicate mount options\n");
+	if (opts != *mnt_opts)
+		kfree(opts);
 	return -EINVAL;
 }
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] smack: fix two memory leaks in smack_add_opt
  2018-12-22 12:27 [PATCH][next] smack: fix two memory leaks in smack_add_opt Colin King
@ 2018-12-22 19:34 ` Al Viro
  2018-12-22 23:03   ` Colin Ian King
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2018-12-22 19:34 UTC (permalink / raw)
  To: Colin King
  Cc: Casey Schaufler, James Morris, Serge E . Hallyn,
	linux-security-module, kernel-janitors, linux-kernel

On Sat, Dec 22, 2018 at 12:27:50PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently if s is null or when returning via the error exit label
> out_opt_err leaks of the allocated opts can occur. Fix the leak
> on the null s case by checking s is null before the allocation. Fix
> the leak on the exit path by checking if opts was allocated by
> kfree'ing opts.
> 
> Detected by CoverityScan, CID#1475953 ("Resource leak")
> 
> Fixes: b2130173efae ("smack: take the guts of smack_parse_opts_str() into a new helper")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

There's a better fix in local tree, will go into -next tonight.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] smack: fix two memory leaks in smack_add_opt
  2018-12-22 19:34 ` Al Viro
@ 2018-12-22 23:03   ` Colin Ian King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2018-12-22 23:03 UTC (permalink / raw)
  To: Al Viro
  Cc: Casey Schaufler, James Morris, Serge E . Hallyn,
	linux-security-module, kernel-janitors, linux-kernel

On 22/12/2018 19:34, Al Viro wrote:
> On Sat, Dec 22, 2018 at 12:27:50PM +0000, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Currently if s is null or when returning via the error exit label
>> out_opt_err leaks of the allocated opts can occur. Fix the leak
>> on the null s case by checking s is null before the allocation. Fix
>> the leak on the exit path by checking if opts was allocated by
>> kfree'ing opts.
>>
>> Detected by CoverityScan, CID#1475953 ("Resource leak")
>>
>> Fixes: b2130173efae ("smack: take the guts of smack_parse_opts_str() into a new helper")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> There's a better fix in local tree, will go into -next tonight.
> 
OK, sounds good to me. Thanks

Colin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-22 23:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-22 12:27 [PATCH][next] smack: fix two memory leaks in smack_add_opt Colin King
2018-12-22 19:34 ` Al Viro
2018-12-22 23:03   ` Colin Ian King

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).