]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
lsm: fix smack_inode_removexattr and xattr_getsecurity memleak
authorCasey Schaufler <casey@schaufler-ca.com>
Tue, 19 Sep 2017 16:39:08 +0000 (09:39 -0700)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 19 Oct 2017 12:05:24 +0000 (10:05 -0200)
commita88a9a27892b2c046a1f5ba245f5fc9dea71ae57
tree6de27727dfab482a0167b24cf9c0d8b5849d30eb
parent572a47d2251244f890556c62fd1528bd6520cec6
lsm: fix smack_inode_removexattr and xattr_getsecurity memleak

BugLink: http://bugs.launchpad.net/bugs/1724783
commit 57e7ba04d422c3d41c8426380303ec9b7533ded9 upstream.

security_inode_getsecurity() provides the text string value
of a security attribute. It does not provide a "secctx".
The code in xattr_getsecurity() that calls security_inode_getsecurity()
and then calls security_release_secctx() happened to work because
SElinux and Smack treat the attribute and the secctx the same way.
It fails for cap_inode_getsecurity(), because that module has no
secctx that ever needs releasing. It turns out that Smack is the
one that's doing things wrong by not allocating memory when instructed
to do so by the "alloc" parameter.

The fix is simple enough. Change the security_release_secctx() to
kfree() because it isn't a secctx being returned by
security_inode_getsecurity(). Change Smack to allocate the string when
told to do so.

Note: this also fixes memory leaks for LSMs which implement
inode_getsecurity but not release_secctx, such as capabilities.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Reported-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: James Morris <james.l.morris@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
fs/xattr.c
security/smack/smack_lsm.c