From patchwork Tue Jan 9 20:23:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10153239 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 B833F60223 for ; Tue, 9 Jan 2018 20:23:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7D3523B32 for ; Tue, 9 Jan 2018 20:23:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC4A623B3C; Tue, 9 Jan 2018 20:23:46 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 4C45223B32 for ; Tue, 9 Jan 2018 20:23:44 +0000 (UTC) Received: (qmail 20169 invoked by uid 550); 9 Jan 2018 20:23:31 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 20140 invoked from network); 9 Jan 2018 20:23:30 -0000 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=RqiicDPGc6xGk9lLmZlrnjVBQ/5d9vw7ZI84qu+1i+M=; b=jY+kqUm1aBcsNe1ge1fyiuPhyd+OiNTopdFFCrVMhzDpjSQ/IXiqGv21qM7VvfuTb4 YmPou1gKcdSB0g+REGkotKCTd65jKn3aZIOZFsHuSPy+uhI4PxHe7d7Fc6qnGbu6STvQ WMY7k0Ah188W1W+FlgTQgYXqOw0u73s+MQ+50= 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=RqiicDPGc6xGk9lLmZlrnjVBQ/5d9vw7ZI84qu+1i+M=; b=cDLghC3Q0fJXWgYX6dLTIyTr0BeW5GRov4Ktagpd16qQ4scv12IQYURRviOsiH+oTg 9xEB1QqbB1wr5IeepvE0XMSnmWYY9MNxLu5dBKsGpMht0ooFB+cjX1V5O/Lk+c1vx0g8 nk6EFOQWzomflUtOtEANa38InBqebfhv1XMU+qc0wZJJ4/d9iCgiuvpNf0Y55MItB8GF ezblXSxxDqgQzy5gO9c206nGL5H61jLSElN3TOhExsklTSwEIBqFj3mAAyT6gvSjEo8P DWDkQu8JixC2vKIEQO0ALMzl5cE4zIB99MLxUWVQNP3YnSIXuwM+cIo3xbFcQydhAtJp 2I8Q== X-Gm-Message-State: AKGB3mLIHNaXKdKnUpmXuHGJTI8HEm0ED/6TqwrJdxU46lxMFn+i2Und IIsImzb53Gc7vP6dnvPuUgyIPA== X-Google-Smtp-Source: ACJfBougviOguy3rPTKRg14C4S40o2nieYH3gUiFtQ/p7l2R/DfxmUYhAh93H1nJlLWVjmPbfXWE1Q== X-Received: by 10.159.214.132 with SMTP id n4mr17215196plp.1.1515529398900; Tue, 09 Jan 2018 12:23:18 -0800 (PST) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Linus Torvalds , Michal Hocko , Ben Hutchings , Willy Tarreau , Hugh Dickins , Oleg Nesterov , "Jason A. Donenfeld" , Rik van Riel , Laura Abbott , Greg KH , Andy Lutomirski , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Tue, 9 Jan 2018 12:23:02 -0800 Message-Id: <1515529383-35695-3-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515529383-35695-1-git-send-email-keescook@chromium.org> References: <1515529383-35695-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [PATCH 2/3] exec: Introduce finalize_exec() before start_thread() X-Virus-Scanned: ClamAV using ClamSMTP Provide a final call back into fs/exec.c before start_thread() takes over, to handle any last-minute changes, like the coming restoration of the stack limit. Signed-off-by: Kees Cook --- fs/binfmt_aout.c | 1 + fs/binfmt_elf.c | 1 + fs/binfmt_elf_fdpic.c | 1 + fs/binfmt_flat.c | 1 + fs/exec.c | 6 ++++++ include/linux/binfmts.h | 1 + 6 files changed, 11 insertions(+) diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index ce1824f47ba6..c3deb2e35f20 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c @@ -330,6 +330,7 @@ static int load_aout_binary(struct linux_binprm * bprm) #ifdef __alpha__ regs->gp = ex.a_gpvalue; #endif + finalize_exec(bprm); start_thread(regs, ex.a_entry, current->mm->start_stack); return 0; } diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 83732fef510d..b9055ff1c70e 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1155,6 +1155,7 @@ static int load_elf_binary(struct linux_binprm *bprm) ELF_PLAT_INIT(regs, reloc_func_desc); #endif + finalize_exec(bprm); start_thread(regs, elf_entry, bprm->p); retval = 0; out: diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 429326b6e2e7..d90993adeffa 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -463,6 +463,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) dynaddr); #endif + finalize_exec(bprm); /* everything is now ready... get the userspace context ready to roll */ entryaddr = interp_params.entry_addr ?: exec_params.entry_addr; start_thread(regs, entryaddr, current->mm->start_stack); diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 5d6b94475f27..82a48e830018 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -994,6 +994,7 @@ static int load_flat_binary(struct linux_binprm *bprm) FLAT_PLAT_INIT(regs); #endif + finalize_exec(bprm); pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", regs, start_addr, current->mm->start_stack); start_thread(regs, start_addr, current->mm->start_stack); diff --git a/fs/exec.c b/fs/exec.c index 7074913ad2e7..e4ae20ff6278 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1384,6 +1384,12 @@ void setup_new_exec(struct linux_binprm * bprm) } EXPORT_SYMBOL(setup_new_exec); +/* Runs immediately before start_thread() takes over. */ +void finalize_exec(struct linux_binprm *bprm) +{ +} +EXPORT_SYMBOL(finalize_exec); + /* * Prepare credentials and lock ->cred_guard_mutex. * install_exec_creds() commits the new creds and drops the lock. diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h index b0abe21d6cc9..40e52afbb2b0 100644 --- a/include/linux/binfmts.h +++ b/include/linux/binfmts.h @@ -118,6 +118,7 @@ extern int __must_check remove_arg_zero(struct linux_binprm *); extern int search_binary_handler(struct linux_binprm *); extern int flush_old_exec(struct linux_binprm * bprm); extern void setup_new_exec(struct linux_binprm * bprm); +extern void finalize_exec(struct linux_binprm *bprm); extern void would_dump(struct linux_binprm *, struct file *); extern int suid_dumpable;