Pull security subsystem updates from James Morris: - Extend LSM stacking to allow sharing of cred, file, ipc, inode, and task blobs. This paves the way for more full-featured LSMs to be merged, and is specifically aimed at LandLock and SARA LSMs. This work is from Casey and Kees. - There's a new LSM from Micah Morton: "SafeSetID gates the setid family of syscalls to restrict UID/GID transitions from a given UID/GID to only those approved by a system-wide whitelist." This feature is currently shipping in ChromeOS. * 'next-general' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (62 commits) keys: fix missing __user in KEYCTL_PKEY_QUERY LSM: Update list of SECURITYFS users in Kconfig LSM: Ignore "security=" when "lsm=" is specified LSM: Update function documentation for cap_capable security: mark expected switch fall-throughs and add a missing break tomoyo: Bump version. LSM: fix return value check in safesetid_init_securityfs() LSM: SafeSetID: add selftest LSM: SafeSetID: remove unused include LSM: SafeSetID: 'depend' on CONFIG_SECURITY LSM: Add 'name' field for SafeSetID in DEFINE_LSM LSM: add SafeSetID module that gates setid calls LSM: add SafeSetID module that gates setid calls tomoyo: Allow multiple use_group lines. tomoyo: Coding style fix. tomoyo: Swicth from cred->security to task_struct->security. security: keys: annotate implicit fall throughs security: keys: annotate implicit fall throughs security: keys: annotate implicit fall through capabilities:: annotate implicit fall through ...
Showing the changes to include/linux (5 of 78 files). Show all
Unified · Split
| @@ -209,6 +209,7 @@ extern bool has_ns_capability_noaudit(struct task_struct *t, · 208 unmodified lines | |||
| 209 | extern bool capable(int cap); | 209 | extern bool capable(int cap); |
| 210 | extern bool ns_capable(struct user_namespace *ns, int cap); | 210 | extern bool ns_capable(struct user_namespace *ns, int cap); |
| 211 | extern bool ns_capable_noaudit(struct user_namespace *ns, int cap); | 211 | extern bool ns_capable_noaudit(struct user_namespace *ns, int cap); |
| 212 | extern bool ns_capable_setid(struct user_namespace *ns, int cap); | ||
| 212 | #else | 213 | #else |
| 213 | static inline bool has_capability(struct task_struct *t, int cap) | 214 | static inline bool has_capability(struct task_struct *t, int cap) |
| 214 | { | 215 | { |
| @@ -240,6 +241,10 @@ static inline bool ns_capable_noaudit(struct user_namespace *ns, int cap) · 25 unmodified lines | |||
| 240 | { | 241 | { |
| 241 | return true; | 242 | return true; |
| 242 | } | 243 | } |
| 244 | static inline bool ns_capable_setid(struct user_namespace *ns, int cap) | ||
| 245 | { | ||
| 246 | return true; | ||
| 247 | } | ||
| 243 | #endif /* CONFIG_MULTIUSER */ | 248 | #endif /* CONFIG_MULTIUSER */ |
| 244 | extern bool privileged_wrt_inode_uidgid(struct user_namespace *ns, const struct inode *inode); | 249 | extern bool privileged_wrt_inode_uidgid(struct user_namespace *ns, const struct inode *inode); |
| 245 | extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap); | 250 | extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap); |
| @@ -15,7 +15,6 @@ · 14 unmodified lines | |||
| 15 | #include <linux/capability.h> | 15 | #include <linux/capability.h> |
| 16 | #include <linux/init.h> | 16 | #include <linux/init.h> |
| 17 | #include <linux/key.h> | 17 | #include <linux/key.h> |
| 18 | #include <linux/selinux.h> | ||
| 19 | #include <linux/atomic.h> | 18 | #include <linux/atomic.h> |
| 20 | #include <linux/uidgid.h> | 19 | #include <linux/uidgid.h> |
| 21 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
| @@ -1270,7 +1270,7 @@ · 1269 unmodified lines | |||
| 1270 | * @cred contains the credentials to use. | 1270 | * @cred contains the credentials to use. |
| 1271 | * @ns contains the user namespace we want the capability in | 1271 | * @ns contains the user namespace we want the capability in |
| 1272 | * @cap contains the capability <include/linux/capability.h>. | 1272 | * @cap contains the capability <include/linux/capability.h>. |
| 1273 | * @audit contains whether to write an audit message or not | 1273 | * @opts contains options for the capable check <include/linux/security.h> |
| 1274 | * Return 0 if the capability is granted for @tsk. | 1274 | * Return 0 if the capability is granted for @tsk. |
| 1275 | * @syslog: | 1275 | * @syslog: |
| 1276 | * Check permission before accessing the kernel message ring or changing | 1276 | * Check permission before accessing the kernel message ring or changing |
| @@ -1446,8 +1446,10 @@ union security_list_options { · 169 unmodified lines | |||
| 1446 | const kernel_cap_t *effective, | 1446 | const kernel_cap_t *effective, |
| 1447 | const kernel_cap_t *inheritable, | 1447 | const kernel_cap_t *inheritable, |
| 1448 | const kernel_cap_t *permitted); | 1448 | const kernel_cap_t *permitted); |
| 1449 | int (*capable)(const struct cred *cred, struct user_namespace *ns, | 1449 | int (*capable)(const struct cred *cred, |
| 1450 | int cap, int audit); | 1450 | struct user_namespace *ns, |
| 1451 | int cap, | ||
| 1452 | unsigned int opts); | ||
| 1451 | int (*quotactl)(int cmds, int type, int id, struct super_block *sb); | 1453 | int (*quotactl)(int cmds, int type, int id, struct super_block *sb); |
| 1452 | int (*quota_on)(struct dentry *dentry); | 1454 | int (*quota_on)(struct dentry *dentry); |
| 1453 | int (*syslog)(int type); | 1455 | int (*syslog)(int type); |
| @@ -2027,6 +2029,18 @@ struct security_hook_list { · 573 unmodified lines | |||
| 2027 | char *lsm; | 2029 | char *lsm; |
| 2028 | } __randomize_layout; | 2030 | } __randomize_layout; |
| 2029 | 2031 | ||
| 2032 | /* | ||
| 2033 | * Security blob size or offset data. | ||
| 2034 | */ | ||
| 2035 | struct lsm_blob_sizes { | ||
| 2036 | int lbs_cred; | ||
| 2037 | int lbs_file; | ||
| 2038 | int lbs_inode; | ||
| 2039 | int lbs_ipc; | ||
| 2040 | int lbs_msg_msg; | ||
| 2041 | int lbs_task; | ||
| 2042 | }; | ||
| 2043 | |||
| 2030 | /* | 2044 | /* |
| 2031 | * Initializing a security_hook_list structure takes | 2045 | * Initializing a security_hook_list structure takes |
| 2032 | * up a lot of space in a source file. This macro takes | 2046 | * up a lot of space in a source file. This macro takes |
| @@ -2042,9 +2056,21 @@ extern char *lsm_names; · 9 unmodified lines | |||
| 2042 | extern void security_add_hooks(struct security_hook_list *hooks, int count, | 2056 | extern void security_add_hooks(struct security_hook_list *hooks, int count, |
| 2043 | char *lsm); | 2057 | char *lsm); |
| 2044 | 2058 | ||
| 2059 | #define LSM_FLAG_LEGACY_MAJOR BIT(0) | ||
| 2060 | #define LSM_FLAG_EXCLUSIVE BIT(1) | ||
| 2061 | |||
| 2062 | enum lsm_order { | ||
| 2063 | LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ | ||
| 2064 | LSM_ORDER_MUTABLE = 0, | ||
| 2065 | }; | ||
| 2066 | |||
| 2045 | struct lsm_info { | 2067 | struct lsm_info { |
| 2046 | const char *name; /* Required. */ | 2068 | const char *name; /* Required. */ |
| 2069 | enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */ | ||
| 2070 | unsigned long flags; /* Optional: flags describing LSM */ | ||
| 2071 | int *enabled; /* Optional: controlled by CONFIG_LSM */ | ||
| 2047 | int (*init)(void); /* Required. */ | 2072 | int (*init)(void); /* Required. */ |
| 2073 | struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */ | ||
| 2048 | }; | 2074 | }; |
| 2049 | 2075 | ||
| 2050 | extern struct lsm_info __start_lsm_info[], __end_lsm_info[]; | 2076 | extern struct lsm_info __start_lsm_info[], __end_lsm_info[]; |
| @@ -2084,17 +2110,6 @@ static inline void security_delete_hooks(struct security_hook_list *hooks, · 33 unmodified lines | |||
| 2084 | #define __lsm_ro_after_init __ro_after_init | 2110 | #define __lsm_ro_after_init __ro_after_init |
| 2085 | #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */ | 2111 | #endif /* CONFIG_SECURITY_WRITABLE_HOOKS */ |
| 2086 | 2112 | ||
| 2087 | extern int __init security_module_enable(const char *module); | 2113 | extern int lsm_inode_alloc(struct inode *inode); |
| 2088 | extern void __init capability_add_hooks(void); | ||
| 2089 | #ifdef CONFIG_SECURITY_YAMA | ||
| 2090 | extern void __init yama_add_hooks(void); | ||
| 2091 | #else | ||
| 2092 | static inline void __init yama_add_hooks(void) { } | ||
| 2093 | #endif | ||
| 2094 | #ifdef CONFIG_SECURITY_LOADPIN | ||
| 2095 | void __init loadpin_add_hooks(void); | ||
| 2096 | #else | ||
| 2097 | static inline void loadpin_add_hooks(void) { }; | ||
| 2098 | #endif | ||
| 2099 | 2114 | ||
| 2100 | #endif /* ! __LINUX_LSM_HOOKS_H */ | 2115 | #endif /* ! __LINUX_LSM_HOOKS_H */ |
| @@ -54,9 +54,12 @@ struct xattr; · 53 unmodified lines | |||
| 54 | struct xfrm_sec_ctx; | 54 | struct xfrm_sec_ctx; |
| 55 | struct mm_struct; | 55 | struct mm_struct; |
| 56 | 56 | ||
| 57 | /* Default (no) options for the capable function */ | ||
| 58 | #define CAP_OPT_NONE 0x0 | ||
| 57 | /* If capable should audit the security request */ | 59 | /* If capable should audit the security request */ |
| 58 | #define SECURITY_CAP_NOAUDIT 0 | 60 | #define CAP_OPT_NOAUDIT BIT(1) |
| 59 | #define SECURITY_CAP_AUDIT 1 | 61 | /* If capable is being called by a setid function */ |
| 62 | #define CAP_OPT_INSETID BIT(2) | ||
| 60 | 63 | ||
| 61 | /* LSM Agnostic defines for sb_set_mnt_opts */ | 64 | /* LSM Agnostic defines for sb_set_mnt_opts */ |
| 62 | #define SECURITY_LSM_NATIVE_LABELS 1 | 65 | #define SECURITY_LSM_NATIVE_LABELS 1 |
| @@ -72,7 +75,7 @@ enum lsm_event { · 9 unmodified lines | |||
| 72 | 75 | ||
| 73 | /* These functions are in security/commoncap.c */ | 76 | /* These functions are in security/commoncap.c */ |
| 74 | extern int cap_capable(const struct cred *cred, struct user_namespace *ns, | 77 | extern int cap_capable(const struct cred *cred, struct user_namespace *ns, |
| 75 | int cap, int audit); | 78 | int cap, unsigned int opts); |
| 76 | extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz); | 79 | extern int cap_settime(const struct timespec64 *ts, const struct timezone *tz); |
| 77 | extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode); | 80 | extern int cap_ptrace_access_check(struct task_struct *child, unsigned int mode); |
| 78 | extern int cap_ptrace_traceme(struct task_struct *parent); | 81 | extern int cap_ptrace_traceme(struct task_struct *parent); |
| @@ -207,10 +210,10 @@ int security_capset(struct cred *new, const struct cred *old, · 128 unmodified lines | |||
| 207 | const kernel_cap_t *effective, | 210 | const kernel_cap_t *effective, |
| 208 | const kernel_cap_t *inheritable, | 211 | const kernel_cap_t *inheritable, |
| 209 | const kernel_cap_t *permitted); | 212 | const kernel_cap_t *permitted); |
| 210 | int security_capable(const struct cred *cred, struct user_namespace *ns, | 213 | int security_capable(const struct cred *cred, |
| 211 | int cap); | 214 | struct user_namespace *ns, |
| 212 | int security_capable_noaudit(const struct cred *cred, struct user_namespace *ns, | 215 | int cap, |
| 213 | int cap); | 216 | unsigned int opts); |
| 214 | int security_quotactl(int cmds, int type, int id, struct super_block *sb); | 217 | int security_quotactl(int cmds, int type, int id, struct super_block *sb); |
| 215 | int security_quota_on(struct dentry *dentry); | 218 | int security_quota_on(struct dentry *dentry); |
| 216 | int security_syslog(int type); | 219 | int security_syslog(int type); |
| @@ -366,8 +369,10 @@ int security_sem_semctl(struct kern_ipc_perm *sma, int cmd); · 149 unmodified lines | |||
| 366 | int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, | 369 | int security_sem_semop(struct kern_ipc_perm *sma, struct sembuf *sops, |
| 367 | unsigned nsops, int alter); | 370 | unsigned nsops, int alter); |
| 368 | void security_d_instantiate(struct dentry *dentry, struct inode *inode); | 371 | void security_d_instantiate(struct dentry *dentry, struct inode *inode); |
| 369 | int security_getprocattr(struct task_struct *p, char *name, char **value); | 372 | int security_getprocattr(struct task_struct *p, const char *lsm, char *name, |
| 370 | int security_setprocattr(const char *name, void *value, size_t size); | 373 | char **value); |
| 374 | int security_setprocattr(const char *lsm, const char *name, void *value, | ||
| 375 | size_t size); | ||
| 371 | int security_netlink_send(struct sock *sk, struct sk_buff *skb); | 376 | int security_netlink_send(struct sock *sk, struct sk_buff *skb); |
| 372 | int security_ismaclabel(const char *name); | 377 | int security_ismaclabel(const char *name); |
| 373 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); | 378 | int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen); |
| @@ -462,14 +467,11 @@ static inline int security_capset(struct cred *new, · 88 unmodified lines | |||
| 462 | } | 467 | } |
| 463 | 468 | ||
| 464 | static inline int security_capable(const struct cred *cred, | 469 | static inline int security_capable(const struct cred *cred, |
| 465 | struct user_namespace *ns, int cap) | 470 | struct user_namespace *ns, |
| 471 | int cap, | ||
| 472 | unsigned int opts) | ||
| 466 | { | 473 | { |
| 467 | return cap_capable(cred, ns, cap, SECURITY_CAP_AUDIT); | 474 | return cap_capable(cred, ns, cap, opts); |
| 468 | } | ||
| 469 | |||
| 470 | static inline int security_capable_noaudit(const struct cred *cred, | ||
| 471 | struct user_namespace *ns, int cap) { | ||
| 472 | return cap_capable(cred, ns, cap, SECURITY_CAP_NOAUDIT); | ||
| 473 | } | 475 | } |
| 474 | 476 | ||
| 475 | static inline int security_quotactl(int cmds, int type, int id, | 477 | static inline int security_quotactl(int cmds, int type, int id, |
| @@ -1112,15 +1114,18 @@ static inline int security_sem_semop(struct kern_ipc_perm *sma, · 636 unmodified lines | |||
| 1112 | return 0; | 1114 | return 0; |
| 1113 | } | 1115 | } |
| 1114 | 1116 | ||
| 1115 | static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode) | 1117 | static inline void security_d_instantiate(struct dentry *dentry, |
| 1118 | struct inode *inode) | ||
| 1116 | { } | 1119 | { } |
| 1117 | 1120 | ||
| 1118 | static inline int security_getprocattr(struct task_struct *p, char *name, char **value) | 1121 | static inline int security_getprocattr(struct task_struct *p, const char *lsm, |
| 1122 | char *name, char **value) | ||
| 1119 | { | 1123 | { |
| 1120 | return -EINVAL; | 1124 | return -EINVAL; |
| 1121 | } | 1125 | } |
| 1122 | 1126 | ||
| 1123 | static inline int security_setprocattr(char *name, void *value, size_t size) | 1127 | static inline int security_setprocattr(const char *lsm, char *name, |
| 1128 | void *value, size_t size) | ||
| 1124 | { | 1129 | { |
| 1125 | return -EINVAL; | 1130 | return -EINVAL; |
| 1126 | } | 1131 | } |
| @@ -1,35 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * SELinux services exported to the rest of the kernel. | ||
| 3 | * | ||
| 4 | * Author: James Morris <jmorris@redhat.com> | ||
| 5 | * | ||
| 6 | * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com> | ||
| 7 | * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com> | ||
| 8 | * Copyright (C) 2006 IBM Corporation, Timothy R. Chavez <tinytim@us.ibm.com> | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License version 2, | ||
| 12 | * as published by the Free Software Foundation. | ||
| 13 | */ | ||
| 14 | #ifndef _LINUX_SELINUX_H | ||
| 15 | #define _LINUX_SELINUX_H | ||
| 16 | |||
| 17 | struct selinux_audit_rule; | ||
| 18 | struct audit_context; | ||
| 19 | struct kern_ipc_perm; | ||
| 20 | |||
| 21 | #ifdef CONFIG_SECURITY_SELINUX | ||
| 22 | |||
| 23 | /** | ||
| 24 | * selinux_is_enabled - is SELinux enabled? | ||
| 25 | */ | ||
| 26 | bool selinux_is_enabled(void); | ||
| 27 | #else | ||
| 28 | |||
| 29 | static inline bool selinux_is_enabled(void) | ||
| 30 | { | ||
| 31 | return false; | ||
| 32 | } | ||
| 33 | #endif /* CONFIG_SECURITY_SELINUX */ | ||
| 34 | |||
| 35 | #endif /* _LINUX_SELINUX_H */ | ||