Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp39799pxb; Wed, 30 Mar 2022 22:22:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR9QlPBjLRC/LoKhBe7+iT7OkFNTjurV8G4UwZWN6r/xqWl3mzb/iG6eykHP5fUR1nxWNl X-Received: by 2002:aa7:90d4:0:b0:4fd:acb9:8eac with SMTP id k20-20020aa790d4000000b004fdacb98eacmr3122056pfk.24.1648704143521; Wed, 30 Mar 2022 22:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648704143; cv=none; d=google.com; s=arc-20160816; b=pdSxxI7/UGEwNzSowO/1RBxgd5xfX0DdtNT0/+SAoX1s3rW5U5CP3obHzh29KyVs9P gikVrcshhGEjZ+Cp6HfIZ3tEts2L13MNtBb7T6m/43a3n0fKJOD/m2cdfnUa9SrgJkSb NRXybQhIcebsNO+aKQiGwrhvaj6QkbzAiJQg+JLH6sFrRy2iXJrt7h7Os3zCja01VRSz /R2qClY7zh956ZHKjifs8O5eoVsBsJXCLGNzFSYEwRVmkb1UiyYCq1f3Ksm8TGX3ka6Z 082Kh+WRPssqVv9cS1l0VXKNpZa/N6ONgSMaglPMBbnD7jZy552xnWjNzhlZ/YuHousZ 57bQ== 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:dkim-signature; bh=hTYTSPjKmzj+vmHdHXYX/HkA6CH3798g482prT8jYOE=; b=vGsEsFQaunFjRSGp991tWiERG5QQlmLDe0Xk55cEjqL5S0vKobPhGISKJ9hoRZHeeX MttVUNaxGIuqmMJMJSf7q+QDFHZ3pAtBMJRV/g2SdOmaWXZCAIqF++/Qt8cI5l9EQIx/ PydBlxskuCpocnMSmM36YJ7gGaf4ISOhgmtsgJXciUO6x96xBpdJrrVMkNg0KYEtK1iu DpamEfUcogK91K5DOO+5+X58kAS8ZomZLTvIgs/HKayC/DmyHj//RAsrIPfEgVftaf93 OIm9GLCR0LBPgX+3y4VKzv/3LXq116J5A2+wHAeGAmtqFw4164qjkHbrguzT+WhwtEdS e1/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="MATa/Ehu"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e1-20020a63aa01000000b003816043f06asi23743035pgf.607.2022.03.30.22.22.09; Wed, 30 Mar 2022 22:22:23 -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; dkim=pass header.i=@chromium.org header.s=google header.b="MATa/Ehu"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229543AbiCaFB1 (ORCPT + 99 others); Thu, 31 Mar 2022 01:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbiCaFB0 (ORCPT ); Thu, 31 Mar 2022 01:01:26 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C0C439688 for ; Wed, 30 Mar 2022 21:59:38 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id gp15-20020a17090adf0f00b001c7cd11b0b3so1566519pjb.3 for ; Wed, 30 Mar 2022 21:59:38 -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=hTYTSPjKmzj+vmHdHXYX/HkA6CH3798g482prT8jYOE=; b=MATa/EhuSiC9n3rxQZYaexkAJx1IL7RS74xROe1UGfyh9/+YHkY19RkVlXFU07jDNZ B5WYTcQ+0j5Kuoo4IdmLNGorMPNy0UQzPZhO5l8cZ46kGKbSNU87AVO1dX1buGQpUNS2 kjnkeBT/Flc5LEWtnUnIjiUUB6IdCRicUXktQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hTYTSPjKmzj+vmHdHXYX/HkA6CH3798g482prT8jYOE=; b=g2yYjkWkUqICSDqP2lE3+y0/8V75hZBZ/M4cy0jVMFRyFBGGV8fWEEMP+dphcoY9En K57uYyyFPnPuzJPhLGxQBSfbpPoQ2f2jWdOBjJGJ8IyggeQ9WQay71lLaTAp2vDOveGH KP0KutzzZ89q5gnaG1zqcAdNDXYTglpyUSRiYW0QVRcquuiG57VHdMQeP4UYGxg/oMC8 saZAYQmLjr3uVdK4gqoXyhp+PPXjxsCjbboBvI3aq1jTAp4oxdrc63c7uH57stoyt5oI jsFttrqW+3KnUWQndGp9EuIpthEy/O7/NYcctlyr1rVEaEm4RFqzV4MjgCENmNmKsdui cvUA== X-Gm-Message-State: AOAM532TH01HVEVMCZWUxnrZCm+TnT5dQYr8IL8Vf+Huyx1W9HNCXD7F 2QyF4+va9rRfLJ1ctH8Pq1i1vQ== X-Received: by 2002:a17:902:db0f:b0:154:665e:af75 with SMTP id m15-20020a170902db0f00b00154665eaf75mr39355836plx.147.1648702778027; Wed, 30 Mar 2022 21:59:38 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n4-20020a637204000000b00398522203a2sm10728411pgc.80.2022.03.30.21.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 21:59:37 -0700 (PDT) Date: Wed, 30 Mar 2022 21:59:37 -0700 From: Kees Cook To: Palmer Dabbelt Cc: Paul Walmsley , aou@eecs.berkeley.edu, peterz@infradead.org, jszhang@kernel.org, geert@linux-m68k.org, mark.rutland@arm.com, chenhuang5@huawei.com, linux-riscv@lists.infradead.org, wangkefeng.wang@huawei.com, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] riscv: Rename "sp_in_global" to "current_stack_pointer" Message-ID: <202203302159.8FA7A6C@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Wed, Mar 30, 2022 at 04:12:18PM -0700, Palmer Dabbelt wrote: > On Tue, 22 Mar 2022 19:16:28 PDT (-0700), Palmer Dabbelt wrote: > > On Wed, 23 Feb 2022 22:04:11 PST (-0800), keescook@chromium.org wrote: > >> To follow the existing per-arch conventions, rename "sp_in_global" to > >> "current_stack_pointer". This will let it be used in non-arch places > >> (like HARDENED_USERCOPY). > >> > >> Cc: Paul Walmsley > >> Cc: Palmer Dabbelt > >> Cc: Albert Ou > >> Cc: Peter Zijlstra > >> Cc: Jisheng Zhang > >> Cc: Geert Uytterhoeven > >> Cc: Mark Rutland > >> Cc: Chen Huang > >> Cc: linux-riscv@lists.infradead.org > >> Signed-off-by: Kees Cook > >> --- > >> arch/riscv/Kconfig | 1 + > >> arch/riscv/include/asm/current.h | 2 ++ > >> arch/riscv/kernel/stacktrace.c | 4 +--- > >> 3 files changed, 4 insertions(+), 3 deletions(-) > >> > >> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > >> index 5adcbd9b5e88..b120c32697af 100644 > >> --- a/arch/riscv/Kconfig > >> +++ b/arch/riscv/Kconfig > >> @@ -16,6 +16,7 @@ config RISCV > >> select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION > >> select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 > >> select ARCH_HAS_BINFMT_FLAT > >> + select ARCH_HAS_CURRENT_STACK_POINTER > >> select ARCH_HAS_DEBUG_VM_PGTABLE > >> select ARCH_HAS_DEBUG_VIRTUAL if MMU > >> select ARCH_HAS_DEBUG_WX > >> diff --git a/arch/riscv/include/asm/current.h b/arch/riscv/include/asm/current.h > >> index 1de233d8e8de..21774d868c65 100644 > >> --- a/arch/riscv/include/asm/current.h > >> +++ b/arch/riscv/include/asm/current.h > >> @@ -33,6 +33,8 @@ static __always_inline struct task_struct *get_current(void) > >> > >> #define current get_current() > >> > >> +register unsigned long current_stack_pointer __asm__("sp"); > >> + > >> #endif /* __ASSEMBLY__ */ > >> > >> #endif /* _ASM_RISCV_CURRENT_H */ > >> diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c > >> index 201ee206fb57..278380e2e956 100644 > >> --- a/arch/riscv/kernel/stacktrace.c > >> +++ b/arch/riscv/kernel/stacktrace.c > >> @@ -14,8 +14,6 @@ > >> > >> #include > >> > >> -register unsigned long sp_in_global __asm__("sp"); > >> - > >> #ifdef CONFIG_FRAME_POINTER > >> > >> void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, > >> @@ -77,7 +75,7 @@ void notrace walk_stackframe(struct task_struct *task, > >> sp = user_stack_pointer(regs); > >> pc = instruction_pointer(regs); > >> } else if (task == NULL || task == current) { > >> - sp = sp_in_global; > >> + sp = current_stack_pointer; > >> pc = (unsigned long)walk_stackframe; > >> } else { > >> /* task blocked in __switch_to */ > > > > Sorry to be slow on this one. This looks good, but another use of > > sp_in_global snuck into fixes and I don't merge fixes into for-next so > > that makes this a bit of a headache. > > > > There's a bunch of stuff in flight, so I'm going to hold off on this > > until after my first week's merge window PR. I intend on merging the > > following, which is at palmer/riscv-sp for now (I'll probably just > > cherry-pick that, I usually start basing stuff on Linus' merge of my PR > > and just cherry-pick in single patches). > > > > commit 7c4f6bb6fb352cfa6028191c2888356b9157a332 > > gpg: Signature made Tue 22 Mar 2022 11:12:19 AM PDT > > gpg: using RSA key 2B3C3747446843B24A943A7A2E1319F35FBB1889 > > gpg: issuer "palmer@dabbelt.com" > > gpg: Good signature from "Palmer Dabbelt " [ultimate] > > gpg: aka "Palmer Dabbelt " [ultimate] > > Author: Kees Cook > > Date: Wed Feb 23 22:04:11 2022 -0800 > > > > riscv: Rename "sp_in_global" to "current_stack_pointer" > > > > To follow the existing per-arch conventions, rename "sp_in_global" to > > "current_stack_pointer". This will let it be used in non-arch places > > (like HARDENED_USERCOPY). > > > > Signed-off-by: Kees Cook > > Signed-off-by: Palmer Dabbelt > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index 5adcbd9b5e88..b120c32697af 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -16,6 +16,7 @@ config RISCV > > select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION > > select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 > > select ARCH_HAS_BINFMT_FLAT > > + select ARCH_HAS_CURRENT_STACK_POINTER > > select ARCH_HAS_DEBUG_VM_PGTABLE > > select ARCH_HAS_DEBUG_VIRTUAL if MMU > > select ARCH_HAS_DEBUG_WX > > diff --git a/arch/riscv/include/asm/current.h b/arch/riscv/include/asm/current.h > > index 1de233d8e8de..21774d868c65 100644 > > --- a/arch/riscv/include/asm/current.h > > +++ b/arch/riscv/include/asm/current.h > > @@ -33,6 +33,8 @@ static __always_inline struct task_struct *get_current(void) > > > > #define current get_current() > > > > +register unsigned long current_stack_pointer __asm__("sp"); > > + > > #endif /* __ASSEMBLY__ */ > > > > #endif /* _ASM_RISCV_CURRENT_H */ > > diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c > > index 14d2b53ec322..08d11a53f39e 100644 > > --- a/arch/riscv/kernel/stacktrace.c > > +++ b/arch/riscv/kernel/stacktrace.c > > @@ -14,8 +14,6 @@ > > > > #include > > > > -register unsigned long sp_in_global __asm__("sp"); > > - > > #ifdef CONFIG_FRAME_POINTER > > > > void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, > > @@ -30,7 +28,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, > > pc = instruction_pointer(regs); > > } else if (task == NULL || task == current) { > > fp = (unsigned long)__builtin_frame_address(0); > > - sp = sp_in_global; > > + sp = current_stack_pointer; > > pc = (unsigned long)walk_stackframe; > > } else { > > /* task blocked in __switch_to */ > > @@ -78,7 +76,7 @@ void notrace walk_stackframe(struct task_struct *task, > > sp = user_stack_pointer(regs); > > pc = instruction_pointer(regs); > > } else if (task == NULL || task == current) { > > - sp = sp_in_global; > > + sp = current_stack_pointer; > > pc = (unsigned long)walk_stackframe; > > } else { > > /* task blocked in __switch_to */ > > > > Thanks! > > Thanks, this is on for-next. I put HARDENED_USERCOPY=y test in for SLAB > and SLUB, not sure if there's anything else that's interesting to test > (we're missing some bits needed for STACKLEAK). Excellent; thank you! -- Kees Cook