diff mbox series

[RFC,13/14] selinux: Implement the watch_key security hook [ver #3]

Message ID 157909515176.20155.5691408493465374252.stgit@warthog.procyon.org.uk (mailing list archive)
State New
Headers show
Series pipe: Keyrings, Block and USB notifications [ver #3] | expand

Commit Message

David Howells Jan. 15, 2020, 1:32 p.m. UTC
Implement the watch_key security hook to make sure that a key grants the
caller View permission in order to set a watch on a key.

For the moment, the watch_devices security hook is left unimplemented as
it's not obvious what the object should be since the queue is global and
didn't previously exist.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>

 security/selinux/hooks.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series


diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 116b4d644f68..d838d1b58d88 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -6587,6 +6587,17 @@  static int selinux_key_getsecurity(struct key *key, char **_buffer)
 	*_buffer = context;
 	return rc;
+static int selinux_watch_key(struct key *key)
+	struct key_security_struct *ksec = key->security;
+	u32 sid = current_sid();
+	return avc_has_perm(&selinux_state,
+			    sid, ksec->sid, SECCLASS_KEY, KEY_NEED_VIEW, NULL);
@@ -7081,6 +7092,9 @@  static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
 	LSM_HOOK_INIT(key_free, selinux_key_free),
 	LSM_HOOK_INIT(key_permission, selinux_key_permission),
 	LSM_HOOK_INIT(key_getsecurity, selinux_key_getsecurity),
+	LSM_HOOK_INIT(watch_key, selinux_watch_key),