From patchwork Sat Mar 3 20:00:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 10256161 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 9CD2D6037E for ; Sat, 3 Mar 2018 20:01:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8800A28787 for ; Sat, 3 Mar 2018 20:01:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BA4C287A1; Sat, 3 Mar 2018 20:01:54 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 9F6F228787 for ; Sat, 3 Mar 2018 20:01:53 +0000 (UTC) Received: (qmail 15850 invoked by uid 550); 3 Mar 2018 20:01:11 -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 15771 invoked from network); 3 Mar 2018 20:01:07 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8xTH0Qn4FJjVArEZhiC6i5hOYrV8Y7yi6fh09pqZCmU=; b=uNbi2fWYo86mU9/hEEhRUUH/HcKpxxaCDn2Vxr8/ayaoemlZSe42qKBFyW6Slanz6L E2jbqy5lHyykK+ei1wLjHHYs2JPVMgKxCigwk5O0PlFncoRm72f36NP+ULzHXiCftB06 qLvBSg+mmaGMv/d0E7anqwYj4U8SFtLTEbBgI14efKfCPsbRHtlHKij7PnYnQ6iwmAQS xtWIbuwRNuwLcazB50w7hdwOlBsjrO4f8CT34SPHINjUMltYRY/wFuLP6hPZMpce8TKs IGzpZdPUrsXJGSrPhRMgj0k4F9Ci6Esc0eMd59QbPzdcNOTf7kjbiJx7lJpR9lbuiuKh zblg== X-Gm-Message-State: AElRT7H+I5XfPhcg9cOlFODwj77liG1yjte0jLB/42R66WsncPoU8vzm 8k9gJlCdPz2JOjLzgYoxLipzeR+E4Gc= X-Google-Smtp-Source: AG47ELuIj0Ui2Y+kadCiozi136we21nmNlr3UWy1DHDDri0FybDbykBc5OOMJXOsUT5IOqpHQb+1dw== X-Received: by 10.25.181.147 with SMTP id g19mr6928950lfk.47.1520107256362; Sat, 03 Mar 2018 12:00:56 -0800 (PST) From: Alexander Popov To: kernel-hardening@lists.openwall.com, Kees Cook , PaX Team , Brad Spengler , Ingo Molnar , Andy Lutomirski , Tycho Andersen , Laura Abbott , Mark Rutland , Ard Biesheuvel , Borislav Petkov , Richard Sandiford , Thomas Gleixner , "H . Peter Anvin" , Peter Zijlstra , "Dmitry V . Levin" , Emese Revfy , Jonathan Corbet , Andrey Ryabinin , "Kirill A . Shutemov" , Thomas Garnier , Andrew Morton , Alexei Starovoitov , Josef Bacik , Masami Hiramatsu , Nicholas Piggin , Al Viro , "David S . Miller" , Ding Tianhong , David Woodhouse , Josh Poimboeuf , Steven Rostedt , Dominik Brodowski , Juergen Gross , Greg Kroah-Hartman , Dan Williams , Dave Hansen , Mathias Krause , Vikas Shivappa , Kyle Huey , Dmitry Safonov , Will Deacon , Arnd Bergmann , x86@kernel.org, linux-kernel@vger.kernel.org, alex.popov@linux.com Subject: [PATCH RFC v9 4/7] x86/entry: Erase kernel stack in syscall_trace_enter() Date: Sat, 3 Mar 2018 23:00:29 +0300 Message-Id: <1520107232-14111-5-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520107232-14111-1-git-send-email-alex.popov@linux.com> References: <1520107232-14111-1-git-send-email-alex.popov@linux.com> X-Virus-Scanned: ClamAV using ClamSMTP Make STACKLEAK erase kernel stack after ptrace/seccomp/auditing not to leave any sensitive information on the stack for the syscall code. This code is modified from Brad Spengler/PaX Team's code in the last public patch of grsecurity/PaX based on our understanding of the code. Changes or omissions from the original code are ours and don't reflect the original grsecurity/PaX code. Signed-off-by: Alexander Popov --- arch/x86/entry/common.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 74f6eee..b4be776 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -46,6 +46,12 @@ __visible inline void enter_from_user_mode(void) static inline void enter_from_user_mode(void) {} #endif +#ifdef CONFIG_GCC_PLUGIN_STACKLEAK +asmlinkage void erase_kstack(void); +#else +static void erase_kstack(void) {} +#endif + static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch) { #ifdef CONFIG_X86_64 @@ -128,6 +134,7 @@ static long syscall_trace_enter(struct pt_regs *regs) do_audit_syscall_entry(regs, arch); + erase_kstack(); return ret ?: regs->orig_ax; }