lsm: ensure the correct LSM context releaser
authorCasey Schaufler <casey@schaufler-ca.com>
Wed, 23 Oct 2024 21:21:54 +0000 (14:21 -0700)
committerPaul Moore <paul@paul-moore.com>
Wed, 4 Dec 2024 15:46:26 +0000 (10:46 -0500)
commit6fba89813ccf333d2bc4d5caea04cd5f3c39eb50
treeb81fee3690bd96f7009b49f7dca8f4a33bc11f01
parent40384c840ea1944d7c5a392e8975ed088ecf0b37
lsm: ensure the correct LSM context releaser

Add a new lsm_context data structure to hold all the information about a
"security context", including the string, its size and which LSM allocated
the string. The allocation information is necessary because LSMs have
different policies regarding the lifecycle of these strings. SELinux
allocates and destroys them on each use, whereas Smack provides a pointer
to an entry in a list that never goes away.

Update security_release_secctx() to use the lsm_context instead of a
(char *, len) pair. Change its callers to do likewise.  The LSMs
supporting this hook have had comments added to remind the developer
that there is more work to be done.

The BPF security module provides all LSM hooks. While there has yet to
be a known instance of a BPF configuration that uses security contexts,
the possibility is real. In the existing implementation there is
potential for multiple frees in that case.

Cc: linux-integrity@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: audit@vger.kernel.org
Cc: netfilter-devel@vger.kernel.org
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: linux-nfs@vger.kernel.org
Cc: Todd Kjos <tkjos@google.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
[PM: subject tweak]
Signed-off-by: Paul Moore <paul@paul-moore.com>
19 files changed:
drivers/android/binder.c
fs/ceph/xattr.c
fs/nfs/nfs4proc.c
fs/nfsd/nfs4xdr.c
include/linux/lsm_hook_defs.h
include/linux/security.h
include/net/scm.h
kernel/audit.c
kernel/auditsc.c
net/ipv4/ip_sockglue.c
net/netfilter/nf_conntrack_netlink.c
net/netfilter/nf_conntrack_standalone.c
net/netfilter/nfnetlink_queue.c
net/netlabel/netlabel_unlabeled.c
net/netlabel/netlabel_user.c
security/apparmor/include/secid.h
security/apparmor/secid.c
security/security.c
security/selinux/hooks.c