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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 655CFC47088 for ; Thu, 1 Dec 2022 15:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To: Message-Id:Subject:Cc: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=jROrtLVaciufTgWD27W2NXKdvgecU4NzYd1yhpBM21c=; b=B3wvj3i+GwOt60 JqxJIP0KNIiy/rJv6FplEBUCs9KPcUAmMG1q9Eg0S6LnhnOFo+VkxyZzHxrU7TCy3/q5rBXYAw3qv NK/ZRMZcgpHW9e3tRI5/rB1Rko4fruOqqSi/zf5NXm35mAxC5WK1phBwaRHHm7Sj5nr6mXjDJz83Y AiZ6ET3/UvARgw5WrckOuJhh83Yls4gMI84otz3v4XuomuehYjTt4ZxZSlhC0/3n1ZMce1LYG3hR8 bWPcz71sW2vOruyUDj/g2NxPBB++rLAb8kuJ2HHEB+1NDV4gdYPQ/fDk35ytCxQw+j3NoZUUDqr/N +ttY8c3XZmgeGRUSNaKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0ltE-008Nb0-F3; Thu, 01 Dec 2022 15:54:20 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0ltA-008NZv-Hj for linux-arm-kernel@lists.infradead.org; Thu, 01 Dec 2022 15:54:18 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D5D8862019; Thu, 1 Dec 2022 15:54:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4364EC433D6; Thu, 1 Dec 2022 15:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669910055; bh=KgUzMsnJxl5S84ksRk/ivCiFuctafV1QIdNmjNmeVz4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qeIACNxujix93s88GjoojcGg/BMy8NUgGxzPiEEICMPCDMLNuvsMxf9qqv4JwINkG jb83En2iCUhf12QEEQ2qK76W0W+OPMfXggHkGQA8WDdGTWOaMPTiCuJO+JOyDpBmSg DZviX3YW84bYt9WV9j2pJpgDSTvJIfSNDF8lUdVjvj99c083qYRC5a2N21I1y0JZZs FxwqSlKHVl8XZ7vqNcn9gZg9uAl+fN6EwMHm4iUV3XtsCEOMJqD9wn6J/AlT9dEOLb bMvedttQVHoYC7mcmPIeFo3Ofk+cHCgekZ3VSQGcSdpUEdD8+AJ6+dUGhzCSau+Vhs owlYrezZUOhoQ== Date: Fri, 2 Dec 2022 00:54:11 +0900 From: Masami Hiramatsu (Google) To: Mark Rutland Cc: Catalin Marinas , Will Deacon , Mark Brown , Kalesh Singh , Marc Zyngier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sandeepa Prabhu Subject: Re: [PATCH 1/3] arm64: Prohibit probing on arch_stack_walk() Message-Id: <20221202005411.49ee4e946e6c790bf482dbd9@kernel.org> In-Reply-To: References: <166990553243.253128.13594802750635478633.stgit@devnote3> <166990554210.253128.7378208454827328942.stgit@devnote3> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221201_075416_696589_EE8E2F91 X-CRM114-Status: GOOD ( 34.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 On Thu, 1 Dec 2022 14:47:32 +0000 Mark Rutland wrote: > Hi Masami, > > On Thu, Dec 01, 2022 at 11:39:02PM +0900, Masami Hiramatsu (Google) wrote: > > From: Masami Hiramatsu (Google) > > > > Make arch_stack_walk() as NOKPROBE_SYMBOL and make other inline functions > > called from arch_stack_walk() as nokprobe_inline so that user does not > > put probe on it, because this function can be used from return_address() > > which is already NOKPROBE_SYMBOL. > > I think it would make sense to make this noinstr rather than NOKPROBES, since > it's also used in the bowels of ftrace, and any instrumentation is liable to > lead to some mutual recursion. Yeah, OK. So use noinstr instead of notrace. > > > Without this, if the kernel built with CONFIG_LOCKDEP=y, just probing > > arch_stack_walk() via /kprobe_events will crash the kernel on > > arm64. > > > > # echo p arch_stack_walk >> ${TRACEFS}/kprobe_events > > # echo 1 > ${TRACEFS}/events/kprobes/enable > > kprobes: Failed to recover from reentered kprobes. > > kprobes: Dump kprobe: > > .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 > > ------------[ cut here ]------------ > > kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! > > kprobes: Failed to recover from reentered kprobes. > > kprobes: Dump kprobe: > > .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 > > ------------[ cut here ]------------ > > kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! > > PREEMPT SMP > > Modules linked in: > > CPU: 0 PID: 17 Comm: migration/0 Tainted: G N 6.1.0-rc5+ #6 > > Hardware name: linux,dummy-virt (DT) > > Stopper: 0x0 <- 0x0 > > pstate: 600003c5 (nZCv DAIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) > > pc : kprobe_breakpoint_handler+0x178/0x17c > > lr : kprobe_breakpoint_handler+0x178/0x17c > > sp : ffff8000080d3090 > > x29: ffff8000080d3090 x28: ffff0df5845798c0 x27: ffffc4f59057a774 > > x26: ffff0df5ffbba770 x25: ffff0df58f420f18 x24: ffff49006f641000 > > x23: ffffc4f590579768 x22: ffff0df58f420f18 x21: ffff8000080d31c0 > > x20: ffffc4f590579768 x19: ffffc4f590579770 x18: 0000000000000006 > > x17: 5f6b636174735f68 x16: 637261203d207264 x15: 64612e202c30203d > > x14: 2074657366666f2e x13: 30633178302f3078 x12: 302b6b6c61775f6b > > x11: 636174735f686372 x10: ffffc4f590dc5bd8 x9 : ffffc4f58eb31958 > > x8 : 00000000ffffefff x7 : ffffc4f590dc5bd8 x6 : 80000000fffff000 > > x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000 > > x2 : 0000000000000000 x1 : ffff0df5845798c0 x0 : 0000000000000064 > > Call trace: > > kprobes: Failed to recover from reentered kprobes. > > kprobes: Dump kprobe: > > .symbol_name = arch_stack_walk, .offset = 0, .addr = arch_stack_walk+0x0/0x1c0 > > ------------[ cut here ]------------ > > kernel BUG at arch/arm64/kernel/probes/kprobes.c:241! > > > > Fixes: 39ef362d2d45 ("arm64: Make return_address() use arch_stack_walk()") > > Cc: stable@vger.kernel.org > > Signed-off-by: Masami Hiramatsu (Google) > > --- > > arch/arm64/kernel/stacktrace.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > > index 634279b3b03d..b0e913f944b4 100644 > > --- a/arch/arm64/kernel/stacktrace.c > > +++ b/arch/arm64/kernel/stacktrace.c > > @@ -23,7 +23,7 @@ > > * > > * The regs must be on a stack currently owned by the calling task. > > */ > > -static inline void unwind_init_from_regs(struct unwind_state *state, > > +static nokprobe_inline void unwind_init_from_regs(struct unwind_state *state, > > struct pt_regs *regs) > > { > > unwind_init_common(state, current); > > @@ -40,7 +40,7 @@ static inline void unwind_init_from_regs(struct unwind_state *state, > > * > > * The function which invokes this must be noinline. > > */ > > -static __always_inline void unwind_init_from_caller(struct unwind_state *state) > > +static nokprobe_inline void unwind_init_from_caller(struct unwind_state *state) > > This code must be __always_inline to get the correct caller context, so making > this nokprobe_inline breaks a CONFIG_KPROBES=n build of the kernel. Oops, indeed. > > This also shouldn't be necessary; nokprobe_inline *is* __always_inline when > CONFIG_KPROBES=y. > > As above, I'd prefer that we mark these helpers as __always_inline and mark the > main entry point as noinstr. OK. Thank you, > > Thanks, > Mark. > > > { > > unwind_init_common(state, current); > > > > @@ -58,7 +58,7 @@ static __always_inline void unwind_init_from_caller(struct unwind_state *state) > > * duration of the unwind, or the unwind will be bogus. It is never valid to > > * call this for the current task. > > */ > > -static inline void unwind_init_from_task(struct unwind_state *state, > > +static nokprobe_inline void unwind_init_from_task(struct unwind_state *state, > > struct task_struct *task) > > { > > unwind_init_common(state, task); > > @@ -218,3 +218,4 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, > > > > unwind(&state, consume_entry, cookie); > > } > > +NOKPROBE_SYMBOL(arch_stack_walk); > > -- Masami Hiramatsu (Google) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel