Received: by 10.223.185.116 with SMTP id b49csp6299003wrg; Wed, 28 Feb 2018 07:11:32 -0800 (PST) X-Google-Smtp-Source: AH8x224fv7Fo6UisTo9D/7q0ZJVKc6mQPidCqrTZ5Lv0SvGFKeXKwBwZ35yx7wbyC3xCqLUR4p7a X-Received: by 10.99.65.199 with SMTP id o190mr14670996pga.238.1519830692071; Wed, 28 Feb 2018 07:11:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519830692; cv=none; d=google.com; s=arc-20160816; b=uv67M3uzAWi2AxWDv1ETuVAjjmza+RTPRddNekM/Ga+VeFZfbVdtB2PuqDr4B6wsph 5Et+mCNR8otDU54KjA+cVX9glj67shsz5m7fABnkJ0PbR3df++qOJJdBCyEkq/xFt6Wr HYPXyS58x0FbE9WSlB6f3HeGg3iwq1HB2iXXfxrtH8ub6sI5XsafnnTIsznvYpxpUYsB 9uil9yPjRy+cafeomerWIYYrKGYPtOc9AEIHdqOMitZGt4eQ68NBa+Y/9U4Xg27LECFa vHA+77LniWFeskLyycPSdXrY9afARR4U3dx10aJSrNnXchvaeS2tXdK5r61SYEF2PtA7 +Hxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:reply-to :arc-authentication-results; bh=Cfmm0QWLKmOIADaK2uVeJibcuRALy5bgNiWqmXg2ryE=; b=sY33xdboUTGitGE4TfNDl1NFcyB2Kq0tJpoV7XRX4URk88cxqnJ3MQIzV/bsamQ+hL D4sDpzMih2yirqQImJ+9yTUMmVhyzbUIuHp8y/9Eo9Ars/hfV757RoZX8VBETtN6GJpc VIDXI1dug+TFpfq0VpK25VSL13FSsnDemq41kx/gksYYuZwneWN6sDVYBh1uEjG9Xuef 13AbfMrmxeAwVoRRgSl0edFEZkMmcPepC9JBpi4BIvaBVr2x6LZnawBn9wa+/Y75isFx pUPWGoSGkgbNVfvucpEVJSQrxEiyC3ojw0JXuMRL3uVBAjGyekIQWGsiUgrkmhinPZpl opiA== 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 q24si1354637pff.301.2018.02.28.07.11.17; Wed, 28 Feb 2018 07:11:32 -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 S932596AbeB1PKH (ORCPT + 99 others); Wed, 28 Feb 2018 10:10:07 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:32925 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932584AbeB1PJ7 (ORCPT ); Wed, 28 Feb 2018 10:09:59 -0500 Received: by mail-lf0-f65.google.com with SMTP id o145so4036676lff.0 for ; Wed, 28 Feb 2018 07:09:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Cfmm0QWLKmOIADaK2uVeJibcuRALy5bgNiWqmXg2ryE=; b=OBerOcVmB/8vnBu7FWDBnroK1fKybfmvSvq0NN8G+RPKZeXk/4JVswas6LSBO7TWh0 TIBKO/C6rn9+5EHgElIN64JZ6ydmOySFGMZ0R7emHDVBuN4OhZPTcoRYoFl9BC/wsqZR JiWnx/glAmtb2+ytGVQxg159r4EUiUjxOjooDc4QHVTBDU1WRcbgGpjaeQXn8PC1HbMp 1rmXhVFH2DUzxp7bloyQqGgpyd4I0oJPAavZz6lrmSYHB7H19GMsAXzvgZyANDvl4OIG IzZMm2WpG5tDqxvu+jiS2U72QGuhAeksZwhPWnX3XsmBj0q43hbtvIbXNjmEw9O2B6MJ msBg== X-Gm-Message-State: APf1xPAN5E8oYqIhSgjQxmr22ZXZlFcx7Rw+u9WSB0MtAR0iE+5OmIYQ YiFlvVnIraF3XJ9XoumqqZg= X-Received: by 10.25.234.75 with SMTP id i72mr13832121lfh.65.1519830597622; Wed, 28 Feb 2018 07:09:57 -0800 (PST) Received: from [192.168.42.252] ([213.87.153.113]) by smtp.gmail.com with ESMTPSA id r13sm401057ljd.60.2018.02.28.07.09.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 07:09:56 -0800 (PST) Reply-To: alex.popov@linux.com Subject: Re: [PATCH 1/2] stackleak: Update for arm64 To: Will Deacon , Laura Abbott , Kees Cook , Mark Rutland , Ard Biesheuvel , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com, richard.sandiford@arm.com References: <20180221011303.20392-1-labbott@redhat.com> <20180221011303.20392-2-labbott@redhat.com> <20180222165834.GC18421@arm.com> <97090ca6-efad-7c03-6084-a97674ae61c7@linux.com> <874lm2d96q.fsf@e105548-lin.cambridge.arm.com> From: Alexander Popov Message-ID: <5d10c6ad-b4b6-eb27-79f0-ca235b73e7eb@linux.com> Date: Wed, 28 Feb 2018 18:09:54 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <874lm2d96q.fsf@e105548-lin.cambridge.arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27.02.2018 13:21, Richard Sandiford wrote: > Hi Alexander, > > Sorry for the slow reply, been caught up in an office move. Thank you very much for the review, Richard! > Alexander Popov writes: >> 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. That's important, thank you! May I ask why you think it's not going to matter in practice? > 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. Oh, that raises the question: how does this leafness inaccuracy affect in my particular case? is_leaf is currently used for finding the special cases to skip the track_stack() call insertion: /* * Special cases to skip the instrumentation. * * Taking the address of static inline functions materializes them, * but we mustn't instrument some of them as the resulting stack * alignment required by the function call ABI will break other * assumptions regarding the expected (but not otherwise enforced) * register clobbering ABI. * * Case in point: native_save_fl on amd64 when optimized for size * clobbers rdx if it were instrumented here. * * TODO: any more special cases? */ if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl)) { return 0; } And now it seems to me that the stackleak plugin should not instrument all static inline functions, regardless of is_leaf. Do you agree? >> + /* >> + * 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 for that notice. May I ask for the additional clarification? I specified -fdump-passes and see a lot of passes between reload and final: ... rtl-sched1 : OFF rtl-ira : ON rtl-reload : ON rtl-vzeroupper : OFF *all-postreload : OFF rtl-postreload : OFF rtl-gcse2 : OFF rtl-split2 : ON rtl-ree : ON rtl-cmpelim : OFF rtl-btl1 : OFF rtl-pro_and_epilogue : ON rtl-dse2 : ON rtl-csa : ON rtl-jump2 : ON rtl-compgotos : ON rtl-sched_fusion : OFF rtl-peephole2 : ON rtl-ce3 : ON rtl-rnreg : OFF rtl-cprop_hardreg : ON rtl-rtl_dce : ON rtl-bbro : ON rtl-btl2 : OFF *leaf_regs : ON rtl-split4 : ON rtl-sched2 : ON *stack_regs : ON rtl-split3 : OFF rtl-stack : ON *all-late_compilation : OFF rtl-alignments : ON rtl-vartrack : ON *free_cfg : ON rtl-mach : ON rtl-barriers : ON rtl-dbr : OFF rtl-split5 : OFF rtl-eh_ranges : OFF rtl-shorten : ON rtl-nothrow : ON rtl-dwarf2 : ON rtl-stackleak_final : ON rtl-final : ON rtl-dfinish : ON clean_state : ON Where exactly would you recommend me to insert the stackleak_final pass, which removes the unneeded track_stack() calls? Best regards, Alexander