smack: Fix a memory leak in smack_add_opt()
Subsystems (3)
PATCH 1/1 smack: Fix a memory leak in smack_add_opt()
The function is leaking "opts" on the error paths.
Fixes 90e3b564ab93 ("smack: take the guts of smack_parse_opts_str() into a new helper")
Signed-off-by Dan Carpenter <[email protected]>
--- security/smack/smack_lsm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
security/smack/smack_lsm.c +4 -2
@@ -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:
@@ -643,6 +643,8 @@ static int smack_add_opt(int token, const char *s, void **mnt_opts)return 0 ; out_opt_err: +if (opts != *mnt_opts) +kfree (opts);pr_warn ("Smack: duplicate mount options\n" );return -EINVAL ; }
Signature · 1 line
2.17.1
Quoted 4 lines · Dan Carpenter
The function is leaking "opts" on the error paths.
Fixes 90e3b564ab93 ("smack: take the guts of smack_parse_opts_str() into a new helper")Signed-off-by Dan Carpenter <[email protected]>
D'oh... Applied, thanks for spotting that braino.
Quoted 7 lines · Al Viro
Quoted 4 lines · Dan Carpenter
The function is leaking "opts" on the error paths.
Fixes 90e3b564ab93 ("smack: take the guts of smack_parse_opts_str() into a new helper")Signed-off-by Dan Carpenter <[email protected]>D'oh... Applied, thanks for spotting that braino.
On the other hand, it's easier to do it this way - the caller will free the damn thing on error, anyway:
security/smack/smack_lsm.c +1 -1
@@ -608,6 +608,7 @@ static int smack_add_opt(int token, const char *s, void **mnt_opts) opts =kzalloc (sizeof (struct smack_mnt_opts ),GFP_KERNEL );if (!opts)return -ENOMEM ; + *mnt_opts = opts; }if (!s)return -ENOMEM ;
@@ -639,7 +640,6 @@ static int smack_add_opt(int token, const char *s, void **mnt_opts) opts->fstransmute = s;break ; } - *mnt_opts = opts;return 0 ; out_opt_err:
Casey Schaufler
maintainerQuoted 9 lines · Al Viro
Quoted 6 lines · Al Viro
Quoted 4 lines · Dan Carpenter
The function is leaking "opts" on the error paths.
Fixes 90e3b564ab93 ("smack: take the guts of smack_parse_opts_str() into a new helper")Signed-off-by Dan Carpenter <[email protected]>D'oh... Applied, thanks for spotting that braino.
On the other hand, it's easier to do it this way - the caller will free the damn thing on error, anyway:
What tree/branch is the happening in?
Quoted 22 lines
security/smack/smack_lsm.c +1
-1@@ -608,6 +608,7 @@ static int smack_add_opt(int token, const char *s, void **mnt_opts) opts =kzalloc (sizeof (struct smack_mnt_opts ),GFP_KERNEL );if (!opts)return -ENOMEM ; + *mnt_opts = opts; }if (!s)return -ENOMEM ;@@ -639,7 +640,6 @@ static int smack_add_opt(int token, const char *s, void **mnt_opts) opts->fstransmute = s;break ; } - *mnt_opts = opts;return 0 ; out_opt_err: