[lkml]   [2018]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH][next] smack: fix two memory leaks in smack_add_opt
From: Colin Ian King <>

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

pr_warn("Smack: duplicate mount options\n");
+ if (opts != *mnt_opts)
+ kfree(opts);
return -EINVAL;

 \ /
  Last update: 2018-12-22 19:32    [W:0.076 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site