Skip to content

Commit 998f504

Browse files
committed
security: Add hooks to rule on setting a watch
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 <[email protected]> Acked-by: James Morris <[email protected]> cc: Casey Schaufler <[email protected]> cc: Stephen Smalley <[email protected]> cc: [email protected]
1 parent c73be61 commit 998f504

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

include/linux/lsm_hook_defs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx,
256256
#if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE)
257257
LSM_HOOK(int, 0, post_notification, const struct cred *w_cred,
258258
const struct cred *cred, struct watch_notification *n)
259+
#endif /* CONFIG_SECURITY && CONFIG_WATCH_QUEUE */
260+
261+
#if defined(CONFIG_SECURITY) && defined(CONFIG_KEY_NOTIFICATIONS)
262+
LSM_HOOK(int, 0, watch_key, struct key *key)
259263
#endif /* CONFIG_SECURITY && CONFIG_KEY_NOTIFICATIONS */
260264

261265
#ifdef CONFIG_SECURITY_NETWORK

include/linux/lsm_hooks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,11 @@
14461446
* @cred: The event-triggerer's credentials
14471447
* @n: The notification being posted
14481448
*
1449+
* @watch_key:
1450+
* Check to see if a process is allowed to watch for event notifications
1451+
* from a key or keyring.
1452+
* @key: The key to watch.
1453+
*
14491454
* Security hooks for using the eBPF maps and programs functionalities through
14501455
* eBPF syscalls.
14511456
*

include/linux/security.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,15 @@ static inline int security_post_notification(const struct cred *w_cred,
12901290
}
12911291
#endif
12921292

1293+
#if defined(CONFIG_SECURITY) && defined(CONFIG_KEY_NOTIFICATIONS)
1294+
int security_watch_key(struct key *key);
1295+
#else
1296+
static inline int security_watch_key(struct key *key)
1297+
{
1298+
return 0;
1299+
}
1300+
#endif
1301+
12931302
#ifdef CONFIG_SECURITY_NETWORK
12941303

12951304
int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk);

security/security.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,13 @@ int security_post_notification(const struct cred *w_cred,
20162016
}
20172017
#endif /* CONFIG_WATCH_QUEUE */
20182018

2019+
#ifdef CONFIG_KEY_NOTIFICATIONS
2020+
int security_watch_key(struct key *key)
2021+
{
2022+
return call_int_hook(watch_key, 0, key);
2023+
}
2024+
#endif
2025+
20192026
#ifdef CONFIG_SECURITY_NETWORK
20202027

20212028
int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)

0 commit comments

Comments
 (0)