From patchwork Tue Aug 1 19:16:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9875325 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 5453E60365 for ; Tue, 1 Aug 2017 19:19:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46369286A4 for ; Tue, 1 Aug 2017 19:19:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A0A928721; Tue, 1 Aug 2017 19:19: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=unavailable 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 DA56B286A4 for ; Tue, 1 Aug 2017 19:19:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752532AbdHATTi (ORCPT ); Tue, 1 Aug 2017 15:19:38 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:38612 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752189AbdHATQr (ORCPT ); Tue, 1 Aug 2017 15:16:47 -0400 Received: by mail-pg0-f51.google.com with SMTP id l64so11537417pge.5 for ; Tue, 01 Aug 2017 12:16:47 -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=8ze4OKUwja78V1d603mxdpKnnVpr/zIbkrXcatubHxs=; b=PnclY9Dv1zH8u+NzWqUssOjKE1cyei8RT4MENhI8mL6moYNbrDzP7Ki0TIg4Q8nkHL hXG/z7E4BEfiaQJ0N6S4drXzxJUkuM8TmiCbIqpzSrrcI1hxdy5iPUmpwTIhYEvEEJ6q 4lldiLtVKwfO6wXiiS+PzbzPrn4CA2TndKwmI= 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=8ze4OKUwja78V1d603mxdpKnnVpr/zIbkrXcatubHxs=; b=Fg4ltlZxztTaslW/g1rzW5vjYvvy+0r2kD7rmlGODeWDvKNwKSiNRNAjYZkIBsmNMZ o3xII5lbqsjv8dcyI/F2Azr3ozq+6Bdf4v+DQlQkJ7TsEq+QwONRSHBPIf78C1MJrHng vtzwVXkzquG88HvI39WL/WJMeQ9UTJqA6IF9k2s9+ZcIx9TdYEl3D+UpDX9OS1G9daC2 wk6RhBqwDj6jLFNtZmn1SNMdx5K1Sh+Cr+88oMbebEEbfjblyX4Ljq6ifoNHckNQhWy2 84SvAkyu8X3qUjfOivIS93zjaA8BcxFQHvYROi03HMe86SeiUhwVs+CMZe2d3f9njQkS sNNA== X-Gm-Message-State: AIVw1139qfEfL2qcjYGed9npsCtl2513gD3M44mjUe4V94TNj9N83KAS 3rfE1SKzbKPDhuDc X-Received: by 10.99.158.10 with SMTP id s10mr20669230pgd.113.1501615006669; Tue, 01 Aug 2017 12:16:46 -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 c64sm23278001pfj.91.2017.08.01.12.16.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 12:16:45 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Linus Torvalds , Andrew Morton , James Morris , "Serge E. Hallyn" , Andy Lutomirski , "Eric W. Biederman" , John Johansen , Paul Moore , Casey Schaufler , Stephen Smalley , Tetsuo Handa , David Howells , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v5 06/15] smack: Refactor to remove bprm_secureexec hook Date: Tue, 1 Aug 2017 12:16:29 -0700 Message-Id: <1501614998-62619-7-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501614998-62619-1-git-send-email-keescook@chromium.org> References: <1501614998-62619-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. Signed-off-by: Kees Cook Acked-by: Serge Hallyn Reviewed-by: James Morris Reviewed-by: Casey Schaufler --- 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 db8e16ec223b..791d028207b9 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),