LSM: Add and use a hook for side-channel safety checks
Subsystems (5)
v3 cover LSM: Add and use a hook for side-channel safety checks
v3: get_task_cred wasn't a good choice due to refcounts.
Use lower level protection instead
v2: SELinux access policy corrected.
Use real_cred instead of cred.
This patchset provide a mechanism by which a security module can advise the system about potential side-channel vulnerabilities. If security_safe_sidechannel() returns 0 the security modules do not know of any data that would be subject to a side-channel attack. If the security module maintains data that it believes may be susceptible to a side-channel attack it will return -EACCES.
Simple hooks are provided for SELinux and Smack. A new security module is provided to make determinations regarding traditional task attributes, including user IDs, capability sets and namespaces.
--- MAINTAINERS | 6 ++ arch/x86/mm/tlb.c | 12 ++- include/linux/lsm_hooks.h | 12 +++ include/linux/security.h | 1 + security/Kconfig | 1 + security/Makefile | 2 + security/security.c | 6 ++ security/selinux/hooks.c | 9 +++ security/sidechannel/Kconfig | 60 ++++++++++++++ security/sidechannel/Makefile | 1 + security/sidechannel/sidechannel.c | 162 +++++++++++++++++++++++++++++++++++++ security/smack/smack_lsm.c | 18 +++++ 12 files changed, 286 insertions(+), 4 deletions(-)
PATCH v3 1/5 LSM: Introduce a hook for side-channel danger
There may be cases where the data maintained for security controls is more sensitive than general process information and that may be subjected to side-channel attacks. An LSM hook is provided so that this can be check for where the system would take action should the current task have potential access to the passed task.
--- include/linux/lsm_hooks.h | 7 +++++++ include/linux/security.h | 1 + security/security.c | 5 +++++ 3 files changed, 13 insertions(+)
include/linux/lsm_hooks.h +7 -0
@@ -698,6 +698,11 @@* security attributes, e.g. for /proc/pid inodes. * @p contains the task_struct for the task. * @inode contains the inode structure for the inode. +* @task_safe_sidechannel: +* Check if a side channel attack is harmless for the current task and @p. +* The caller may have determined that no attack is possible, in which +* case this hook won't get called. +* @p contains the task_struct for the task. * * Security hooks for Netlink messaging. *
@@ -1611,6 +1616,7 @@ union security_list_options {int (*task_prctl)(int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5);void (*task_to_inode)(struct task_struct *p,struct inode *inode); +int (*task_safe_sidechannel)(struct task_struct *p);int (*ipc_permission)(struct kern_ipc_perm *ipcp,short flag);void (*ipc_getsecid)(struct kern_ipc_perm *ipcp,u32 *secid);
@@ -1897,6 +1903,7 @@ struct security_hook_heads {struct hlist_head task_kill;struct hlist_head task_prctl;struct hlist_head task_to_inode; +struct hlist_head task_safe_sidechannel;struct hlist_head ipc_permission;struct hlist_head ipc_getsecid;struct hlist_head msg_msg_alloc_security;
include/linux/security.h +1 -0
@@ -366,6 +366,7 @@ int security_task_kill(struct task_struct *p, struct siginfo *info,int security_task_prctl (int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5);void security_task_to_inode (struct task_struct *p,struct inode *inode); +int security_task_safe_sidechannel (struct task_struct *p);int security_ipc_permission (struct kern_ipc_perm *ipcp,short flag);void security_ipc_getsecid (struct kern_ipc_perm *ipcp,u32 *secid);int security_msg_msg_alloc (struct msg_msg *msg);
security/security.c +5 -0
@@ -1165,6 +1165,11 @@ void security_task_to_inode(struct task_struct *p, struct inode *inode)call_void_hook (task_to_inode, p, inode); } +int security_task_safe_sidechannel (struct task_struct *p) +{ +return call_int_hook (task_safe_sidechannel,0 , p); +} +int security_ipc_permission (struct kern_ipc_perm *ipcp,short flag) {return call_int_hook (ipc_permission,0 , ipcp, flag);
Signature · 1 line
2.17.1
PATCH v3 2/5 X86: Support LSM determination of side-channel
In reply to Casey SchauflerWhen switching between tasks it may be necessary to set an indirect branch prediction barrier if the tasks are potentially vulnerable to side-channel attacks. This adds a call to security_task_safe_sidechannel so that security modules can weigh in on the decision.
--- arch/x86/mm/tlb.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch/x86/mm/tlb.c +8 -4
@@ -7,6 +7,7 @@#include <linux/export.h> #include <linux/cpu.h> #include <linux/debugfs.h> +#include <linux/security.h> #include <asm/tlbflush.h> #include <asm/mmu_context.h>
@@ -270,11 +271,14 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,* threads. It will also not flush if we switch to idle * thread and back to the same process. It will flush if we * switch to a different non-dumpable process. +* If a security module thinks that the transition +* is unsafe do the flush. */ -if (tsk && tsk->mm && - tsk->mm->context.ctx_id != last_ctx_id && -get_dumpable (tsk->mm) !=SUID_DUMP_USER ) -indirect_branch_prediction_barrier (); +if (tsk && tsk->mm && tsk->mm->context.ctx_id != last_ctx_id) { +if (get_dumpable (tsk->mm) !=SUID_DUMP_USER || +security_task_safe_sidechannel (tsk) !=0 ) +indirect_branch_prediction_barrier (); + }if (IS_ENABLED (CONFIG_VMAP_STACK )) {/*
Signature · 1 line
2.17.1
PATCH v3 3/5 LSM: Security module checking for side-channel dangers
In reply to Casey SchauflerThe sidechannel LSM checks for cases where a side-channel attack may be dangerous based on security attributes of tasks. This includes:
Effective UID of the tasks is different Capablity sets are different
Tasks are in different namespaces
An option is also provided to assert that task are never to be considered safe. This is high paranoia, and expensive as well.
--- MAINTAINERS | 6 ++ include/linux/lsm_hooks.h | 5 + security/Kconfig | 1 + security/Makefile | 2 + security/security.c | 1 + security/sidechannel/Kconfig | 60 +++++++++++ security/sidechannel/Makefile | 1 + security/sidechannel/sidechannel.c | 162 +++++++++++++++++++++++++++++ 8 files changed, 238 insertions(+) create mode 100644 security/sidechannel/Kconfig create mode 100644 security/sidechannel/Makefile create mode 100644 security/sidechannel/sidechannel.c
MAINTAINERS +6 -0
@@ -13066,6 +13066,12 @@ F: drivers/slimbus/ F: Documentation/devicetree/bindings/slimbus/ F: include/linux/slimbus.h +SIDECHANNEL SECURITY MODULE +M: Casey Schaufler <[email protected]> +L: [email protected] +S: Maintained +F: security/sidechannel/ + SMACK SECURITY MODULE M: Casey Schaufler <[email protected]> L: [email protected]
include/linux/lsm_hooks.h +5 -0
@@ -2088,5 +2088,10 @@ void __init loadpin_add_hooks(void);#else static inline void loadpin_add_hooks (void ) { };#endif +#ifdef CONFIG_SECURITY_SIDECHANNEL +void __init sidechannel_add_hooks (void ); +#else +static inline void sidechannel_add_hooks (void ) { }; +#endif #endif /* ! __LINUX_LSM_HOOKS_H */
security/Kconfig +1 -0
@@ -237,6 +237,7 @@ source security/tomoyo/Kconfig source security/apparmor/Kconfig source security/loadpin/Kconfig source security/yama/Kconfig +source security/sidechannel/Kconfig source security/integrity/Kconfig
security/Makefile +2 -0
@@ -10,6 +10,7 @@ subdir-$(CONFIG_SECURITY_TOMOYO) += tomoyo subdir-$(CONFIG_SECURITY_APPARMOR) += apparmor subdir-$(CONFIG_SECURITY_YAMA) += yama subdir-$(CONFIG_SECURITY_LOADPIN) += loadpin +subdir-$(CONFIG_SECURITY_SIDECHANNEL) += sidechannel # always enable default capabilities obj-y += commoncap.o
@@ -25,6 +26,7 @@ obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/ obj-$(CONFIG_SECURITY_APPARMOR) += apparmor/ obj-$(CONFIG_SECURITY_YAMA) += yama/ obj-$(CONFIG_SECURITY_LOADPIN) += loadpin/ +obj-$(CONFIG_SECURITY_SIDECHANNEL) += sidechannel/ obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o # Object integrity file lists
security/security.c +1 -0
@@ -80,6 +80,7 @@ int __init security_init(void)capability_add_hooks ();yama_add_hooks ();loadpin_add_hooks (); +sidechannel_add_hooks ();/* * Load all the remaining security modules.
security/sidechannel/Kconfig new file +60 -0
60 lines not on this page · raw message
security/sidechannel/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_SECURITY_SIDECHANNEL) += sidechannel.o
security/sidechannel/sidechannel.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v3 4/5 Smack: Support determination of side-channel
In reply to Casey SchauflerSmack considers its private task data safe if the current task has read access to the passed task.
--- security/smack/smack_lsm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
security/smack/smack_lsm.c +18 -0
@@ -2299,6 +2299,23 @@ static void smack_task_to_inode(struct task_struct *p, struct inode *inode) isp->smk_inode = skp; } +/** +* smack_task_safe_sidechannel - Are the task and current sidechannel safe? +* @p: task to check on +* +* A crude value for sidechannel safety is that the current task is +* already allowed to read from the other. +* +* Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. +*/ +static int smack_task_safe_sidechannel (struct task_struct *p) +{ +struct smack_known *skp =smk_of_task_struct (p); +struct smack_known *ckp =smk_of_task_struct (current); + +return smk_access (ckp, skp,MAY_READ ,NULL ); +} +/* * Socket hooks. */
@@ -4718,6 +4735,7 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_movememory, smack_task_movememory),LSM_HOOK_INIT (task_kill, smack_task_kill),LSM_HOOK_INIT (task_to_inode, smack_task_to_inode), +LSM_HOOK_INIT (task_safe_sidechannel, smack_task_safe_sidechannel),LSM_HOOK_INIT (ipc_permission, smack_ipc_permission), LSM_HOOK_INIT(ipc_getsecid, smack_ipc_getsecid),
Signature · 1 line
2.17.1
PATCH v3 5/5 SELinux: Support SELinux determination of side-channel
In reply to Casey SchauflerSELinux considers tasks to be side-channel safe if they have FILE__READ access.
--- security/selinux/hooks.c | 9 +++++++++ 1 file changed, 9 insertions(+)
security/selinux/hooks.c +9 -0
@@ -4219,6 +4219,14 @@ static void selinux_task_to_inode(struct task_struct *p,spin_unlock (&isec->lock); } +static int selinux_task_safe_sidechannel (struct task_struct *p) +{ +struct av_decision avd; + +return avc_has_perm_noaudit (&selinux_state,current_sid (),task_sid (p), +SECCLASS_FILE ,FILE__READ ,0 , &avd); +} +/* Returns error only if unable to parse addresses */ static int selinux_parse_skb_ipv4 (struct sk_buff *skb,struct common_audit_data *ad,u8 *proto)
@@ -7002,6 +7010,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (task_movememory, selinux_task_movememory),LSM_HOOK_INIT (task_kill, selinux_task_kill),LSM_HOOK_INIT (task_to_inode, selinux_task_to_inode), +LSM_HOOK_INIT (task_safe_sidechannel, selinux_task_safe_sidechannel),LSM_HOOK_INIT (ipc_permission, selinux_ipc_permission), LSM_HOOK_INIT(ipc_getsecid, selinux_ipc_getsecid),
Signature · 1 line
2.17.1
Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangers
In reply to Casey SchauflerQuoted 13 lines · Casey Schaufler
The sidechannel LSM checks for cases where a side-channel attack may be dangerous based on security attributes of tasks. This includes:
Effective UID of the tasks is different Capablity sets are different
Tasks are in different namespaces
An option is also provided to assert that task are never to be considered safe. This is high paranoia, and expensive as well.Signed-off-by Casey Schaufler <[email protected]>---
[...]
Quoted 5 lines
security/sidechannel/Kconfig new file +0
-0
[...]
Quoted 23 lines
security/sidechannel/Kconfig new file +23
-0+config SECURITY_SIDECHANNEL_CAPABILITIES + bool "Sidechannel check on capability sets" + depends on SECURITY_SIDECHANNEL + default n + help + Assume that tasks with different sets of privilege may be + subject to side-channel attacks. Potential interactions + where the attacker lacks capabilities the attacked has + are blocked. + + If you are unsure how to answer this question, answer N. + +config SECURITY_SIDECHANNEL_NAMESPACES + bool "Sidechannel check on namespaces" + depends on SECURITY_SIDECHANNEL + depends on NAMESPACES + default n + help + Assume that tasks in different namespaces may be + subject to side-channel attacks. User, PID and cgroup + namespaces are checked. + + If you are unsure how to answer this question, answer N.
[...]
Quoted 5 lines
security/sidechannel/sidechannel.c new file +0
-0
[...]
Quoted 11 lines
security/sidechannel/sidechannel.c new file +11
-0+/* +* safe_by_capability - Are task and current sidechannel safe? +* @p: task to check on +* +* Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. +*/ +#ifdef CONFIG_SECURITY_SIDECHANNEL_CAPABILITIES +static int safe_by_capability (struct task_struct *p) +{ +const struct cred *ccred =current_real_cred (); +const struct cred *pcred =rcu_dereference_protected (p->real_cred,1 );
security/sidechannel/sidechannel.c line 73
Quoted 10 lines
security/sidechannel/sidechannel.c new file +10
-0+ +/* +* Capabilities checks. Considered safe if: +* current has all the capabilities p does +*/ +if (ccred != pcred && + !cap_issubset (pcred->cap_effective, ccred->cap_effective)) +return -EACCES ; +return 0 ; +}
On its own (without safe_by_namespace()), this check makes no sense, I think. You're performing a test on the namespaced capability sets without looking at which user namespaces they are relative to. Maybe either introduce a configuration dependency or add an extra namespace check here?
Quoted 29 lines
security/sidechannel/sidechannel.c new file +29
-0+static int safe_by_namespace (struct task_struct *p) +{ +struct cgroup_namespace *ccgn =NULL ; +struct cgroup_namespace *pcgn =NULL ; +const struct cred *ccred; +const struct cred *pcred; + +/* +* Namespace checks. Considered safe if: +* cgroup namespace is the same +* User namespace is the same +* PID namespace is the same +*/ +if (current->nsproxy) + ccgn = current->nsproxy->cgroup_ns; +if (p->nsproxy) + pcgn = p->nsproxy->cgroup_ns; +if (ccgn != pcgn) +return -EACCES ; + + ccred =current_real_cred (); + pcred =rcu_dereference_protected (p->real_cred,1 ); + +if (ccred->user_ns != pcred->user_ns) +return -EACCES ; +if (task_active_pid_ns (current) !=task_active_pid_ns (p)) +return -EACCES ; +return 0 ; +}
RE: [PATCH v3 3/5] LSM: Security module checking for side-channel dangers
Quoted 84 lines
-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Tuesday, August 21, 2018 10:24 AM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangersQuoted 13 lines · Casey Schaufler
The sidechannel LSM checks for cases where a side-channel attack may be dangerous based on security attributes of tasks. This includes:
Effective UID of the tasks is different Capablity sets are different
Tasks are in different namespaces
An option is also provided to assert that task are never to be considered safe. This is high paranoia, and expensive as well.Signed-off-by Casey Schaufler <[email protected]>---
[...]
Quoted 5 lines
security/sidechannel/Kconfig new file +0
-0[...]
Quoted 23 lines
security/sidechannel/Kconfig new file +23
-0+config SECURITY_SIDECHANNEL_CAPABILITIES + bool "Sidechannel check on capability sets" + depends on SECURITY_SIDECHANNEL + default n + help + Assume that tasks with different sets of privilege may be + subject to side-channel attacks. Potential interactions + where the attacker lacks capabilities the attacked has + are blocked. + + If you are unsure how to answer this question, answer N. + +config SECURITY_SIDECHANNEL_NAMESPACES + bool "Sidechannel check on namespaces" + depends on SECURITY_SIDECHANNEL + depends on NAMESPACES + default n + help + Assume that tasks in different namespaces may be + subject to side-channel attacks. User, PID and cgroup + namespaces are checked. + + If you are unsure how to answer this question, answer N.[...]
Review
Quoted 1 line
(quoted diff) +0
-0
b/security/sidechannel/sidechannel.cQuoted 4 lines
new file mode 100644
index 000000000000..4da7d6dafdc5security/sidechannel/sidechannel.c new file +0
-0[...]
Quoted 19 lines
security/sidechannel/sidechannel.c new file +19
-0+/* +* safe_by_capability - Are task and current sidechannel safe? +* @p: task to check on +* +* Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. +*/ +#ifdef CONFIG_SECURITY_SIDECHANNEL_CAPABILITIES +static int safe_by_capability (struct task_struct *p) +{ +const struct cred *ccred =current_real_cred (); +const struct cred *pcred =rcu_dereference_protected (p->real_cred,1 ); + +/* +* Capabilities checks. Considered safe if: +* current has all the capabilities p does +*/ +if (ccred != pcred && + !cap_issubset (pcred->cap_effective, ccred->cap_effective)) +return -EACCES ;
Quoted 8 lines
security/sidechannel/sidechannel.c
Quoted 2 lines
security/sidechannel/sidechannel.c new file +2
-0+return 0 ; +}On its own (without
safe_by_namespace()), this check makes no sense, I think. You're performing a test on the namespaced capability sets without looking at which user namespaces they are relative to. Maybe either introduce a configuration dependency or add an extra namespace check here?
If you don't have namespaces the check is correct. If you do, and use safe_by_namespace() you're also correct. If you use namespaces and care about side-channel attacks you should enable the namespace checks. I don't see real value in adding namespace checks in the capability checks for the event where someone has said they don't want namespace checks.
I got early feedback that configurability was considered important. This is the correct behavior if you want namespace checks to be separately configurable from capability checks. You could ask for distinct configuration options for each kind of namespace, but, well, yuck.
Quoted 29 lines
Quoted 29 lines
security/sidechannel/sidechannel.c new file +29
-0+static int safe_by_namespace (struct task_struct *p) +{ +struct cgroup_namespace *ccgn =NULL ; +struct cgroup_namespace *pcgn =NULL ; +const struct cred *ccred; +const struct cred *pcred; + +/* +* Namespace checks. Considered safe if: +* cgroup namespace is the same +* User namespace is the same +* PID namespace is the same +*/ +if (current->nsproxy) + ccgn = current->nsproxy->cgroup_ns; +if (p->nsproxy) + pcgn = p->nsproxy->cgroup_ns; +if (ccgn != pcgn) +return -EACCES ; + + ccred =current_real_cred (); + pcred =rcu_dereference_protected (p->real_cred,1 ); + +if (ccred->user_ns != pcred->user_ns) +return -EACCES ; +if (task_active_pid_ns (current) !=task_active_pid_ns (p)) +return -EACCES ; +return 0 ; +}
Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangers
Quoted 94 lines · Casey
Quoted 85 lines
-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Tuesday, August 21, 2018 10:24 AM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangersQuoted 13 lines · Casey Schaufler
The sidechannel LSM checks for cases where a side-channel attack may be dangerous based on security attributes of tasks. This includes:
Effective UID of the tasks is different Capablity sets are different
Tasks are in different namespaces
An option is also provided to assert that task are never to be considered safe. This is high paranoia, and expensive as well.Signed-off-by Casey Schaufler <[email protected]>---
[...]
Quoted 5 lines
security/sidechannel/Kconfig new file +0
-0[...]
Quoted 23 lines
security/sidechannel/Kconfig new file +23
-0+config SECURITY_SIDECHANNEL_CAPABILITIES + bool "Sidechannel check on capability sets" + depends on SECURITY_SIDECHANNEL + default n + help + Assume that tasks with different sets of privilege may be + subject to side-channel attacks. Potential interactions + where the attacker lacks capabilities the attacked has + are blocked. + + If you are unsure how to answer this question, answer N. + +config SECURITY_SIDECHANNEL_NAMESPACES + bool "Sidechannel check on namespaces" + depends on SECURITY_SIDECHANNEL + depends on NAMESPACES + default n + help + Assume that tasks in different namespaces may be + subject to side-channel attacks. User, PID and cgroup + namespaces are checked. + + If you are unsure how to answer this question, answer N.[...]
Review
Quoted 1 line
(quoted diff) +0
-0
b/security/sidechannel/sidechannel.cQuoted 4 lines
new file mode 100644
index 000000000000..4da7d6dafdc5security/sidechannel/sidechannel.c new file +0
-0[...]
Quoted 19 lines
security/sidechannel/sidechannel.c new file +19
-0+/* +* safe_by_capability - Are task and current sidechannel safe? +* @p: task to check on +* +* Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. +*/ +#ifdef CONFIG_SECURITY_SIDECHANNEL_CAPABILITIES +static int safe_by_capability (struct task_struct *p) +{ +const struct cred *ccred =current_real_cred (); +const struct cred *pcred =rcu_dereference_protected (p->real_cred,1 ); + +/* +* Capabilities checks. Considered safe if: +* current has all the capabilities p does +*/ +if (ccred != pcred && + !cap_issubset (pcred->cap_effective, ccred->cap_effective)) +return -EACCES ;Quoted 8 lines
security/sidechannel/sidechannel.c
Quoted 2 lines
security/sidechannel/sidechannel.c new file +2
-0+return 0 ; +}On its own (without
safe_by_namespace()), this check makes no sense, I think. You're performing a test on the namespaced capability sets without looking at which user namespaces they are relative to. Maybe either introduce a configuration dependency or add an extra namespace check here?
Quoted 3 lines
If you don't have namespaces the check is correct. If you do, and use
safe_by_namespace()you're also correct. If you use namespaces and care about side-channel attacks you should enable the namespace checks.
By "use namespaces", you mean "have CONFIG_USER_NS=y set in the kernel config", right?
It doesn't matter much whether processes on your system are intentionally using namespaces; what matters is whether some random process can just use unshare(CLONE_NEWUSER) to increase its apparent capabilities and bypass the checks performed by this LSM. My expectation is that unshare(CLONE_NEWUSER) should not increase the caller's abilities. Your patch seems to violate that expectation.
Quoted 2 lines
I don't see real value in adding namespace checks in the capability checks for the event where someone has said they don't want namespace checks.
Capabilities are meaningless if you don't consider the namespaces relative to which they are effective. Anyone can get CAP_SYS_ADMIN or whatever other capabilities they want, by design - just not relative to objects they don't own. Look:
$ grep ^Cap /proc/self/status CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000003fffffffff CapAmb: 0000000000000000 $ unshare -Ur grep ^Cap /proc/self/status CapInh: 0000000000000000 CapPrm: 0000003fffffffff CapEff: 0000003fffffffff CapBnd: 0000003fffffffff CapAmb: 0000000000000000
Ta-daa! Full capability set.
Quoted 34 lines
I got early feedback that configurability was considered important. This is the correct behavior if you want namespace checks to be separately configurable from capability checks. You could ask for distinct configuration options for each kind of namespace, but, well, yuck.
Quoted 29 lines
Quoted 29 lines
security/sidechannel/sidechannel.c new file +29
-0+static int safe_by_namespace (struct task_struct *p) +{ +struct cgroup_namespace *ccgn =NULL ; +struct cgroup_namespace *pcgn =NULL ; +const struct cred *ccred; +const struct cred *pcred; + +/* +* Namespace checks. Considered safe if: +* cgroup namespace is the same +* User namespace is the same +* PID namespace is the same +*/ +if (current->nsproxy) + ccgn = current->nsproxy->cgroup_ns; +if (p->nsproxy) + pcgn = p->nsproxy->cgroup_ns; +if (ccgn != pcgn) +return -EACCES ; + + ccred =current_real_cred (); + pcred =rcu_dereference_protected (p->real_cred,1 ); + +if (ccred->user_ns != pcred->user_ns) +return -EACCES ; +if (task_active_pid_ns (current) !=task_active_pid_ns (p)) +return -EACCES ; +return 0 ; +}
RE: [PATCH v3 3/5] LSM: Security module checking for side-channel dangers
Quoted 109 lines
-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Tuesday, August 21, 2018 6:01 PM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangersQuoted 66 lines · Casey
Quoted 66 lines
-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Tuesday, August 21, 2018 10:24 AM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangersQuoted 13 lines · Casey Schaufler
The sidechannel LSM checks for cases where a side-channel attack may be dangerous based on security attributes of tasks. This includes:
Effective UID of the tasks is different Capablity sets are different
Tasks are in different namespaces
An option is also provided to assert that task are never to be considered safe. This is high paranoia, and expensive as well.Signed-off-by Casey Schaufler <[email protected]>---
[...]
Quoted 5 lines
security/sidechannel/Kconfig new file +0
-0[...]
Quoted 23 lines
security/sidechannel/Kconfig new file +23
-0+config SECURITY_SIDECHANNEL_CAPABILITIES + bool "Sidechannel check on capability sets" + depends on SECURITY_SIDECHANNEL + default n + help + Assume that tasks with different sets of privilege may be + subject to side-channel attacks. Potential interactions + where the attacker lacks capabilities the attacked has + are blocked. + + If you are unsure how to answer this question, answer N. + +config SECURITY_SIDECHANNEL_NAMESPACES + bool "Sidechannel check on namespaces" + depends on SECURITY_SIDECHANNEL + depends on NAMESPACES + default n + help + Assume that tasks in different namespaces may be + subject to side-channel attacks. User, PID and cgroup + namespaces are checked. + + If you are unsure how to answer this question, answer N.[...]
Review
Quoted 1 line
(quoted diff) +0
-0
b/security/sidechannel/sidechannel.cQuoted 4 lines
new file mode 100644
index 000000000000..4da7d6dafdc5security/sidechannel/sidechannel.c new file +0
-0[...]
Quoted 11 lines
Quoted 11 lines
security/sidechannel/sidechannel.c
Quoted 11 lines
security/sidechannel/sidechannel.c new file +11
-0+/* +* safe_by_capability - Are task and current sidechannel safe? +* @p: task to check on +* +* Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. +*/ +#ifdef CONFIG_SECURITY_SIDECHANNEL_CAPABILITIES +static int safe_by_capability (struct task_struct *p) +{ +const struct cred *ccred =current_real_cred (); + const struct cred *pcred = rcu_dereference_protected(p->real_cred,1);
Quoted 17 lines
Quoted 16 lines
security/sidechannel/sidechannel.c line 73
Quoted 10 lines
security/sidechannel/sidechannel.c new file +10
-0+ +/* +* Capabilities checks. Considered safe if: +* current has all the capabilities p does +*/ +if (ccred != pcred && + !cap_issubset (pcred->cap_effective, ccred->cap_effective)) +return -EACCES ; +return 0 ; +}On its own (without
safe_by_namespace()), this check makes no sense, I think. You're performing a test on the namespaced capability sets without looking at which user namespaces they are relative to. Maybe either introduce a configuration dependency or add an extra namespace check here?
Quoted 6 lines
Quoted 3 lines
If you don't have namespaces the check is correct. If you do, and use
safe_by_namespace()you're also correct. If you use namespaces and care about side-channel attacks you should enable the namespace checks.By "use namespaces", you mean "have
CONFIG_USER_NS=yset in the kernel config", right?
That's correct.
Quoted 2 lines
It doesn't matter much whether processes on your system are intentionally using namespaces;
Also correct.
Quoted 3 lines
what matters is whether some random
process can just useunshare(CLONE_NEWUSER)to increase its apparent capabilities and bypass the checks performed by this LSM.
Which puts it in a new user namespace, which gets caught by the safe_by_namespace() check.
Quoted 2 lines
My expectation is that
unshare(CLONE_NEWUSER)should not increase the caller's abilities. Your patch seems to violate that expectation.
If you have CONFIG_USER_NS and not CONFIG_SECURITY_SIDECHANNEL_NAMESPACES you do not increase the caller's abilities from what you have without safesidechannel. If you have CONFIG_SECURITY_SIDECHANNEL_NAMESPACES you have additional restriction (assuming one considers setting the barrier a restriction) that the tasks must be in the same namespace(s). As I said, if you care about namespace implications you should configure the system accordingly.
Quoted 5 lines
Quoted 2 lines
I don't see real value in adding namespace checks in the capability checks for the event where someone has said they don't want namespace checks.
Capabilities are meaningless if you don't consider the namespaces relative to which they are effective.
Agreed. But if CONFIG_NAMESPACES is off you are always in the same namespace and if it is on you should use the sidechannel namespace check.
Quoted 17 lines
Anyone can get
CAP_SYS_ADMINor
whatever other capabilities they want, by design - just not relative to objects they don't own. Look:$ grep ^Cap /proc/self/status CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000003fffffffff CapAmb: 0000000000000000 $ unshare -Ur grep ^Cap /proc/self/status CapInh: 0000000000000000 CapPrm: 0000003fffffffff CapEff: 0000003fffffffff CapBnd: 0000003fffffffff CapAmb: 0000000000000000
Quoted 1 line
Ta-daa! Full capability set.
Yes, but in a different namespace. Hence the namespace check.
What I hear you saying is that you don't want the capability check to be independent of the namespace check. This conflicts with the strong desire expressed to me when I started this that the configuration should be flexible. I can beef up the description of the various options. Would that address the issue?
Quoted 35 lines
Quoted 35 lines
I got early feedback that configurability was considered important. This is the correct behavior if you want namespace checks to be separately configurable from capability checks. You could ask for distinct configuration options for each kind of namespace, but, well, yuck.
Quoted 29 lines
Quoted 29 lines
security/sidechannel/sidechannel.c new file +29
-0+static int safe_by_namespace (struct task_struct *p) +{ +struct cgroup_namespace *ccgn =NULL ; +struct cgroup_namespace *pcgn =NULL ; +const struct cred *ccred; +const struct cred *pcred; + +/* +* Namespace checks. Considered safe if: +* cgroup namespace is the same +* User namespace is the same +* PID namespace is the same +*/ +if (current->nsproxy) + ccgn = current->nsproxy->cgroup_ns; +if (p->nsproxy) + pcgn = p->nsproxy->cgroup_ns; +if (ccgn != pcgn) +return -EACCES ; + + ccred =current_real_cred (); + pcred =rcu_dereference_protected (p->real_cred,1 ); + +if (ccred->user_ns != pcred->user_ns) +return -EACCES ; +if (task_active_pid_ns (current) !=task_active_pid_ns (p)) +return -EACCES ; +return 0 ; +}
Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangers
Quoted 168 lines · Casey
Quoted 110 lines
-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Tuesday, August 21, 2018 6:01 PM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangersQuoted 66 lines · Casey
Quoted 66 lines
-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Tuesday, August 21, 2018 10:24 AM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangersQuoted 13 lines · Casey Schaufler
The sidechannel LSM checks for cases where a side-channel attack may be dangerous based on security attributes of tasks. This includes:
Effective UID of the tasks is different Capablity sets are different
Tasks are in different namespaces
An option is also provided to assert that task are never to be considered safe. This is high paranoia, and expensive as well.Signed-off-by Casey Schaufler <[email protected]>---
[...]
Quoted 5 lines
security/sidechannel/Kconfig new file +0
-0[...]
Quoted 23 lines
security/sidechannel/Kconfig new file +23
-0+config SECURITY_SIDECHANNEL_CAPABILITIES + bool "Sidechannel check on capability sets" + depends on SECURITY_SIDECHANNEL + default n + help + Assume that tasks with different sets of privilege may be + subject to side-channel attacks. Potential interactions + where the attacker lacks capabilities the attacked has + are blocked. + + If you are unsure how to answer this question, answer N. + +config SECURITY_SIDECHANNEL_NAMESPACES + bool "Sidechannel check on namespaces" + depends on SECURITY_SIDECHANNEL + depends on NAMESPACES + default n + help + Assume that tasks in different namespaces may be + subject to side-channel attacks. User, PID and cgroup + namespaces are checked. + + If you are unsure how to answer this question, answer N.[...]
Review
Quoted 1 line
(quoted diff) +0
-0
b/security/sidechannel/sidechannel.cQuoted 4 lines
new file mode 100644
index 000000000000..4da7d6dafdc5security/sidechannel/sidechannel.c new file +0
-0[...]
Quoted 11 lines
Quoted 11 lines
security/sidechannel/sidechannel.c
Quoted 11 lines
security/sidechannel/sidechannel.c new file +11
-0+/* +* safe_by_capability - Are task and current sidechannel safe? +* @p: task to check on +* +* Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. +*/ +#ifdef CONFIG_SECURITY_SIDECHANNEL_CAPABILITIES +static int safe_by_capability (struct task_struct *p) +{ +const struct cred *ccred =current_real_cred (); + const struct cred *pcred = rcu_dereference_protected(p->real_cred,1);
Quoted 17 lines
Quoted 16 lines
security/sidechannel/sidechannel.c line 73
Quoted 10 lines
security/sidechannel/sidechannel.c new file +10
-0+ +/* +* Capabilities checks. Considered safe if: +* current has all the capabilities p does +*/ +if (ccred != pcred && + !cap_issubset (pcred->cap_effective, ccred->cap_effective)) +return -EACCES ; +return 0 ; +}On its own (without
safe_by_namespace()), this check makes no sense, I think. You're performing a test on the namespaced capability sets without looking at which user namespaces they are relative to. Maybe either introduce a configuration dependency or add an extra namespace check here?Quoted 6 lines
Quoted 3 lines
If you don't have namespaces the check is correct. If you do, and use
safe_by_namespace()you're also correct. If you use namespaces and care about side-channel attacks you should enable the namespace checks.By "use namespaces", you mean "have
CONFIG_USER_NS=yset in the kernel config", right?That's correct.
Quoted 2 lines
It doesn't matter much whether processes on your system are intentionally using namespaces;
Also correct.
Quoted 3 lines
what matters is whether some random
process can just useunshare(CLONE_NEWUSER)to increase its apparent capabilities and bypass the checks performed by this LSM.Which puts it in a new user namespace, which gets caught by the
safe_by_namespace()check.Quoted 2 lines
My expectation is that
unshare(CLONE_NEWUSER)should not increase the caller's abilities. Your patch seems to violate that expectation.If you have
CONFIG_USER_NSand notCONFIG_SECURITY_SIDECHANNEL_NAMESPACESyou do not increase the caller's abilities from what you have without safesidechannel. If you haveCONFIG_SECURITY_SIDECHANNEL_NAMESPACESyou have additional restriction (assuming one considers setting the barrier a restriction) that the tasks must be in the same namespace(s). As I said, if you care about namespace implications you should configure the system accordingly.Quoted 5 lines
Quoted 2 lines
I don't see real value in adding namespace checks in the capability checks for the event where someone has said they don't want namespace checks.
Capabilities are meaningless if you don't consider the namespaces relative to which they are effective.
Agreed. But if
CONFIG_NAMESPACESis off you are always in the same namespace and if it is on you should use the sidechannel namespace check.Quoted 17 lines
Anyone can get
CAP_SYS_ADMINor
whatever other capabilities they want, by design - just not relative to objects they don't own. Look:$ grep ^Cap /proc/self/status CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000003fffffffff CapAmb: 0000000000000000 $ unshare -Ur grep ^Cap /proc/self/status CapInh: 0000000000000000 CapPrm: 0000003fffffffff CapEff: 0000003fffffffff CapBnd: 0000003fffffffff CapAmb: 0000000000000000
Quoted 6 lines
Quoted 1 line
Ta-daa! Full capability set.
Yes, but in a different namespace. Hence the namespace check.
What I hear you saying is that you don't want the capability check to be independent of the namespace check.
The capability check doesn't always require a namespace match, and I don't care about non-user namespaces here, but I would prefer it if A->B with A having some capabilities required A's user namespace to be ancestor-or-self of B's user namespace. But alternatively:
Quoted 4 lines
This conflicts with the
strong desire expressed to me when I started this that the configuration should be flexible. I can beef up the description of the various options. Would that address the issue?
It seems to me that it would make sense to express this as something like a Kconfig dependency. But I guess if you document that the combination of CONFIG_USER_NS=y, CONFIG_SECURITY_SIDECHANNEL_NAMESPACES=n and SECURITY_SIDECHANNEL_CAPABILITIES=y is nonsensical, that works too. I just don't see why you'd want to provide such a footgun? Configurability is nice, but if we know that one of the possible configurations doesn't make sense, it seems like a good idea to just not allow the system to be configured that way.
You say that you were asked to make the configuration flexible. Did whoever told you that actually want the ability to compare raw capability sets on a system with CONFIG_USER_NS=y, and understand what semantics that has (and doesn't have)? Or was their intent more along the lines of "we want to flush if the new task has higher privileges, capability-wise, than the old task; but we don't explicitly care about namespaces"?
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
I got early feedback that configurability was considered important. This is the correct behavior if you want namespace checks to be separately configurable from capability checks. You could ask for distinct configuration options for each kind of namespace, but, well, yuck.
Quoted 29 lines
Quoted 29 lines
security/sidechannel/sidechannel.c new file +29
-0+static int safe_by_namespace (struct task_struct *p) +{ +struct cgroup_namespace *ccgn =NULL ; +struct cgroup_namespace *pcgn =NULL ; +const struct cred *ccred; +const struct cred *pcred; + +/* +* Namespace checks. Considered safe if: +* cgroup namespace is the same +* User namespace is the same +* PID namespace is the same +*/ +if (current->nsproxy) + ccgn = current->nsproxy->cgroup_ns; +if (p->nsproxy) + pcgn = p->nsproxy->cgroup_ns; +if (ccgn != pcgn) +return -EACCES ; + + ccred =current_real_cred (); + pcred =rcu_dereference_protected (p->real_cred,1 ); + +if (ccred->user_ns != pcred->user_ns) +return -EACCES ; +if (task_active_pid_ns (current) !=task_active_pid_ns (p)) +return -EACCES ; +return 0 ; +}
RE: [PATCH v3 3/5] LSM: Security module checking for side-channel dangers
Quoted 16 lines
-----Original Message-----
From: Jann Horn [mailto:[email protected]]
Sent: Wednesday, August 22, 2018 10:04 AM
To: Schaufler, Casey <[email protected]>
Cc: Kernel Hardening <[email protected]>; kernel list <[email protected]>; linux-security-module <linux-security- [email protected]>; [email protected]; Hansen, Dave <[email protected]>; Dock, Deneen T <[email protected]>; [email protected]; Arjan van de Ven <[email protected]>
Subject: Re: [PATCH v3 3/5] LSM: Security module checking for side-channel dangers[SNIP]
Quoted 2 lines
Yes, but in a different namespace. Hence the namespace check.
Quoted 7 lines
Quoted 2 lines
What I hear you saying is that you don't want the capability check to be independent of the namespace check.
The capability check doesn't always require a namespace match, and I don't care about non-user namespaces here, but I would prefer it if
A->Bwith A having some capabilities required A's user namespace to be ancestor-or-self of B's user namespace. But alternatively:
Looking at ancestor relations starts to get us pretty close to the point where the cost of checking will overwhelm the savings. This is something we have to be very careful of.
Quoted 7 lines
Quoted 4 lines
This conflicts with the
strong desire expressed to me when I started this that the configuration should be flexible. I can beef up the description of the various options. Would that address the issue?It seems to me that it would make sense to express this as something like a
Kconfigdependency.
I thought about that. It could be the best choice. I will investigate further.
Quoted 5 lines
But I guess if you document that the
combination ofCONFIG_USER_NS=y,CONFIG_SECURITY_SIDECHANNEL_NAMESPACES=nand SECURITY_SIDECHANNEL_CAPABILITIES=y is nonsensical, that works too. I just don't see why you'd want to provide such a footgun?
Point.
Quoted 3 lines
Configurability is nice, but if we know that one of the possible configurations doesn't make sense, it seems like a good idea to just not allow the system to be configured that way.
Another point.
Quoted 7 lines
You say that you were asked to make the configuration flexible. Did whoever told you that actually want the ability to compare raw capability sets on a system with
CONFIG_USER_NS=y, and understand what semantics that has (and doesn't have)? Or was their intent more along the lines of "we want to flush if the new task has higher privileges, capability-wise, than the old task; but we don't explicitly care about namespaces"?
Without going into too much detail, it's a matter of people who understand chips and performance better than they understand security or the user experience.