Received: by 10.223.185.116 with SMTP id b49csp4776918wrg; Tue, 27 Feb 2018 02:23:08 -0800 (PST) X-Google-Smtp-Source: AH8x227sxmKrVqnihgQ4/T6FGYlNyZo8iWTJZpBFCeWtUpkTt2WMz+mY4P5UNFX6JRdebNg1OP3Q X-Received: by 10.98.93.87 with SMTP id r84mr13676529pfb.131.1519726988379; Tue, 27 Feb 2018 02:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519726988; cv=none; d=google.com; s=arc-20160816; b=vWfAvx3phKbrcD5fjAS6zYyMQJj3p7RnQ24pJW7bTb9PaxCf0IE93I4Wg3V1r2OByI twCwcQ+AYsavmjy5p1defno5iOLxO1kupfraGWqHW2xqEgtFcy0Be7SfGYPz6HRC1o1S w7cQyflFMX/YF2ICmGgmfhn6/XudMBDN0nTLQQpb4I81eYhq3gTJoBK4vgnZYKY9VjEe 4gNA1Y4UMKWOGy6s+DS81FedhJLmseDFU58uVNqKg/PaLboT8SRsX+0OhHiadEFf/fzq ckEb0E1c1hmXnCIK2pQnfG10Ixuamb3LSHd5ymYVKAUqi/D6TjuFH+HVlyn+f06F1I+j ampQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:mail-followup-to:to:from :arc-authentication-results; bh=88rcwyF5AZha0S0nr04HEnm1cC64igoqB+kbTpGGOv8=; b=jjIrKmHi/c597pCGUuIZCvQeAg9r0tVbGbb7C2lSIqdg7OZIAzMbW17719kKbNlEPt j7KtPxhw8Qd51FRSVhm+XJK5SD4fAWR+5AeuaZWCG11v8JfeE6ZdVleyql9RsduTyKOI 6t9ItIdIZnKFeHPg4O7SLTDHFQqcSzKCDjMtpUOOsDRqNVqExcp8krR91KbFBr1ehCpD sv40SXl67JG3uPFz4kVno1EHoSna22JXgJ6RCsRP4Gr+D6DKUUUhmWps4MdSraHUC+A0 DtdN219mh4/kIDns1V25PQPgzIocfQY52FmmL0Wr+Eebe1kNVwPGx7zSprKBtH4DRPqh AZbg== 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 h10si6832586pgr.94.2018.02.27.02.22.53; Tue, 27 Feb 2018 02:23:08 -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 S1752692AbeB0KWA (ORCPT + 99 others); Tue, 27 Feb 2018 05:22:00 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:32820 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752090AbeB0KV7 (ORCPT ); Tue, 27 Feb 2018 05:21:59 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CC29215AD; Tue, 27 Feb 2018 02:21:58 -0800 (PST) Received: from localhost (unknown [10.32.99.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E93A73F318; Tue, 27 Feb 2018 02:21:56 -0800 (PST) From: Richard Sandiford To: Alexander Popov Mail-Followup-To: Alexander Popov ,Will Deacon , Laura Abbott , Kees Cook , Mark Rutland , Ard Biesheuvel , , , , richard.sandiford@arm.com Cc: Will Deacon , Laura Abbott , Kees Cook , Mark Rutland , Ard Biesheuvel , , , Subject: Re: [PATCH 1/2] stackleak: Update for arm64 In-Reply-To: <97090ca6-efad-7c03-6084-a97674ae61c7@linux.com> (Alexander Popov's message of "Thu, 22 Feb 2018 22:22:14 +0300") References: <20180221011303.20392-1-labbott@redhat.com> <20180221011303.20392-2-labbott@redhat.com> <20180222165834.GC18421@arm.com> <97090ca6-efad-7c03-6084-a97674ae61c7@linux.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.5 (gnu/linux) Date: Tue, 27 Feb 2018 10:21:49 +0000 Message-ID: <874lm2d96q.fsf@e105548-lin.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexander, Sorry for the slow reply, been caught up in an office move. Alexander Popov writes: > Hello Will, Richard and GCC folks! > > On 22.02.2018 19:58, Will Deacon wrote: >> On Tue, Feb 20, 2018 at 05:13:02PM -0800, Laura Abbott wrote: >>> >>> arm64 has another layer of indirection in the RTL. >>> Account for this in the plugin. >>> >>> Signed-off-by: Laura Abbott >>> --- >>> scripts/gcc-plugins/stackleak_plugin.c | 5 +++++ >>> 1 file changed, 5 insertions(+) >>> >>> diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c >>> index 6fc991c98d8b..7dfaa027423f 100644 >>> --- a/scripts/gcc-plugins/stackleak_plugin.c >>> +++ b/scripts/gcc-plugins/stackleak_plugin.c >>> @@ -244,6 +244,11 @@ static unsigned int stackleak_final_execute(void) >>> * that insn. >>> */ >>> body = PATTERN(insn); >>> + /* arm64 is different */ >>> + if (GET_CODE(body) == PARALLEL) { >>> + body = XEXP(body, 0); >>> + body = XEXP(body, 0); >>> + } >> >> Like most kernel developers, I don't know the first thing about GCC internals >> so I asked our GCC team and Richard (CC'd) reckons this should be: >> >> if (GET_CODE(body) == PARALLEL) >> body = XVECEXP(body, 0, 0); >> >> instead of the hunk above. Can you give that a go instead, please? > > Thanks a lot! > > Would you be so kind to take a look at the whole STACKLEAK plugin? > http://www.openwall.com/lists/kernel-hardening/2018/02/16/4 > https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=kspp/gcc-plugin/stackleak&id=57a0a6763b12e82dd462593d0f42be610e93cdc9 > > It's not very big. I documented it in detail. I would be really grateful for the > review! Looks good to me FWIW. Just a couple of minor things: > + /* > + * 1. Loop through the GIMPLE statements in each of cfun basic blocks. > + * cfun is a global variable which represents the function that is > + * currently processed. > + */ > + FOR_EACH_BB_FN(bb, cfun) { > + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) { > + gimple stmt; > + > + stmt = gsi_stmt(gsi); > + > + /* Leaf function is a function which makes no calls */ > + if (is_gimple_call(stmt)) > + is_leaf = false; It's probably not going to matter in practice, but it might be worth emphasising in the comments that this leafness is only approximate. It will sometimes be a false positive, because we could still end up creating calls to libgcc functions from non-call statements (or for target-specific reasons). It can also be a false negative, since call statements can be to built-in or internal functions that end up being open-coded. > + /* > + * The stackleak_final pass should be executed before the "final" pass, > + * which turns the RTL (Register Transfer Language) into assembly. > + */ > + PASS_INFO(stackleak_final, "final", 1, PASS_POS_INSERT_BEFORE); This might be too late, since it happens e.g. after addresses have been calculated for branch ranges, and after machine-specific passes (e.g. bundling on ia64). The stack size is final after reload, so inserting the pass after that might be better. Thanks, Richard