From patchwork Tue Dec 5 23:33:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 10094145 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 306A260348 for ; Tue, 5 Dec 2017 23:34:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 216D6288DC for ; Tue, 5 Dec 2017 23:34:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 147E2289A3; Tue, 5 Dec 2017 23:34:43 +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 2DAA4288DC for ; Tue, 5 Dec 2017 23:34:42 +0000 (UTC) Received: (qmail 8182 invoked by uid 550); 5 Dec 2017 23:34: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 8127 invoked from network); 5 Dec 2017 23:34:10 -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=JBTotQ9nxx6GwCQh1DJPigtPt0/UdzEWPJhekt3kXO0=; b=mAeUd8bExuQscxQw4bhP2wrdqfiazSJ9zIhQDNWK18T0K0JdxKJEgILMV7byxxsIib qbq9CNi+HW1K7KxhJtrq3Hkkm2Zrf+yMDZLvx38rA0HUaTUFm2zwuESAtlFxxxXboCB4 6kdW9qBVZm8RFIp+jn5JOO9n2YbdazBtm83K45mX3FuvEYWiyGDkxakOx9E6nTJw5I+y s7BuJXsZ2Rqgax2qu8v/L/MuxeEjoAUy13e490O8EOmCeax5bJh2oJ4Hd4PAMD0yCl35 ib21UUhOfvjLeCxM+GdnmbA+FPwOZBSp0JT9yAix2YvLSXz3W0+PjyZMcSt0xpWCbi3h Whng== X-Gm-Message-State: AJaThX7+kfZ+U20eknItuyYvVg7kMetRNWJy2duOxSMrKD47begrzDcZ z2OyXOPqV8C6iPCaa8nAj7WU2DcH X-Google-Smtp-Source: AGs4zMaSAJ7Tx+FMy+NaL5UpQKVRQIeUrYtganKSlmokb5/z6m5PChyYV7kak0yexLvToWR/PDB35w== X-Received: by 10.25.29.80 with SMTP id d77mr10159260lfd.39.1512516839038; Tue, 05 Dec 2017 15:33:59 -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 , Thomas Gleixner , "H . Peter Anvin" , Peter Zijlstra , x86@kernel.org, alex.popov@linux.com Date: Wed, 6 Dec 2017 02:33:44 +0300 Message-Id: <1512516827-29797-4-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512516827-29797-1-git-send-email-alex.popov@linux.com> References: <1512516827-29797-1-git-send-email-alex.popov@linux.com> Subject: [kernel-hardening] [PATCH RFC v6 3/6] x86/entry: Erase kernel stack in syscall_trace_enter() 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 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index d7d3cc2..d45b7cf 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -45,6 +45,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 @@ -81,11 +87,15 @@ static long syscall_trace_enter(struct pt_regs *regs) emulated = true; if ((emulated || (work & _TIF_SYSCALL_TRACE)) && - tracehook_report_syscall_entry(regs)) + tracehook_report_syscall_entry(regs)) { + erase_kstack(); return -1L; + } - if (emulated) + if (emulated) { + erase_kstack(); return -1L; + } #ifdef CONFIG_SECCOMP /* @@ -117,8 +127,10 @@ static long syscall_trace_enter(struct pt_regs *regs) } ret = __secure_computing(&sd); - if (ret == -1) + if (ret == -1) { + erase_kstack(); return ret; + } } #endif @@ -127,6 +139,7 @@ static long syscall_trace_enter(struct pt_regs *regs) do_audit_syscall_entry(regs, arch); + erase_kstack(); return ret ?: regs->orig_ax; }