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: 9875323 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 5525260365 for ; Tue, 1 Aug 2017 19:19:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4534D286A4 for ; Tue, 1 Aug 2017 19:19:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36DB628721; Tue, 1 Aug 2017 19:19:56 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM 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 AE4B0286A4 for ; Tue, 1 Aug 2017 19:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752082AbdHATTi (ORCPT ); Tue, 1 Aug 2017 15:19:38 -0400 Received: from mail-pg0-f48.google.com ([74.125.83.48]:33421 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752015AbdHATQr (ORCPT ); Tue, 1 Aug 2017 15:16:47 -0400 Received: by mail-pg0-f48.google.com with SMTP id c14so11720838pgn.0 for ; Tue, 01 Aug 2017 12:16:46 -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=QjMV7q5kTr5zQoDvx+zMTTp67oNdhcSYn5w4uMiuXh1tuwVoqvRY5OHyGVXHhmrDRE XNspA0bJz527SZQQUgibpwDdH6EAO+W6DAicXur0WPv3Y5Pq6bCi1+q0bRQVBnceTjNv TdK6u/lyhl91KeGK/l7ULGY+R0au81XeYqtKOIMDqRZ5sbQmixIMXvMZuwzDDpGfZc09 KJ2qYXnV5wmVYAU5T7odzB+BaKMhQ/ya6gzXjjpr5LIPNz9ji6yHSgTovS8iJYMfSMdk zcypgMaS/ICfn52In22cmMr5bItXnPBts0j5aKDKnoFulLkJZ58WWK/naRGyJZzGyEnI nhZQ== X-Gm-Message-State: AIVw113ooH5P/MR+5ItmMM0RjDYHlb7Rjn0qCE5L670Av8pu/TTIIEAM Yi6r8PYwnGwzBIzG 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: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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),