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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 61722C4361B for ; Tue, 8 Dec 2020 10:21:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 0173123AA7 for ; Tue, 8 Dec 2020 10:21:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0173123AA7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+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=merlin.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=KPilO2nTaJqDaG43onodSAMJb1H1g+9o9Wj4fAR7Ygs=; b=JIm+C7Uc/Feealzg9yZd/0Xmm eykev+Vk72wSocfgyv045STIVh3O6ND3z/cjywWKd72bCWjORiP9svt1LXZJe/ORCRIfBIN4Vm31f IkxJ+agJc2PN+WqZg5Mk7vQyPvLQArL9iPYU6jYytA647zviKP7b2ZpAbsSeEbeX9Uq0+HvjzL/PH AsD4q+qpmGZ+ExnxG9SCLn/zhHNBTUL00lF9ZxQRPrgQmdOY3WNrTPfqqn+j+pdAI1JacgmZ3kWPq Jb5c69tHGScuXGvhpNKhPBvGgw/0v60QuiG01qrw1dAbv5vrfaWSTBrO0N0RUhdO5W9PDaPv+4YPQ SDxizwvsg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kma6g-0001yQ-DO; Tue, 08 Dec 2020 10:20:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kma6e-0001xz-ER for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 10:20:29 +0000 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 2DFC81FB; Tue, 8 Dec 2020 02:20:27 -0800 (PST) Received: from C02TD0UTHF1T.local (unknown [10.57.29.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DF5523F68F; Tue, 8 Dec 2020 02:20:24 -0800 (PST) Date: Tue, 8 Dec 2020 10:20:16 +0000 From: Mark Rutland To: Peter Collingbourne Subject: Re: [PATCH v3 1/3] arm64: Change the on_*stack functions to take a size argument Message-ID: <20201208102016.GA14327@C02TD0UTHF1T.local> References: <01b1819ec213797c9cd44bc23a9e9641f3bb64b2.1606972188.git.pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <01b1819ec213797c9cd44bc23a9e9641f3bb64b2.1606972188.git.pcc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_052028_612884_5FD335C3 X-CRM114-Status: GOOD ( 25.20 ) 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: Catalin Marinas , Mark Brown , Linux ARM , Andrey Konovalov , Will Deacon , Ard Biesheuvel , Evgenii Stepanov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Peter, Thanks for bearing with all the review comments. The patches look good to me now, and I've given this some light testing locally with a tip-of-tree clang (testing KASAN with LKDTM, and a short soak under Syzkaller with lots of debug enabled) and that hasn't highlighted any problems. So for the series: Reviewed-by: Mark Rutland Tested-by: Mark Rutland Thanks, Mark. On Wed, Dec 02, 2020 at 09:12:22PM -0800, Peter Collingbourne wrote: > unwind_frame() was previously implicitly checking that the frame > record is in bounds of the stack by enforcing that FP is both aligned > to 16 and in bounds of the stack. Once the FP alignment requirement > is relaxed to 8 this will not be sufficient because it does not > account for the case where FP points to 8 bytes before the end of the > stack. > > Make the check explicit by changing the on_*stack functions to take a > size argument and adjusting the callers to pass the appropriate sizes. > > Signed-off-by: Peter Collingbourne > Link: https://linux-review.googlesource.com/id/Ib7a3eb3eea41b0687ffaba045ceb2012d077d8b4 > --- > arch/arm64/include/asm/processor.h | 12 +++++------ > arch/arm64/include/asm/sdei.h | 7 ++++--- > arch/arm64/include/asm/stacktrace.h | 32 ++++++++++++++--------------- > arch/arm64/kernel/ptrace.c | 2 +- > arch/arm64/kernel/sdei.c | 16 ++++++++------- > arch/arm64/kernel/stacktrace.c | 2 +- > 6 files changed, 37 insertions(+), 34 deletions(-) > > diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h > index fce8cbecd6bc..bf3e07f67e79 100644 > --- a/arch/arm64/include/asm/processor.h > +++ b/arch/arm64/include/asm/processor.h > @@ -318,13 +318,13 @@ long get_tagged_addr_ctrl(struct task_struct *task); > * of header definitions for the use of task_stack_page. > */ > > -#define current_top_of_stack() \ > -({ \ > - struct stack_info _info; \ > - BUG_ON(!on_accessible_stack(current, current_stack_pointer, &_info)); \ > - _info.high; \ > +#define current_top_of_stack() \ > +({ \ > + struct stack_info _info; \ > + BUG_ON(!on_accessible_stack(current, current_stack_pointer, 1, &_info)); \ > + _info.high; \ > }) > -#define on_thread_stack() (on_task_stack(current, current_stack_pointer, NULL)) > +#define on_thread_stack() (on_task_stack(current, current_stack_pointer, 1, NULL)) > > #endif /* __ASSEMBLY__ */ > #endif /* __ASM_PROCESSOR_H */ > diff --git a/arch/arm64/include/asm/sdei.h b/arch/arm64/include/asm/sdei.h > index 63e0b92a5fbb..8bc30a5c4569 100644 > --- a/arch/arm64/include/asm/sdei.h > +++ b/arch/arm64/include/asm/sdei.h > @@ -42,8 +42,9 @@ unsigned long sdei_arch_get_entry_point(int conduit); > > struct stack_info; > > -bool _on_sdei_stack(unsigned long sp, struct stack_info *info); > -static inline bool on_sdei_stack(unsigned long sp, > +bool _on_sdei_stack(unsigned long sp, unsigned long size, > + struct stack_info *info); > +static inline bool on_sdei_stack(unsigned long sp, unsigned long size, > struct stack_info *info) > { > if (!IS_ENABLED(CONFIG_VMAP_STACK)) > @@ -51,7 +52,7 @@ static inline bool on_sdei_stack(unsigned long sp, > if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) > return false; > if (in_nmi()) > - return _on_sdei_stack(sp, info); > + return _on_sdei_stack(sp, size, info); > > return false; > } > diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h > index eb29b1fe8255..77192df232bf 100644 > --- a/arch/arm64/include/asm/stacktrace.h > +++ b/arch/arm64/include/asm/stacktrace.h > @@ -69,14 +69,14 @@ extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, > > DECLARE_PER_CPU(unsigned long *, irq_stack_ptr); > > -static inline bool on_stack(unsigned long sp, unsigned long low, > - unsigned long high, enum stack_type type, > - struct stack_info *info) > +static inline bool on_stack(unsigned long sp, unsigned long size, > + unsigned long low, unsigned long high, > + enum stack_type type, struct stack_info *info) > { > if (!low) > return false; > > - if (sp < low || sp >= high) > + if (sp < low || sp + size < sp || sp + size > high) > return false; > > if (info) { > @@ -87,38 +87,38 @@ static inline bool on_stack(unsigned long sp, unsigned long low, > return true; > } > > -static inline bool on_irq_stack(unsigned long sp, > +static inline bool on_irq_stack(unsigned long sp, unsigned long size, > struct stack_info *info) > { > unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr); > unsigned long high = low + IRQ_STACK_SIZE; > > - return on_stack(sp, low, high, STACK_TYPE_IRQ, info); > + return on_stack(sp, size, low, high, STACK_TYPE_IRQ, info); > } > > static inline bool on_task_stack(const struct task_struct *tsk, > - unsigned long sp, > + unsigned long sp, unsigned long size, > struct stack_info *info) > { > unsigned long low = (unsigned long)task_stack_page(tsk); > unsigned long high = low + THREAD_SIZE; > > - return on_stack(sp, low, high, STACK_TYPE_TASK, info); > + return on_stack(sp, size, low, high, STACK_TYPE_TASK, info); > } > > #ifdef CONFIG_VMAP_STACK > DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack); > > -static inline bool on_overflow_stack(unsigned long sp, > +static inline bool on_overflow_stack(unsigned long sp, unsigned long size, > struct stack_info *info) > { > unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack); > unsigned long high = low + OVERFLOW_STACK_SIZE; > > - return on_stack(sp, low, high, STACK_TYPE_OVERFLOW, info); > + return on_stack(sp, size, low, high, STACK_TYPE_OVERFLOW, info); > } > #else > -static inline bool on_overflow_stack(unsigned long sp, > +static inline bool on_overflow_stack(unsigned long sp, unsigned long size, > struct stack_info *info) { return false; } > #endif > > @@ -128,21 +128,21 @@ static inline bool on_overflow_stack(unsigned long sp, > * context. > */ > static inline bool on_accessible_stack(const struct task_struct *tsk, > - unsigned long sp, > + unsigned long sp, unsigned long size, > struct stack_info *info) > { > if (info) > info->type = STACK_TYPE_UNKNOWN; > > - if (on_task_stack(tsk, sp, info)) > + if (on_task_stack(tsk, sp, size, info)) > return true; > if (tsk != current || preemptible()) > return false; > - if (on_irq_stack(sp, info)) > + if (on_irq_stack(sp, size, info)) > return true; > - if (on_overflow_stack(sp, info)) > + if (on_overflow_stack(sp, size, info)) > return true; > - if (on_sdei_stack(sp, info)) > + if (on_sdei_stack(sp, size, info)) > return true; > > return false; > diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c > index f49b349e16a3..b44d6981decb 100644 > --- a/arch/arm64/kernel/ptrace.c > +++ b/arch/arm64/kernel/ptrace.c > @@ -122,7 +122,7 @@ static bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr) > { > return ((addr & ~(THREAD_SIZE - 1)) == > (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1))) || > - on_irq_stack(addr, NULL); > + on_irq_stack(addr, sizeof(unsigned long), NULL); > } > > /** > diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c > index 793c46d6a447..ee8a13ce239b 100644 > --- a/arch/arm64/kernel/sdei.c > +++ b/arch/arm64/kernel/sdei.c > @@ -91,31 +91,33 @@ static int init_sdei_stacks(void) > return err; > } > > -static bool on_sdei_normal_stack(unsigned long sp, struct stack_info *info) > +static bool on_sdei_normal_stack(unsigned long sp, unsigned long size, > + struct stack_info *info) > { > unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr); > unsigned long high = low + SDEI_STACK_SIZE; > > - return on_stack(sp, low, high, STACK_TYPE_SDEI_NORMAL, info); > + return on_stack(sp, size, low, high, STACK_TYPE_SDEI_NORMAL, info); > } > > -static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info) > +static bool on_sdei_critical_stack(unsigned long sp, unsigned long size, > + struct stack_info *info) > { > unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr); > unsigned long high = low + SDEI_STACK_SIZE; > > - return on_stack(sp, low, high, STACK_TYPE_SDEI_CRITICAL, info); > + return on_stack(sp, size, low, high, STACK_TYPE_SDEI_CRITICAL, info); > } > > -bool _on_sdei_stack(unsigned long sp, struct stack_info *info) > +bool _on_sdei_stack(unsigned long sp, unsigned long size, struct stack_info *info) > { > if (!IS_ENABLED(CONFIG_VMAP_STACK)) > return false; > > - if (on_sdei_critical_stack(sp, info)) > + if (on_sdei_critical_stack(sp, size, info)) > return true; > > - if (on_sdei_normal_stack(sp, info)) > + if (on_sdei_normal_stack(sp, size, info)) > return true; > > return false; > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index fa56af1a59c3..ce613e22b58b 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -50,7 +50,7 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) > if (!tsk) > tsk = current; > > - if (!on_accessible_stack(tsk, fp, &info)) > + if (!on_accessible_stack(tsk, fp, 16, &info)) > return -EINVAL; > > if (test_bit(info.type, frame->stacks_done)) > -- > 2.29.2.454.gaff20da3a2-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel