Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2219966pxb; Wed, 30 Mar 2022 19:44:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5AV+GP4qIR9Pw/WG6jfY6v7/bw4vD5fH1IRFzzN2sYtb13GJ+s5WaTkMMbC9XApGklI2h X-Received: by 2002:a05:6a00:1824:b0:4f6:dc69:227e with SMTP id y36-20020a056a00182400b004f6dc69227emr2910609pfa.58.1648694674318; Wed, 30 Mar 2022 19:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648694674; cv=none; d=google.com; s=arc-20160816; b=H5wrapL3rb+iWhm5zy/j6VywRziQOexvSMmNr3Y7UODBFNoqok3kS/s61LsBIwQVsf G6fbgb8+zif5j7Gvpbpn10DFhEqrg1V6fMNAEIxVji3PgABjuC5Om91DC8fqNFqoyfih Cvq+ryZOpUOXWySBzLsQJCPcrnbv/9yVfsjxYtH91Ss1SXumntWxZFy5Df4FdRL/iXAy YgdvwUGm4M8IMo/2k2HBjljWIF+c/N182ETuAvo4OZ8T4r/5rMJMnxhWhPCmJk5UqTfg qAW40ZqHlNQmiHdQNOzVAd4t1ydEFol3tKIBEFbWmDyNSyzg5Xl4BGR2LdSxxmdtcH8j Pnig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:to:from:cc:in-reply-to:subject:date :dkim-signature; bh=sHR4EcucliUpX7+65qOWS8vP81r34dp/5wb9FsMswWI=; b=TD8TKheuc5kVyEtZdEazxMaCNd7GC2pUtUQtZ0nK9YBIGfejHFmFc/Lax7Htvocb2B 9DuzA35ydRkELDaaVb+Wj8uxZjTu08F9O2XMimqF4R7oBADcRdufw/EFXqfxjkDxU+JA Cw0JDNnGuY9iyKW7XTXeYlhhro+LP2/Rqy8DN9mZFpA09Jy0wcVdfohsEEu/ZS+aSKNM W++jwwDk/YGpSJW2pauAaAzdnfBHNuS8gHPQ4kGkzMxILZOJO+MNBDTzEUVh+nDRVhfp tRWDLpCQ4LJ5nEaLYFo42Gy/D4kqZpTic7XSORTENbP/WLOGbgU1yMFdsi2aoPqL7i5a nt1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=x9LzSrMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j16-20020a62e910000000b004fa3a8dff83si21874530pfh.58.2022.03.30.19.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 19:44:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=x9LzSrMw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ADE0AAC04D; Wed, 30 Mar 2022 19:35:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351768AbiC3XOH (ORCPT + 99 others); Wed, 30 Mar 2022 19:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343615AbiC3XOF (ORCPT ); Wed, 30 Mar 2022 19:14:05 -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 8765B4A3F8 for ; Wed, 30 Mar 2022 16:12:19 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id bx5so22258353pjb.3 for ; Wed, 30 Mar 2022 16:12:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=date:subject:in-reply-to:cc:from:to:message-id; bh=sHR4EcucliUpX7+65qOWS8vP81r34dp/5wb9FsMswWI=; b=x9LzSrMwm+OX0LDp8wR/iVTvAirwptvVKFGRsLefAoZx3mxBaC5m3CbbNsq2v9k6rn atQrs2BR3hgdPIkyvTsAbkRBsbmxLVS79kMGutu+P3vZfvflL1ScawHcKIHvWYCDiRMP kw8Qon7IXj49MvWj6TJG6u/xCJsCUWyNtNtahDQ5AxH/GIgKQmnx/dEMStromPP7YKaW TegSDzXqDjpEripUsME1eVjFMnv/KeotMJ2s5VfvM6dO0PALqXQ4gpj55nDNZUIn5bww jHcqPj7uMMvPu51qcFKgU3h3cfrv2Vw5ui/7M0sjaSeuQtBWBAykiX400AH/uMbxo5Mi Nxtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id; bh=sHR4EcucliUpX7+65qOWS8vP81r34dp/5wb9FsMswWI=; b=k58aMONlxgnT9RhWbdX3WrJB/OVlKPtapUj8tDS7UwjVDuOGqqt5xlVmvskbyqeUcv +Vrj3Y+JXu80Q3De6bMlNWrMTU8KLze/ml5oyxCmnexKehTVGed9jyKVlTBWKPwK4U8k 2NBIdt1RBvm15/2ApgLs6dZYOUJ73lYfLSPi6o1IDuRwsoeZnmWDiiKxd1wvHv9da8Fe FZMqyVXZ/d6jv8GIBGCpPIHwtZaKqm0OprEytjp6O06q/jJy6iNyfJKjXm4DitNqI0i8 S7yimAa+ipQZpKsE5oDn5ur+Pei+y92r1Ok9r8iNR2JoJvR1Mft/BYbZ0+nt3sW+QigG 1Zmw== X-Gm-Message-State: AOAM532AFpC8jCylN9tC4A5y5skxWukz4RC+jxhI0RyQPRhdi5FDF6MW mS8gj/FhWvaWSYzhv6tEbsbLCA== X-Received: by 2002:a17:902:b10e:b0:156:1bf8:bf26 with SMTP id q14-20020a170902b10e00b001561bf8bf26mr2277287plr.8.1648681938921; Wed, 30 Mar 2022 16:12:18 -0700 (PDT) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id ml16-20020a17090b361000b001c6c9141b0csm7303574pjb.45.2022.03.30.16.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 16:12:18 -0700 (PDT) Date: Wed, 30 Mar 2022 16:12:18 -0700 (PDT) X-Google-Original-Date: Wed, 30 Mar 2022 16:12:10 PDT (-0700) Subject: Re: [PATCH] riscv: Rename "sp_in_global" to "current_stack_pointer" In-Reply-To: CC: Paul Walmsley , keescook@chromium.org, 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 From: Palmer Dabbelt To: keescook@chromium.org Message-ID: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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).