From patchwork Tue Aug 1 19:16:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9875269 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 B583460365 for ; Tue, 1 Aug 2017 19:17:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A78BB2871F for ; Tue, 1 Aug 2017 19:17:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B0B528722; Tue, 1 Aug 2017 19:17:02 +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 898CB2871F for ; Tue, 1 Aug 2017 19:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752357AbdHATQ7 (ORCPT ); Tue, 1 Aug 2017 15:16:59 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:36396 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752330AbdHATQv (ORCPT ); Tue, 1 Aug 2017 15:16:51 -0400 Received: by mail-pg0-f45.google.com with SMTP id v77so5942058pgb.3 for ; Tue, 01 Aug 2017 12:16:51 -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=DYxmbdSZgrzy7oYf+A+9oWw9thkUslEKDPwl6svI8YQ=; b=IU++R7bWG2MX5NU6XfjJ6JjWky38kvUKWdIb7+Ic6q0v8gAZ0fcQH+XtaBxY21CD02 JFkE0PYPrw0BTIOlNg6O4ltgT4kLAyunJuUfiUaltbHSgpoSqlfvtov1ykEiBP4Eara/ DjKXm5+J1FU8vo/7Z1LR8jEX9BL749B44scqI= 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=DYxmbdSZgrzy7oYf+A+9oWw9thkUslEKDPwl6svI8YQ=; b=B955HZuZTBKp/7r/oOgEUKK7Q+I6aktTMzeNEuNr1wU9/bY+bZlHHZhpVEiNJZt8Mv l/tL2gtAdsbU12CVFedpLqAj3O5FlqXviUhHIpB7xUXIcZXIf5h6pNzpZ7xv1OGP6Vh7 Ta8RskQMy93MhpMPQ88C6DYxLSiIPzuUXQ9i4RWe7zNN7VDtBlXBaUzCkSn6S4g5kfTd NTbdivZyQElCY3xXY9sDEqEbzOK1rOuKysClF9PMAPkjUhd0CtBHAkQ4rYxxqcRG7h1r c6mgcwDlhnbFJ/zQZ4/Fh3YrKJB59dbrTthcCQfy6qjgIMV8mNvjSuKBdBg//ihIbNrK hU8A== X-Gm-Message-State: AIVw112yJd/72Zfrlod1XG4hQK8MHteKexR6XlCQk0EjwUJEWQjEonpL 3gUVwE8kHKtmDrgr X-Received: by 10.84.129.45 with SMTP id 42mr22141167plb.229.1501615011296; Tue, 01 Aug 2017 12:16:51 -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 s9sm62679134pfe.67.2017.08.01.12.16.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 12:16:49 -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 13/15] exec: Consolidate dumpability logic Date: Tue, 1 Aug 2017 12:16:36 -0700 Message-Id: <1501614998-62619-14-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 Since it's already valid to set dumpability in the early part of setup_new_exec(), we can consolidate the logic into a single place. The BINPRM_FLAGS_ENFORCE_NONDUMP is set during would_dump() calls before setup_new_exec(), so its test is safe to move as well. Signed-off-by: Kees Cook Acked-by: Serge Hallyn Reviewed-by: James Morris --- fs/exec.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 7a9288551d62..3006c1c24304 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1354,10 +1354,12 @@ void setup_new_exec(struct linux_binprm * bprm) current->sas_ss_sp = current->sas_ss_size = 0; - if (!bprm->secureexec) - set_dumpable(current->mm, SUID_DUMP_USER); - else + /* Figure out dumpability. */ + if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP || + bprm->secureexec) set_dumpable(current->mm, suid_dumpable); + else + set_dumpable(current->mm, SUID_DUMP_USER); arch_setup_new_exec(); perf_event_exec(); @@ -1371,9 +1373,6 @@ void setup_new_exec(struct linux_binprm * bprm) if (bprm->secureexec) { current->pdeath_signal = 0; - } else { - if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP) - set_dumpable(current->mm, suid_dumpable); } /* An exec changes our domain. We are no longer part of the thread