Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp824352rwb; Fri, 7 Oct 2022 04:48:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gsO2YaYXweVMu13Ug5fcDBx1CSr6OKtNJZ+03ShBr6urH84PrRJtuXu7oX8QzC1zT3m2G X-Received: by 2002:a63:8843:0:b0:449:4ec9:df42 with SMTP id l64-20020a638843000000b004494ec9df42mr4325254pgd.38.1665143313520; Fri, 07 Oct 2022 04:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665143313; cv=none; d=google.com; s=arc-20160816; b=xebYgCMYsoFS6e2K3fSGnyHjonUj9DobyDtB0an0Zh7iad9sWPBPb7ITUehtFc80NX ehXlfP9z0jL/0eHKlhpEbH8XzUZi1cgZlvGgl/dcxeGbyMNdIgAmTGN0ouLMu3GC5+hj 4LYKtZWlDIHX6m6AjcAOMN6JPMXU8p3vaHGpy2wz/GPdP2YswICoRpOxD8ExMgF2pdyj YZmKAWXlplsb1zrUhkHZh5IfO4CFmyC+BqI+mOe++Yl/nvCgIuoNUGdHzoLZIEPcvgRu LxAOsH5/zcqMmyHXHhMJeZ/Hv0kxwlMrnX8uFufB/ZG4uwOan/XAp0yWFFpF0Fck+Xzc mUig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=9WeLTh8pH1fcspwikGfEg6fw6U7lBUXASVZ+acrgPNw=; b=bP9nSrz3LJLkC98BceHblVmGKp2Ti5ZOuBy+Eo/7gZB/PN65SU3gmcjGpbEddYR+qQ +4a10uapMRod5hk7uljIMX4SiijlX21ZOBXYciKKjWaSftu3N0eWDhpG5LWKvppvyTEj DTscU5Lv3j6HwdJVg70I8xN6B9fQRhnP3CVacqonpnVccKXX81UwlgtqmbAHarAMdUE8 IE6AD1A9KXAJroMxjn5NvsKDaVjA2fool/f8CoUVKXp+olzSA2UdgxtzYYYhqUJhnoa6 RZZoYqV/XsoYpYx6VMz7P3nSUoMzgwSOgEW0urixDSotmzRFg2I2v/+yLWZfgpOJoy2t Ot6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w129-20020a628287000000b00536c7c210d3si1957246pfd.171.2022.10.07.04.48.21; Fri, 07 Oct 2022 04:48:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbiJGLaL (ORCPT + 99 others); Fri, 7 Oct 2022 07:30:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiJGLaI (ORCPT ); Fri, 7 Oct 2022 07:30:08 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9ED8A476F4; Fri, 7 Oct 2022 04:30:04 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 746711063; Fri, 7 Oct 2022 04:30:10 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 695033F792; Fri, 7 Oct 2022 04:30:00 -0700 (PDT) Date: Fri, 7 Oct 2022 12:29:49 +0100 From: Mark Rutland To: Palmer Dabbelt Cc: Conor.Dooley@microchip.com, guoren@kernel.org, oleg@redhat.com, vgupta@kernel.org, linux@armlinux.org.uk, monstr@monstr.eu, dinguyen@kernel.org, davem@davemloft.net, Arnd Bergmann , shorne@gmail.com, Paul Walmsley , aou@eecs.berkeley.edu, ardb@kernel.org, heiko@sntech.de, daolu@rivosinc.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-snps-arc@lists.infradead.org, sparclinux@vger.kernel.org, openrisc@lists.librecores.org, xianting.tian@linux.alibaba.com, linux-efi@vger.kernel.org Subject: Re: [PATCH] RISC-V: Add STACKLEAK erasing the kernel stack at the end of syscalls Message-ID: References: <6c48657c-04df-132d-6167-49ed293dea44@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 06, 2022 at 07:31:01PM -0700, Palmer Dabbelt wrote: > On Tue, 06 Sep 2022 10:35:10 PDT (-0700), Conor.Dooley@microchip.com wrote: > > On 03/09/2022 17:23, guoren@kernel.org wrote: > > > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe > > > > > > From: Xianting Tian > > > > > > This adds support for the STACKLEAK gcc plugin to RISC-V and disables > > > the plugin in EFI stub code, which is out of scope for the protection. > > > > > > For the benefits of STACKLEAK feature, please check the commit > > > afaef01c0015 ("x86/entry: Add STACKLEAK erasing the kernel stack at the end of syscalls") > > > > > > Performance impact (tested on qemu env with 1 riscv64 hart, 1GB mem) > > > hackbench -s 512 -l 200 -g 15 -f 25 -P > > > 2.0% slowdown > > > > > > Signed-off-by: Xianting Tian > > > > What changed since Xianting posted it himself a week ago: > > https://lore.kernel.org/linux-riscv/20220828135407.3897717-1-xianting.tian@linux.alibaba.com/ > > > > There's an older patch from Du Lao adding STACKLEAK too: > > https://lore.kernel.org/linux-riscv/20220615213834.3116135-1-daolu@rivosinc.com/ > > > > But since there's been no activity there since June... > > Looks like the only issues were some commit log wording stuff, and that > there's a test suite that should be run. It's not clear from the commits > that anyone has done that, I'm fine with the patch if it passes the tests > but don't really know how to run them. Enable CONFIG_LKDTM, and do: echo STACKLEAK_ERASING > /sys/kernel/debug/provoke-crash/DIRECT Example GOOD/BAD output below, taken from: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/misc/lkdtm/stackleak.c?id=72b61896f2b47fa4b98e86184bc0e6ddbd1a8db1 GOOD result on x86_64: | # echo STACKLEAK_ERASING > /sys/kernel/debug/provoke-crash/DIRECT | lkdtm: Performing direct entry STACKLEAK_ERASING | lkdtm: stackleak stack usage: | high offset: 168 bytes | current: 336 bytes | lowest: 656 bytes | tracked: 656 bytes | untracked: 400 bytes | poisoned: 15152 bytes | low offset: 8 bytes | lkdtm: OK: the rest of the thread stack is properly erased GOOD result on arm64: | # echo STACKLEAK_ERASING > /sys/kernel/debug/provoke-crash/DIRECT | lkdtm: Performing direct entry STACKLEAK_ERASING | lkdtm: stackleak stack usage: | high offset: 336 bytes | current: 656 bytes | lowest: 1232 bytes | tracked: 1232 bytes | untracked: 672 bytes | poisoned: 14136 bytes | low offset: 8 bytes | lkdtm: OK: the rest of the thread stack is properly erased BAD result on arm64: | # echo STACKLEAK_ERASING > /sys/kernel/debug/provoke-crash/DIRECT | lkdtm: Performing direct entry STACKLEAK_ERASING | lkdtm: FAIL: non-poison value 24 bytes below poison boundary: 0x0 | lkdtm: FAIL: non-poison value 32 bytes below poison boundary: 0xffff8000083dbc00 ... | lkdtm: FAIL: non-poison value 1912 bytes below poison boundary: 0x78b4b9999e8cb15 | lkdtm: FAIL: non-poison value 1920 bytes below poison boundary: 0xffff8000083db400 | lkdtm: stackleak stack usage: | high offset: 336 bytes | current: 688 bytes | lowest: 1232 bytes | tracked: 576 bytes | untracked: 288 bytes | poisoned: 15176 bytes | low offset: 8 bytes | lkdtm: FAIL: the thread stack is NOT properly erased! | lkdtm: Unexpected! This kernel (5.18.0-rc1-00013-g1f7b1f1e29e0-dirty aarch64) was built with CONFIG_GCC_PLUGIN_STACKLEAK=y Mark.