Skip to content

Commit af15f14

Browse files
WOnder93pcmoore
authored andcommitted
selinux: free str on error in str_read()
In [see "Fixes:"] I missed the fact that str_read() may give back an allocated pointer even if it returns an error, causing a potential memory leak in filename_trans_read_one(). Fix this by making the function free the allocated string whenever it returns a non-zero value, which also makes its behavior more obvious and prevents repeating the same mistake in the future. Reported-by: coverity-bot <[email protected]> Addresses-Coverity-ID: 1461665 ("Resource leaks") Fixes: c3a2761 ("selinux: optimize storage of filename transitions") Signed-off-by: Ondrej Mosnacek <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent c753924 commit af15f14

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

security/selinux/ss/policydb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,14 @@ static int str_read(char **strp, gfp_t flags, void *fp, u32 len)
10351035
if (!str)
10361036
return -ENOMEM;
10371037

1038-
/* it's expected the caller should free the str */
1039-
*strp = str;
1040-
10411038
rc = next_entry(str, fp, len);
1042-
if (rc)
1039+
if (rc) {
1040+
kfree(str);
10431041
return rc;
1042+
}
10441043

10451044
str[len] = '\0';
1045+
*strp = str;
10461046
return 0;
10471047
}
10481048

0 commit comments

Comments
 (0)