Skip to content

Commit 3e412cc

Browse files
committed
selinux: Implement the watch_key security hook
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 <[email protected]> Acked-by: Stephen Smalley <[email protected]> Reviewed-by: James Morris <[email protected]>
1 parent 8c0637e commit 3e412cc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

security/selinux/hooks.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6619,6 +6619,17 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
66196619
*_buffer = context;
66206620
return rc;
66216621
}
6622+
6623+
#ifdef CONFIG_KEY_NOTIFICATIONS
6624+
static int selinux_watch_key(struct key *key)
6625+
{
6626+
struct key_security_struct *ksec = key->security;
6627+
u32 sid = current_sid();
6628+
6629+
return avc_has_perm(&selinux_state,
6630+
sid, ksec->sid, SECCLASS_KEY, KEY__VIEW, NULL);
6631+
}
6632+
#endif
66226633
#endif
66236634

66246635
#ifdef CONFIG_SECURITY_INFINIBAND
@@ -7134,6 +7145,9 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
71347145
LSM_HOOK_INIT(key_free, selinux_key_free),
71357146
LSM_HOOK_INIT(key_permission, selinux_key_permission),
71367147
LSM_HOOK_INIT(key_getsecurity, selinux_key_getsecurity),
7148+
#ifdef CONFIG_KEY_NOTIFICATIONS
7149+
LSM_HOOK_INIT(watch_key, selinux_watch_key),
7150+
#endif
71377151
#endif
71387152

71397153
#ifdef CONFIG_AUDIT

0 commit comments

Comments
 (0)