From patchwork Tue Mar 28 14:08:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 9649727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 64B6960113 for ; Tue, 28 Mar 2017 14:09:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5228C283C9 for ; Tue, 28 Mar 2017 14:09:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46D1E283E8; Tue, 28 Mar 2017 14:09:34 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1E02283C9 for ; Tue, 28 Mar 2017 14:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752340AbdC1OJc (ORCPT ); Tue, 28 Mar 2017 10:09:32 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:23950 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752193AbdC1OJb (ORCPT ); Tue, 28 Mar 2017 10:09:31 -0400 Received: from fsav406.sakura.ne.jp (fsav406.sakura.ne.jp [133.242.250.105]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id v2SE8oDb039280; Tue, 28 Mar 2017 23:08:50 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav406.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav406.sakura.ne.jp); Tue, 28 Mar 2017 23:08:50 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav406.sakura.ne.jp) Received: from AQUA (softbank126227147111.bbtec.net [126.227.147.111]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id v2SE8oWK039270; Tue, 28 Mar 2017 23:08:50 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) To: sds@tycho.nsa.gov Cc: selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org Subject: Re: [PATCH] selinux: Use task_alloc hook rather than task_create hook From: Tetsuo Handa References: <1490706772-8013-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> <1490707796.6046.1.camel@tycho.nsa.gov> In-Reply-To: <1490707796.6046.1.camel@tycho.nsa.gov> Message-Id: <201703282308.BHJ95808.MFFHVQLOOtJFOS@I-love.SAKURA.ne.jp> X-Mailer: Winbiff [Version 2.51 PL2] X-Accept-Language: ja,en,zh Date: Tue, 28 Mar 2017 23:08:45 +0900 Mime-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Stephen Smalley wrote: > On Tue, 2017-03-28 at 22:12 +0900, Tetsuo Handa wrote: > > This patch is a preparation for getting rid of task_create hook > > because > > task_create hook > > task_alloc hook? Oops, copy&paste error. Yes, I meant task_alloc hook. > > > which can do what task_create hook can do was revived. > > > > Creating a new thread is unlikely prohibited by security policy, for > > fork()/execve()/exit() is fundamental of how processes are managed in > > Unix. If a program is known to create a new thread, it is likely that > > permission to create a new thread is given to that program. > > Therefore, > > a situation where security_task_create() returns an error is likely > > that > > the program was exploited and lost control. Even if SELinux failed to > > check permission to create a thread at security_task_create(), > > SELinux > > can later check it at security_task_alloc(). Since the new thread is > > not > > yet visible from the rest of the system, nobody can do bad things > > using > > the new thread. What we waste will be limited to some initialization > > steps such as dup_task_struct(), copy_creds() and audit_alloc() in > > copy_process(). We can tolerate these overhead for unlikely > > situation. > > > > Therefore, this patch changes SELinux to use task_alloc hook rather > > than > > task_create hook so that we can remove task_create hook. > > Aside from the nit on the patch description above, > > Acked-by: Stephen Smalley Thank you. >From b43bd0fc0cc267b91f51ad118f6fabd13efb921e Mon Sep 17 00:00:00 2001 From: Tetsuo Handa Date: Tue, 28 Mar 2017 22:09:38 +0900 Subject: [PATCH v2] selinux: Use task_alloc hook rather than task_create hook This patch is a preparation for getting rid of task_create hook because task_alloc hook which can do what task_create hook can do was revived. Creating a new thread is unlikely prohibited by security policy, for fork()/execve()/exit() is fundamental of how processes are managed in Unix. If a program is known to create a new thread, it is likely that permission to create a new thread is given to that program. Therefore, a situation where security_task_create() returns an error is likely that the program was exploited and lost control. Even if SELinux failed to check permission to create a thread at security_task_create(), SELinux can later check it at security_task_alloc(). Since the new thread is not yet visible from the rest of the system, nobody can do bad things using the new thread. What we waste will be limited to some initialization steps such as dup_task_struct(), copy_creds() and audit_alloc() in copy_process(). We can tolerate these overhead for unlikely situation. Therefore, this patch changes SELinux to use task_alloc hook rather than task_create hook so that we can remove task_create hook. Signed-off-by: Tetsuo Handa Acked-by: Stephen Smalley --- security/selinux/hooks.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index d37a723..d850b7f 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3710,7 +3710,8 @@ static int selinux_file_open(struct file *file, const struct cred *cred) /* task security operations */ -static int selinux_task_create(unsigned long clone_flags) +static int selinux_task_alloc(struct task_struct *task, + unsigned long clone_flags) { u32 sid = current_sid(); @@ -6205,7 +6206,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer) LSM_HOOK_INIT(file_open, selinux_file_open), - LSM_HOOK_INIT(task_create, selinux_task_create), + LSM_HOOK_INIT(task_alloc, selinux_task_alloc), LSM_HOOK_INIT(cred_alloc_blank, selinux_cred_alloc_blank), LSM_HOOK_INIT(cred_free, selinux_cred_free), LSM_HOOK_INIT(cred_prepare, selinux_cred_prepare),