History

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.

David Howells committed 6 years ago

Commit 998f5041 parent c73be614 files · +25 −0Browse files

Unified · Split

4 files
  1. include/linux/lsm_hook_defs.h +4 −0
  2. include/linux/lsm_hooks.h +5 −0
  3. include/linux/security.h +9 −0
  4. security/security.c +7 −0
include/linux/lsm_hook_defs.h+4−0
@@ -256,6 +256,10 @@ LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx, · 255 unmodified lines
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+5−0
@@ -1446,6 +1446,11 @@ · 1445 unmodified lines
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+9−0
@@ -1290,6 +1290,15 @@ static inline int security_post_notification(const struct cred *w_cred, · 1289 unmodified lines
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+7−0
@@ -2016,6 +2016,13 @@ int security_post_notification(const struct cred *w_cred, · 2015 unmodified lines
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)