From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7992CC433DF for ; Tue, 9 Jun 2020 18:46:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3407320734 for ; Tue, 9 Jun 2020 18:46:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="u772ecPX"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="U99j7Jwk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3407320734 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1ooUFoTSKJ3Tka+MnumhUOkAO5IyMz+wLwmv2P124Js=; b=u772ecPXEqzpCH 2SnH6gw1BZFhpwvwQLsZexqk6i3k66LLGWGw6lc6tkGHUlQ/tc6ZxGzF5mXxC+Fg4E3XkqSMymp5G lIMVkb0aXXS5ZILah9I9ncO63929n7axIyK8+0w4hZzwnSUFZjqam8hWBtdVhe43AWz3aPJkywtXX LQrBYPVCx7ZBkzcKfJ1q4CojebTrGfaaVIpeX9MWDbWU4pZTSv8n8+A4cB+ujSa0iMcYrlDtiXTbl be3Z+4fFp4K4rDP7hpKA71+Tu21lqRmES5XWRYxztmb/blk5TFDP8HvUOP8CVsMhfb8g2xKeYNS3Y 9MP3zE75SEfWgQLhQYjw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jijGn-0001dv-Hs; Tue, 09 Jun 2020 18:46:45 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jijGl-0001dU-5f for linux-arm-kernel@lists.infradead.org; Tue, 09 Jun 2020 18:46:44 +0000 Received: by mail-pl1-x643.google.com with SMTP id q16so8389176plr.2 for ; Tue, 09 Jun 2020 11:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=7dtLX6XP7HnlQbHJsaggWu4QmeqwjrddfqDvUbVDx4s=; b=U99j7JwkXu9xDjTaNwOqMNsfY/1JGbl0JiVGPVKaBXgK5sILh3SCCo6eu1pc4epTXg OFJZw9ln4TBPmUC0pW0XxrKMH3JsdoIHM3vcI+UatnP+BjixVR5jhLwwCKfajn4CK89/ LsKyztUzZULA3YetUMhR5C2itWjI8K5031e9w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7dtLX6XP7HnlQbHJsaggWu4QmeqwjrddfqDvUbVDx4s=; b=CG8f52CP1GMFN5A8qLOhzWvcFZpX5oe5o/Ypw/ku41q4mcNtl7nLKBX5o2EIGf6hMJ oqBc8pYR3mUDR9ZJYZmLH9LixA4an2rvCHod9Ko1v/tFRGQsBG7YdR8tqWgwhRvq4YFk oaPxhZxYkjNyawbo7LO15zA3s/Em3DB8ATd9u/1YzfEU4dEkvMYaRUDIn5Vm1c+2OeEh sxif6rcfhazkKGg64qo0v9vO6ugo97ikRpMhrx987jJ8y3SU7C1dA/U0cOy5lQIOl8B1 aRJKDd4Ypfsk1SRpXdjBOY6CvAvxOd/4ojGz4A+CTwC0ssvVVe5Tk6TvXYZsyquxCkq/ kZqw== X-Gm-Message-State: AOAM5307Iayt3BMlumXlQx/ocSxMy621Vvz1lP7nU40+lPE4IVdGnAL7 vucYYuqxhY3cthMJTxrIqCWlEA== X-Google-Smtp-Source: ABdhPJwL5HN0U2KSWusdzlMqd2urfWL8t6YS0AxExIzAB1X6VceO1GflzGC9ecX1Ma+jdmYtMYrhFQ== X-Received: by 2002:a17:90a:3489:: with SMTP id p9mr6357379pjb.56.1591728402460; Tue, 09 Jun 2020 11:46:42 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id lt14sm3139209pjb.52.2020.06.09.11.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 11:46:41 -0700 (PDT) Date: Tue, 9 Jun 2020 11:46:40 -0700 From: Kees Cook To: Alexander Popov Subject: Re: [PATCH 2/5] gcc-plugins/stackleak: Use asm instrumentation to avoid useless register saving Message-ID: <202006091143.AD1A662@keescook> References: <20200604134957.505389-1-alex.popov@linux.com> <20200604134957.505389-3-alex.popov@linux.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200604134957.505389-3-alex.popov@linux.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200609_114643_228682_AF598F84 X-CRM114-Status: GOOD ( 14.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-hardening@lists.openwall.com, Catalin Marinas , Masahiro Yamada , Vincenzo Frascino , Will Deacon , Naohiro Aota , Sven Schnelle , Masahiro Yamada , x86@kernel.org, Emese Revfy , Iurii Zaikin , PaX Team , Laura Abbott , Mathias Krause , linux-kbuild@vger.kernel.org, Alexander Monakov , Michal Marek , Thomas Gleixner , Peter Collingbourne , linux-arm-kernel@lists.infradead.org, notify@kernel.org, Florian Weimer , gcc@gcc.gnu.org, Brad Spengler , linux-kernel@vger.kernel.org, Miguel Ojeda , Luis Chamberlain , Jessica Yu , Andrew Morton , Thiago Jung Bauermann Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jun 04, 2020 at 04:49:54PM +0300, Alexander Popov wrote: > Let's improve the instrumentation to avoid this: > > 1. Make stackleak_track_stack() save all register that it works with. > Use no_caller_saved_registers attribute for that function. This attribute > is available for x86_64 and i386 starting from gcc-7. > > 2. Insert calling stackleak_track_stack() in asm: > asm volatile("call stackleak_track_stack" :: "r" (current_stack_pointer)) > Here we use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h. > The input constraint is taken into account during gcc shrink-wrapping > optimization. It is needed to be sure that stackleak_track_stack() call is > inserted after the prologue of the containing function, when the stack > frame is prepared. Very cool; nice work! > +static void add_stack_tracking(gimple_stmt_iterator *gsi) > +{ > + /* > + * The 'no_caller_saved_registers' attribute is used for > + * stackleak_track_stack(). If the compiler supports this attribute for > + * the target arch, we can add calling stackleak_track_stack() in asm. > + * That improves performance: we avoid useless operations with the > + * caller-saved registers in the functions from which we will remove > + * stackleak_track_stack() call during the stackleak_cleanup pass. > + */ > + if (lookup_attribute_spec(get_identifier("no_caller_saved_registers"))) > + add_stack_tracking_gasm(gsi); > + else > + add_stack_tracking_gcall(gsi); > +} The build_for_x86 flag is only ever used as an assert() test against no_caller_saved_registers, but we're able to test for that separately. Why does the architecture need to be tested? (i.e. when this flag becomes supported o other architectures, why must it still be x86-only?) -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel