]> git.baikalelectronics.ru Git - kernel.git/commit
selinux: free str on error in str_read()
authorOndrej Mosnacek <omosnace@redhat.com>
Tue, 14 Apr 2020 14:23:51 +0000 (16:23 +0200)
committerPaul Moore <paul@paul-moore.com>
Wed, 15 Apr 2020 21:23:16 +0000 (17:23 -0400)
commit7c41d5c8e174b79c47bd7db80cc200c921959685
tree1b200b5d57bc5479434ac08daa0b15027d23f06a
parentd6c7469fc3d7566e7ba7d0e42c9f927d32519dec
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 <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1461665 ("Resource leaks")
Fixes: 21e3d7c7a350 ("selinux: optimize storage of filename transitions")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/policydb.c