From patchwork Mon Jul 10 07:57: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: 9832513 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 DF6D160363 for ; Mon, 10 Jul 2017 07:58:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D48D026E3A for ; Mon, 10 Jul 2017 07:58:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8F6328426; Mon, 10 Jul 2017 07:58:27 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 567C826E3A for ; Mon, 10 Jul 2017 07:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753640AbdGJH5u (ORCPT ); Mon, 10 Jul 2017 03:57:50 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:34213 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753562AbdGJH5s (ORCPT ); Mon, 10 Jul 2017 03:57:48 -0400 Received: by mail-pg0-f41.google.com with SMTP id t186so45675548pgb.1 for ; Mon, 10 Jul 2017 00:57: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=PGqFcGOigLzR6iVWkSL5UleD5JwOCpYeajTM4eTNMh8=; b=BiErs9xZM4A8boiaUsyVVfs2wX3XTHrQ+ESmbqJN5rrQGzQ9P3lhj3ayY7XpZytvmU XqW5Kn6PkhM67bXETrGv6k7ubdNw5YGsqSslSrg5ahl2lLVXaUPE7g2OolLw8VDCFF0R I+ITLXZwu/aUjx4epbqAkRvy9DX5fTtNu9M7s= 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=PGqFcGOigLzR6iVWkSL5UleD5JwOCpYeajTM4eTNMh8=; b=fZ2JyH5VFRv3v7FjDFTBdYfX6zgr3dqJ5mnc5xXuwYptl8NMCHx6P/q4RcN1ngXEjm g+0d2+D3mNEgOX+b+TL60zAtVFMtit5ElHVm488KWeV9kc1sKhVhP8rseEiqJg0nhq9J G97qwyxx500mbV/nVpT/WrUxc4oI5nSZ6I4NxgNWDHxjYQzz6e3L57dUXj1pEF0c83AL 4ZKDSmCfd37yVeRa8YS5DIfagsmO5Qx3ke8TMuE5kf8/f1cuLul1u2wlhq32OVwki8fM fRQ6bDxJPSd+2cGdXEG251ebeAt+dLk0YQbmHmzlETsbcq6JCuK40h8gy67s1FC4hIHu kPog== X-Gm-Message-State: AIVw112NTqJmWwQLlwLw0hdANXhOpAO5iKwQyaQFFCF48D/PZIbDHdN/ BHQBY6iyUB7qR1ds X-Received: by 10.84.129.69 with SMTP id 63mr17299935plb.0.1499673463150; Mon, 10 Jul 2017 00:57:43 -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 b78sm27861261pfk.71.2017.07.10.00.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jul 2017 00:57:42 -0700 (PDT) From: Kees Cook To: Linus Torvalds Cc: Kees Cook , Andy Lutomirski , David Howells , Serge Hallyn , John Johansen , Casey Schaufler , "Eric W. Biederman" , Alexander Viro , Michal Hocko , Ben Hutchings , Hugh Dickins , Oleg Nesterov , "Jason A. Donenfeld" , Rik van Riel , James Morris , Greg Ungerer , Ingo Molnar , Nicolas Pitre , Stephen Smalley , Paul Moore , Vivek Goyal , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Tetsuo Handa , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov Subject: [PATCH v2 6/8] exec: Consolidate dumpability logic Date: Mon, 10 Jul 2017 00:57:29 -0700 Message-Id: <1499673451-66160-7-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499673451-66160-1-git-send-email-keescook@chromium.org> References: <1499673451-66160-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 --- fs/exec.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index d7bda5b60e7b..eeb8323977d1 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1346,10 +1346,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(); @@ -1363,9 +1365,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