BACKPORT: SMACK: Fix the memory leak in smack_cred_prepare() hook
authorHimanshu Shukla <himanshu.sh@samsung.com>
Thu, 10 Nov 2016 10:47:02 +0000 (16:17 +0530)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 21 Nov 2016 16:02:12 +0000 (17:02 +0100)
commitecb007d924a481408060ab0dd5e30d5839cd9c8d
tree349a821d34811f3f58aaebbf50d905d6e4f0855e
parent2b92f54763859ab3a802dddd39ddf7d5a1d7fb33
BACKPORT: SMACK: Fix the memory leak in smack_cred_prepare() hook

Memory leak in smack_cred_prepare()function.
smack_cred_prepare() hook returns error if there is error in allocating
memory in smk_copy_rules() or smk_copy_relabel() function.
If smack_cred_prepare() function returns error then the calling
function should call smack_cred_free() function for cleanup.
In smack_cred_free() function first credential is  extracted and
then all rules are deleted. In smack_cred_prepare() function security
field is assigned in the end when all function return success. But this
function may return before and memory will not be freed.

Signed-off-by: Himanshu Shukla <himanshu.sh@samsung.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
(cherry-picked from upstream b437aba85b5c4689543409d8407c016749231aae)
security/smack/smack_lsm.c