From patchwork Tue Jul 18 22:25:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9849921 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 CF13E600CC for ; Tue, 18 Jul 2017 22:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8E8F28433 for ; Tue, 18 Jul 2017 22:25:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD5BF285B7; Tue, 18 Jul 2017 22:25:57 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 6797628433 for ; Tue, 18 Jul 2017 22:25:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752667AbdGRWZw (ORCPT ); Tue, 18 Jul 2017 18:25:52 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:35018 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752626AbdGRWZt (ORCPT ); Tue, 18 Jul 2017 18:25:49 -0400 Received: by mail-pg0-f41.google.com with SMTP id v190so19969583pgv.2 for ; Tue, 18 Jul 2017 15:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5Ug8iz26JYnRI98Bdav4Q5ABB5B07BAdRi26S2v/vCc=; b=bw3EN0m8q1gPC1ht36+jR3sEH/bdmlbTtP6Fjx1Rf8EQBkSwoW4JhqekqRXz9TjOjm fhr+C+Bz1866Ookcf9AN2euiGi0TsflCchUtrL+OiO6kZKON5F/EuHt3St9eiC2YhJLX SK/ZwTOMNH0wLku4iON/zKGT6SNGB+QHYT9e0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5Ug8iz26JYnRI98Bdav4Q5ABB5B07BAdRi26S2v/vCc=; b=RwBr133S61GFqVa41JBSWRVCJQz3ni5G1S83oXEcGXRYSelXy4IhcUsvr9QMCXmp/o rPCu69flL7EkEiUrfHzcJgPABg2SE6jGeFELT7fo8lIS1HNV5x4OK3WjSNnFzrvaWUJL HbxlOJWJrp4B9E6SCXWBAW7kqt5mhnK4v7A3qBpfcQA63ekOkdcRDVFMZUrJeXXnLooD rj7UEy3E2O42rqHaVfFDP+wUB8+6h1CoQHo1vLZZRLExB7g+8+GQvk2DC2cK4LqqYgSW Fo7inVpRVr8xjdBxnfLz8eBmnxHUY8nVvZsgHG+1eD3XvDBwi12JqcTWaWzFP2RaDNhX b3+w== X-Gm-Message-State: AIVw111r7m5B9WKIMyMZAZm8JLiEtkv3CmW1vETsuQDSvOYQazpGIqdw OuFxZLo2C1PW83jt X-Received: by 10.99.38.69 with SMTP id m66mr3976919pgm.72.1500416748480; Tue, 18 Jul 2017 15:25:48 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id v62sm6887907pfa.6.2017.07.18.15.25.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 15:25:47 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Casey Schaufler , David Howells , "Eric W. Biederman" , John Johansen , "Serge E. Hallyn" , Paul Moore , Stephen Smalley , Tetsuo Handa , James Morris , Andy Lutomirski , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 05/15] smack: Refactor to remove bprm_secureexec hook Date: Tue, 18 Jul 2017 15:25:26 -0700 Message-Id: <1500416736-49829-6-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500416736-49829-1-git-send-email-keescook@chromium.org> References: <1500416736-49829-1-git-send-email-keescook@chromium.org> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The Smack bprm_secureexec hook can be merged with the bprm_set_creds hook since it's dealing with the same information, and all of the details are finalized during the first call to the bprm_set_creds hook via prepare_binprm() (subsequent calls due to binfmt_script, etc, are ignored via bprm->called_set_creds). Here, the test can just happen at the end of the bprm_set_creds hook, and the bprm_secureexec hook can be dropped. Cc: Casey Schaufler Signed-off-by: Kees Cook --- security/smack/smack_lsm.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 7d4b2e221124..4f1967be3d20 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -950,6 +950,10 @@ static int smack_bprm_set_creds(struct linux_binprm *bprm) bsp->smk_task = isp->smk_task; bprm->per_clear |= PER_CLEAR_ON_SETID; + /* Decide if this is a secure exec. */ + if (bsp->smk_task != bsp->smk_forked) + bprm->secureexec = 1; + return 0; } @@ -967,22 +971,6 @@ static void smack_bprm_committing_creds(struct linux_binprm *bprm) current->pdeath_signal = 0; } -/** - * smack_bprm_secureexec - Return the decision to use secureexec. - * @bprm: binprm for exec - * - * Returns 0 on success. - */ -static int smack_bprm_secureexec(struct linux_binprm *bprm) -{ - struct task_smack *tsp = current_security(); - - if (tsp->smk_task != tsp->smk_forked) - return 1; - - return 0; -} - /* * Inode hooks */ @@ -4646,7 +4634,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = { LSM_HOOK_INIT(bprm_set_creds, smack_bprm_set_creds), LSM_HOOK_INIT(bprm_committing_creds, smack_bprm_committing_creds), - LSM_HOOK_INIT(bprm_secureexec, smack_bprm_secureexec), LSM_HOOK_INIT(inode_alloc_security, smack_inode_alloc_security), LSM_HOOK_INIT(inode_free_security, smack_inode_free_security),