From patchwork Mon Jul 31 23:51:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9873391 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 61F9C6016C for ; Mon, 31 Jul 2017 23:54:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B53128567 for ; Mon, 31 Jul 2017 23:54:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 403A32856D; Mon, 31 Jul 2017 23:54:35 +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 DAC85285D8 for ; Mon, 31 Jul 2017 23:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959AbdGaXxd (ORCPT ); Mon, 31 Jul 2017 19:53:33 -0400 Received: from mail-pg0-f46.google.com ([74.125.83.46]:35825 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751760AbdGaXvy (ORCPT ); Mon, 31 Jul 2017 19:51:54 -0400 Received: by mail-pg0-f46.google.com with SMTP id v189so487838pgd.2 for ; Mon, 31 Jul 2017 16:51:54 -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=MioTWfVNb3j+RAgdevH3Tts1vUHO7JaIH1sk/J5jR+8=; b=ZkuWyUdsU0th9ac0iI7ZrLmxJSh4ZDJ2MdJV/n8lWMWnxlZIHKn5GduDIwE9+R4/Gy qMQNEkCcbZABiqcTrz1gSe1dD/o7cxUnO3bYrLLDcebhhfFEalFS09FIwMNPB9f7Nexf 0OHPg0LW8QZXDJ1ZTYqe/lVOe2hnfWlhrNfh4= 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=MioTWfVNb3j+RAgdevH3Tts1vUHO7JaIH1sk/J5jR+8=; b=IvUJdHRoI+NXLJHH/rurTeSG9IkFnZbgRu8cqaz6Ryyi0SL31KG8Dc7qalqX9ZXBQP 6rSA7ZF9cKGh8mvHQUIvLUYKm6DCCd3bKoEaV4b2/sQ/asdtV0K8PYfBtgy72LA1EJpb jDTVYbZQyGjAY+6Yxfq/Pv5Y53xILHSTFgbRMy24Njhuyky+EiGQW+DeZImQhyuf0IZf 2Mse3eYJHuBPAUvw/ACG4fD4+4jvmeMz4l6d/Ki5OdPtmwrPDU3P6sidmpyJcexAxtgx VLu6iuLTcp0ZXsBq+U8KaSLj2ZUaWZFS7uC4m6MdoiRKZvZgHxTTIzvPASoNIT3Vg3cW hebA== X-Gm-Message-State: AIVw112yCiGDy6jNBS1tLI1HECmFGZsgPnASBRZ8CCDlO9DZQ4yLdwEi qoLKkQ56gI1ENp0l X-Received: by 10.99.108.69 with SMTP id h66mr1129959pgc.163.1501545113916; Mon, 31 Jul 2017 16:51:53 -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 n11sm20805560pfg.92.2017.07.31.16.51.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Jul 2017 16:51:53 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , David Howells , "Eric W. Biederman" , John Johansen , "Serge E. Hallyn" , Paul Moore , Stephen Smalley , Casey Schaufler , 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 v4 13/15] exec: Consolidate dumpability logic Date: Mon, 31 Jul 2017 16:51:31 -0700 Message-Id: <1501545093-56634-14-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501545093-56634-1-git-send-email-keescook@chromium.org> References: <1501545093-56634-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 --- fs/exec.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 708a72f93320..3ae8a40c587b 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1333,10 +1333,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(); @@ -1350,9 +1352,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