Skip to content

Commit

Permalink
security: Add hooks to rule on setting a watch
Browse files Browse the repository at this point in the history
Add security hooks that will allow an LSM to rule on whether or not a watch
may be set.  More than one hook is required as the watches watch different
types of object.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jamorris@linux.microsoft.com>
cc: Casey Schaufler <casey@schaufler-ca.com>
cc: Stephen Smalley <sds@tycho.nsa.gov>
cc: linux-security-module@vger.kernel.org
  • Loading branch information
David Howells committed May 19, 2020
1 parent c73be61 commit 998f504
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/linux/lsm_hook_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx,
#if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE)
LSM_HOOK(int, 0, post_notification, const struct cred *w_cred,
const struct cred *cred, struct watch_notification *n)
#endif /* CONFIG_SECURITY && CONFIG_WATCH_QUEUE */

#if defined(CONFIG_SECURITY) && defined(CONFIG_KEY_NOTIFICATIONS)
LSM_HOOK(int, 0, watch_key, struct key *key)
#endif /* CONFIG_SECURITY && CONFIG_KEY_NOTIFICATIONS */

#ifdef CONFIG_SECURITY_NETWORK
Expand Down
5 changes: 5 additions & 0 deletions include/linux/lsm_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,11 @@
* @cred: The event-triggerer's credentials
* @n: The notification being posted
*
* @watch_key:
* Check to see if a process is allowed to watch for event notifications
* from a key or keyring.
* @key: The key to watch.
*
* Security hooks for using the eBPF maps and programs functionalities through
* eBPF syscalls.
*
Expand Down
9 changes: 9 additions & 0 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,15 @@ static inline int security_post_notification(const struct cred *w_cred,
}
#endif

#if defined(CONFIG_SECURITY) && defined(CONFIG_KEY_NOTIFICATIONS)
int security_watch_key(struct key *key);
#else
static inline int security_watch_key(struct key *key)
{
return 0;
}
#endif

#ifdef CONFIG_SECURITY_NETWORK

int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk);
Expand Down
7 changes: 7 additions & 0 deletions security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,13 @@ int security_post_notification(const struct cred *w_cred,
}
#endif /* CONFIG_WATCH_QUEUE */

#ifdef CONFIG_KEY_NOTIFICATIONS
int security_watch_key(struct key *key)
{
return call_int_hook(watch_key, 0, key);
}
#endif

#ifdef CONFIG_SECURITY_NETWORK

int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)
Expand Down

0 comments on commit 998f504

Please sign in to comment.