From patchwork Wed Aug 15 23:53:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schaufler, Casey" X-Patchwork-Id: 10567257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80DE0921 for ; Thu, 16 Aug 2018 09:51:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DE8428733 for ; Thu, 16 Aug 2018 09:51:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6186F2AB2E; Thu, 16 Aug 2018 09:51:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 743E728733 for ; Thu, 16 Aug 2018 09:51:36 +0000 (UTC) Received: (qmail 16014 invoked by uid 550); 16 Aug 2018 09:51:34 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 11714 invoked from network); 15 Aug 2018 23:54:10 -0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,245,1531810800"; d="scan'208";a="75694061" From: Casey Schaufler To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, SMACK-discuss@lists.01.org, casey.schaufler@intel.com, dave.hansen@intel.com, deneen.t.dock@intel.com, kristen@linux.intel.com, arjan@linux.intel.com Subject: [PATCH RFC 1/5] LSM: Introduce a hook for side-channel danger Date: Wed, 15 Aug 2018 16:53:51 -0700 Message-Id: <20180815235355.14908-2-casey.schaufler@intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180815235355.14908-1-casey.schaufler@intel.com> References: <20180815235355.14908-1-casey.schaufler@intel.com> X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler 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. Signed-off-by: Casey Schaufler --- include/linux/lsm_hooks.h | 7 +++++++ include/linux/security.h | 1 + security/security.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index a08bc2587b96..fd2a7e6beb01 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -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; diff --git a/include/linux/security.h b/include/linux/security.h index 3410acfe139c..69a5526f789f 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -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); diff --git a/security/security.c b/security/security.c index 4927e7cc7d96..353b711e635a 100644 --- a/security/security.c +++ b/security/security.c @@ -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); From patchwork Wed Aug 15 23:53:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schaufler, Casey" X-Patchwork-Id: 10567261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC2D25A4 for ; Thu, 16 Aug 2018 09:51:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8A0928733 for ; Thu, 16 Aug 2018 09:51:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC4672AB2E; Thu, 16 Aug 2018 09:51:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id E387E28733 for ; Thu, 16 Aug 2018 09:51:42 +0000 (UTC) Received: (qmail 16333 invoked by uid 550); 16 Aug 2018 09:51:38 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 11754 invoked from network); 15 Aug 2018 23:54:10 -0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,245,1531810800"; d="scan'208";a="75694064" From: Casey Schaufler To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, SMACK-discuss@lists.01.org, casey.schaufler@intel.com, dave.hansen@intel.com, deneen.t.dock@intel.com, kristen@linux.intel.com, arjan@linux.intel.com Subject: [PATCH RFC 2/5] X86: Support LSM determination of side-channel vulnerability Date: Wed, 15 Aug 2018 16:53:52 -0700 Message-Id: <20180815235355.14908-3-casey.schaufler@intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180815235355.14908-1-casey.schaufler@intel.com> References: <20180815235355.14908-1-casey.schaufler@intel.com> X-Virus-Scanned: ClamAV using ClamSMTP From: Casey Schaufler When 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. Signed-off-by: Casey Schaufler --- arch/x86/mm/tlb.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 6eb1f34c3c85..8714d4af06aa 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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)) { /* From patchwork Wed Aug 15 23:53:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schaufler, Casey" X-Patchwork-Id: 10567265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19822921 for ; Thu, 16 Aug 2018 09:51:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0425728733 for ; Thu, 16 Aug 2018 09:51:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECAB62AB2E; Thu, 16 Aug 2018 09:51:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 7913228733 for ; Thu, 16 Aug 2018 09:51:51 +0000 (UTC) Received: (qmail 17857 invoked by uid 550); 16 Aug 2018 09:51:43 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 11787 invoked from network); 15 Aug 2018 23:54:11 -0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,245,1531810800"; d="scan'208";a="75694067" From: Casey Schaufler To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, SMACK-discuss@lists.01.org, casey.schaufler@intel.com, dave.hansen@intel.com, deneen.t.dock@intel.com, kristen@linux.intel.com, arjan@linux.intel.com Subject: [PATCH RFC 3/5] LSM: Security module checking for side-channel dangers Date: Wed, 15 Aug 2018 16:53:53 -0700 Message-Id: <20180815235355.14908-4-casey.schaufler@intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180815235355.14908-1-casey.schaufler@intel.com> References: <20180815235355.14908-1-casey.schaufler@intel.com> X-Virus-Scanned: ClamAV using ClamSMTP From: 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 --- 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 | 156 +++++++++++++++++++++++++++++ 8 files changed, 232 insertions(+) create mode 100644 security/sidechannel/Kconfig create mode 100644 security/sidechannel/Makefile create mode 100644 security/sidechannel/sidechannel.c diff --git a/MAINTAINERS b/MAINTAINERS index 3119bba7971c..d078d6a5b471 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13066,6 +13066,12 @@ F: drivers/slimbus/ F: Documentation/devicetree/bindings/slimbus/ F: include/linux/slimbus.h +SIDECHANNEL SECURITY MODULE +M: Casey Schaufler +L: linux-security-module@vger.kernel.org +S: Maintained +F: security/sidechannel/ + SMACK SECURITY MODULE M: Casey Schaufler L: linux-security-module@vger.kernel.org diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index fd2a7e6beb01..d48e4a085fe2 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -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 */ diff --git a/security/Kconfig b/security/Kconfig index c4302067a3ad..28cb7b2939ee 100644 --- a/security/Kconfig +++ b/security/Kconfig @@ -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 diff --git a/security/Makefile b/security/Makefile index 4d2d3782ddef..d0c9e1b227f9 100644 --- a/security/Makefile +++ b/security/Makefile @@ -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 diff --git a/security/security.c b/security/security.c index 353b711e635a..777919349751 100644 --- a/security/security.c +++ b/security/security.c @@ -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. diff --git a/security/sidechannel/Kconfig b/security/sidechannel/Kconfig new file mode 100644 index 000000000000..af9396534128 --- /dev/null +++ b/security/sidechannel/Kconfig @@ -0,0 +1,60 @@ +config SECURITY_SIDECHANNEL + bool "Sidechannel attack safety extra checks" + depends on SECURITY + default n + help + Look for a variety of cases where a side-channel attack + could potentially be exploited. Instruct the switching + code to use the indirect_branch_prediction_barrier in + cases where the passed task and the current task may be + at risk. + + If you are unsure how to answer this question, answer N. + +config SECURITY_SIDECHANNEL_UIDS + bool "Sidechannel check on UID" + depends on SECURITY_SIDECHANNEL + default n + help + Assume that tasks with different effective UIDs may be + subject to side-channel attacks. As most task switching + occurs between tasks with different effective UIDs this + can have a significant performance impact. + + If you are unsure how to answer this question, answer N. + + +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. + +config SECURITY_SIDECHANNEL_ALWAYS + bool "Sidechannel assumed to always be possible" + depends on SECURITY_SIDECHANNEL + default n + help + Assume that all tasks may be subject to side-channel attacks. + Always instruct the system to use countermeasures regardless + of the potential impact. + + If you are unsure how to answer this question, answer N. diff --git a/security/sidechannel/Makefile b/security/sidechannel/Makefile new file mode 100644 index 000000000000..f61d83f28035 --- /dev/null +++ b/security/sidechannel/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_SECURITY_SIDECHANNEL) += sidechannel.o diff --git a/security/sidechannel/sidechannel.c b/security/sidechannel/sidechannel.c new file mode 100644 index 000000000000..9dc875611bd8 --- /dev/null +++ b/security/sidechannel/sidechannel.c @@ -0,0 +1,156 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Side Channel Safety Security Module + * + * Copyright (C) 2018 Intel Corporation. + * + */ + +#define pr_fmt(fmt) "SideChannel: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_SECURITY_SIDECHANNEL_ALWAYS +static int sidechannel_task_safe_sidechannel(struct task_struct *p) +{ + return -EACCES; +} +#else +/* + * safe_by_uid - 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_UIDS +static int safe_by_uid(struct task_struct *p) +{ + const struct cred *ccred = current->cred; + const struct cred *pcred = p->cred; + + /* + * Credential checks. Considered safe if: + * UIDs are the same + */ + if (ccred != pcred && ccred->euid.val != pcred->euid.val) + return -EACCES; + return 0; +} +#else +static inline int safe_by_uid(struct task_struct *p) +{ + return 0; +} +#endif + +/* + * 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->cred; + const struct cred *pcred = p->cred; + + /* + * 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; +} +#else +static inline int safe_by_capability(struct task_struct *p) +{ + return 0; +} +#endif + +#ifdef CONFIG_SECURITY_SIDECHANNEL_NAMESPACES +/** + * safe_by_namespace - Are task and current sidechannel safe? + * @p: task to check on + * + * Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. + */ +static int safe_by_namespace(struct task_struct *p) +{ + struct cgroup_namespace *ccgn = NULL; + struct cgroup_namespace *pcgn = NULL; + + /* + * 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; + if (current->cred->user_ns != p->cred->user_ns) + return -EACCES; + if (task_active_pid_ns(current) != task_active_pid_ns(p)) + return -EACCES; + return 0; +} +#else +static inline int safe_by_namespace(struct task_struct *p) +{ + return 0; +} +#endif + +/** + * sidechannel_task_safe_sidechannel - Are task and current sidechannel safe? + * @p: task to check on + * + * Returns 0 if the tasks are sidechannel safe, -EACCES otherwise. + */ +static int sidechannel_task_safe_sidechannel(struct task_struct *p) +{ + int rc; + + /* + * Easy optimizations + */ + if (p == current || p->pid == current->pid) + return 0; + + rc = safe_by_uid(p); + if (rc) + return rc; + rc = safe_by_capability(p); + if (rc) + return rc; + rc = safe_by_namespace(p); + if (rc) + return rc; + return 0; +} +#endif /* CONFIG_SECURITY_SIDECHANNEL_ALWAYS */ + +static struct security_hook_list sidechannel_hooks[] __lsm_ro_after_init = { + LSM_HOOK_INIT(task_safe_sidechannel, sidechannel_task_safe_sidechannel), +}; + +void __init sidechannel_add_hooks(void) +{ + pr_info("Extra sidechannel checks enabled\n"); + security_add_hooks(sidechannel_hooks, ARRAY_SIZE(sidechannel_hooks), + "sidechannel"); +} From patchwork Wed Aug 15 23:53:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schaufler, Casey" X-Patchwork-Id: 10567269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8B9A5A4 for ; Thu, 16 Aug 2018 09:52:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D63D028733 for ; Thu, 16 Aug 2018 09:52:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA4572AB2E; Thu, 16 Aug 2018 09:52:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id ED5D828733 for ; Thu, 16 Aug 2018 09:52:15 +0000 (UTC) Received: (qmail 20179 invoked by uid 550); 16 Aug 2018 09:52:02 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 11829 invoked from network); 15 Aug 2018 23:54:13 -0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,245,1531810800"; d="scan'208";a="75694071" From: Casey Schaufler To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, SMACK-discuss@lists.01.org, casey.schaufler@intel.com, dave.hansen@intel.com, deneen.t.dock@intel.com, kristen@linux.intel.com, arjan@linux.intel.com Subject: [PATCH RFC 4/5] Smack: Support determination of side-channel vulnerability Date: Wed, 15 Aug 2018 16:53:54 -0700 Message-Id: <20180815235355.14908-5-casey.schaufler@intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180815235355.14908-1-casey.schaufler@intel.com> References: <20180815235355.14908-1-casey.schaufler@intel.com> X-Virus-Scanned: ClamAV using ClamSMTP Smack considers its private task data safe if the current task has read access to the passed task. Signed-off-by: Casey Schaufler --- security/smack/smack_lsm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 91750205a5de..85dc053e610c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -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), From patchwork Wed Aug 15 23:53:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schaufler, Casey" X-Patchwork-Id: 10567267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15090921 for ; Thu, 16 Aug 2018 09:52:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01A0A28733 for ; Thu, 16 Aug 2018 09:52:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E834D2AB2E; Thu, 16 Aug 2018 09:52:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id E6B0C28733 for ; Thu, 16 Aug 2018 09:52:03 +0000 (UTC) Received: (qmail 20168 invoked by uid 550); 16 Aug 2018 09:52:01 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 11863 invoked from network); 15 Aug 2018 23:54:14 -0000 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,245,1531810800"; d="scan'208";a="75694074" From: Casey Schaufler To: kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, SMACK-discuss@lists.01.org, casey.schaufler@intel.com, dave.hansen@intel.com, deneen.t.dock@intel.com, kristen@linux.intel.com, arjan@linux.intel.com Subject: [PATCH RFC 5/5] SELinux: Support SELinux determination of side-channel vulnerability Date: Wed, 15 Aug 2018 16:53:55 -0700 Message-Id: <20180815235355.14908-6-casey.schaufler@intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180815235355.14908-1-casey.schaufler@intel.com> References: <20180815235355.14908-1-casey.schaufler@intel.com> X-Virus-Scanned: ClamAV using ClamSMTP SELinux considers tasks to be side-channel safe if they have PROCESS_SHARE access. Signed-off-by: Casey Schaufler --- security/selinux/hooks.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index a8bf324130f5..7fbd7d7ac1cb 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -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_PROCESS, PROCESS__SHARE, 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),