From patchwork Fri Nov 30 13:19:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 10706251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0517713AD for ; Fri, 30 Nov 2018 13:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E49182FE64 for ; Fri, 30 Nov 2018 13:20:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D87782FE8C; Fri, 30 Nov 2018 13:20:29 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 3CB282FE73 for ; Fri, 30 Nov 2018 13:20:22 +0000 (UTC) Received: (qmail 19884 invoked by uid 550); 30 Nov 2018 13:20: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 19861 invoked from network); 30 Nov 2018 13:20:11 -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; bh=MYK1Fe1SMo3XkBqdmK20b/a6CPuB50O2uKZhV3bkitM=; b=mkG3zf9i45QHm2votdKTJjUE9Vau9SOexvmm93VceSxkhsiWM1Hu74SV+Zerq9XBlB 6O0JOM70oL5+ZHIiZ19kQjggur9OwofZXa0Nh1dmD3XKa5VsuQuV1FjwlZh2rRjRhNpd lr0wXij7mxvG6NjOQLF1XrhWk/Hz8ShuBfdRdU3vk3ecDHLcB71iH5FFHdZGQBjG55Om XyoyYsfPALqYdbuTX6SJ1IgP1G2c/QaC9lk83NlAMhbRxNbGBELdTlrImrzWrj8qw5WK I6Rwrg8yGarPhdc9npqawn3AXQ0+JFgiOn0IXCiavFqG0KEHMeSxvktMi4YoSzhwzcqe sr5A== X-Gm-Message-State: AA+aEWYWKGE0yrCiifVcnAgp4bnQpdTOLUE6qFhLfKnk0y5W08DRVh64 5OmoodYjjkzZkFHYOytR7g8ST/maiOo= X-Google-Smtp-Source: AFSGD/Ug4nwyFB+Fak6D+Ks51fspieVWWH94yQHG7jlNyW+kdC2/h8GHEEwPZjRnekNlGWcNwd21YQ== X-Received: by 2002:a2e:91d1:: with SMTP id u17-v6mr3846732ljg.160.1543583999439; Fri, 30 Nov 2018 05:19:59 -0800 (PST) From: Alexander Popov To: kernel-hardening@lists.openwall.com, Kees Cook , Jann Horn , Andy Lutomirski , Borislav Petkov , Thomas Gleixner , Dave Hansen , Steven Rostedt , Peter Zijlstra , Masami Hiramatsu , Florian Weimer , Richard Sandiford , Segher Boessenkool , Alexander Monakov , Tycho Andersen , Laura Abbott , Mark Rutland , Emese Revfy , Thomas Garnier , Ingo Molnar , Will Deacon , Alexei Starovoitov , Ard Biesheuvel , H Peter Anvin , David S Miller , linux-arm-kernel@lists.infradead.org, gcc@gcc.gnu.org, alex.popov@linux.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] stackleak: Register the 'stackleak_cleanup' pass before the 'mach' pass Date: Fri, 30 Nov 2018 16:19:47 +0300 Message-Id: <1543583987-27948-1-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Currently the 'stackleak_cleanup' pass deleting a CALL insn is executed after the 'reload' pass. That allows gcc to do some weird optimization in function prologues and epilogues, which are generated later [1]. Let's avoid that by registering the 'stackleak_cleanup' pass before the 'mach' pass, which performs the machine dependent code transformations. It's the moment when the stack frame size is final and function prologues and epilogues are already generated. [1] https://www.openwall.com/lists/kernel-hardening/2018/11/23/2 Reported-by: kbuild test robot Signed-off-by: Alexander Popov --- scripts/gcc-plugins/stackleak_plugin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c index 2f48da9..6f41b32 100644 --- a/scripts/gcc-plugins/stackleak_plugin.c +++ b/scripts/gcc-plugins/stackleak_plugin.c @@ -363,10 +363,12 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, PASS_POS_INSERT_BEFORE); /* - * The stackleak_cleanup pass should be executed after the - * "reload" pass, when the stack frame size is final. + * The stackleak_cleanup pass should be executed before the "mach" + * pass, which performs the machine dependent code transformations. + * It's the moment when the stack frame size is already final and + * function prologues and epilogues are generated. */ - PASS_INFO(stackleak_cleanup, "reload", 1, PASS_POS_INSERT_AFTER); + PASS_INFO(stackleak_cleanup, "mach", 1, PASS_POS_INSERT_BEFORE); if (!plugin_default_version_check(version, &gcc_version)) { error(G_("incompatible gcc/plugin versions"));