Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3738947imu; Fri, 30 Nov 2018 05:22:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/U2K9Iyday07h1z94J+pu3c5aUiKLRE/1V3+RSKLn/wsQKJus9eGD4fSX9hG/6sHzJ9W6A4 X-Received: by 2002:a17:902:bb86:: with SMTP id m6mr5764233pls.315.1543584137128; Fri, 30 Nov 2018 05:22:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543584137; cv=none; d=google.com; s=arc-20160816; b=GA/ko04XKQ73/NYQIAqj2QSsgRsL5QJcm8Sb3f4U2QvbcbmLHIgI1YJOGtxrwzfjQC Jk/+47yJREmGS1i8eDv1dmh+O7pAgUzAIrvZcZP4IopOBXmTTZ+w2ctFKygix4/21WQI ePKm3x+PXUPShnZQK9RioZ/xEp9cgOwMPrdHobf2O2T2r14kV4VBdXmM0ci/UcUHSxUl 1AfjM+KHAwM7B1kxa03jwtQ7FpZoQaIasVV/Cz9BRWamUPSXRZoiTJytCiZKNf7nrZVW abXz+lWrzkqwK/A3s2wfIvm41CsuU0Uc46281YaJgDnYX3DtcVW353X4MZG3lkIuyQ3I YPgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from; bh=MYK1Fe1SMo3XkBqdmK20b/a6CPuB50O2uKZhV3bkitM=; b=bZvYym02JtH+6BY2FwtFCWTKXPjRX+f9ENXwxe6pX592/NUvzEOlXrDPbOaVMPrFya +tS0H69TppoRroNwIRUdOBzNecW/SgLL9Yzoer0loPSdZ6WH2EFI9zuWERp22ULY9Ibg xV4PSIB4CJjr3pTE6tj7SWE+FZYtamVCJY8Rv1jm1CDVXtEF+1yZbSlyt7X1CAEOMAxv o4thMhLN45/dTzCtehZps7NsO7Ndi35r1zFWgZpE/kVSv906jMQPBejNM9k3zO6iqJsJ ReykUxnohCAkHa40IeRIUBeEtuPdIaS8E4gef6bXB4mz3Hk3QSEmyYD8QEQOQDTV4gEA 8z3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si5219710ply.404.2018.11.30.05.22.02; Fri, 30 Nov 2018 05:22:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbeLAA3S (ORCPT + 99 others); Fri, 30 Nov 2018 19:29:18 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:40110 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726070AbeLAA3S (ORCPT ); Fri, 30 Nov 2018 19:29:18 -0500 Received: by mail-lj1-f193.google.com with SMTP id n18-v6so4958978lji.7 for ; Fri, 30 Nov 2018 05:20:00 -0800 (PST) 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=bPthkvVvNKJDLy4b3TDEvD37DOTtVgkNEuq6DFPzVN955HLemoX26pVgghMI+h0+yz MSxSQ/kd+4ndjRcajIAgsbAl1M9MFhMgvDvGXe/Bl2gP7K1ZAYM3h2IuhXKPA550AR6K fhbjhAPIhXPf18IwA4fkmJndX8GWVKZvFLsml9V/Nk3QHYqni7kbohCyoLRhYAfPJCV+ HuyGIudwD3gYXNrZz6/8CMPYREkH3H2lezS2Vzj0AmA6Tgly1qHIn1Onlj/p8cbTiLtx AmZ5z21cIIOgOLXjTiyP5lKBTYDLZ+dasAz3M8+UrJwcOx70Sl/h4UV65lsaUhCyb6rk CS5g== X-Gm-Message-State: AA+aEWaahns+H19VrV+S5wsplvH3i6V7OLYM1j83y3sqzuoCHEPWF9sj zCZ+QLq2Bw4OpTbbkP4viZQ= X-Received: by 2002:a2e:91d1:: with SMTP id u17-v6mr3846732ljg.160.1543583999439; Fri, 30 Nov 2018 05:19:59 -0800 (PST) Received: from localhost.localdomain ([213.87.138.170]) by smtp.gmail.com with ESMTPSA id c22sm802455lfd.88.2018.11.30.05.19.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Nov 2018 05:19:58 -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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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")); -- 2.7.4