From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC25E36D4E6 for ; Thu, 27 Nov 2025 09:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764234962; cv=none; b=aXfKGLIWjat9CrUqTOke4K5GjnOCfIhqTuEx2tvofKzkfboMaSqgr+5xQdQkTeOm1B3qb7lxEkb2tGvDuU8bjElIrR4IjSyDIxV7uQRuHPedPNsh4y0LszTGNvjp+rIp4EDRWCGnCHY+jX6GDZIbtGfb0QIm/Ien6VF/mDGB5/E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764234962; c=relaxed/simple; bh=XivCFpsiORmcMMjYshd1KFCwzRy3fds9WJYiw7dmh2c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FLaSwaiWfVqOHcH9XYjrRWFQe75iR+owjy+b6Owo6fLM6bVB9ksHA6pxCWVXbH95oDNzGI+upDSJrbP+OPWUKfQGOxKQugdqvcU7nTA2FREFODl/o7ZpaM6ZrBdJu/YCt/U2y2F4eTheCcPCkNMprr6Im3EJqNuDIW+nzY6yrro= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 3AC761477; Thu, 27 Nov 2025 01:15:51 -0800 (PST) Received: from J2N7QTR9R3 (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0D2BF3F66E; Thu, 27 Nov 2025 01:15:54 -0800 (PST) Date: Thu, 27 Nov 2025 09:15:49 +0000 From: Mark Rutland To: Onkarnath Cc: catalin.marinas@arm.com, will@kernel.org, ada.coupriediaz@arm.com, thuth@redhat.com, broonie@kernel.org, song@kernel.org, yeoreum.yun@arm.com, kevin.brodsky@arm.com, ryan.roberts@arm.com, jeremy.linton@arm.com, maz@kernel.org, smostafa@google.com, leitao@debian.org, bigeasy@linutronix.de, kees@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, maninder1.s@samsung.com, r.thapliyal@samsung.com, Sarvesh Kadam Subject: Re: [PATCH 1/1] arm64: Print slab alloc and free paths for addresses in registers Message-ID: References: <20251127060227.3575956-1-onkarnath.1@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251127060227.3575956-1-onkarnath.1@samsung.com> On Thu, Nov 27, 2025 at 11:32:27AM +0530, Onkarnath wrote: > When debugging use-after-free kernel oopses, knowing the allocation and > freeing paths of an object is crucial. Like arm this patch enhances arm64 > debugging by checking if register addresses belong to a slab and printing > their corresponding alloc and free paths. > > For example x21 prints alloc and free path: > > pc : crash_init+0x44/0x64 [crash] > lr : crash_init+0x34/0x64 [crash] > ..... These dots are hiding *tonnes* of lines. Please see my response from the last time this was proposed: https://lore.kernel.org/linux-arm-kernel/ZcDa2RXC6z7XuwAD@FVFF77S0Q05N/ At a high level, I still don't think this is a good idea. > Register x21 information: slab task_struct start ffff0000c3cc7000 data offset 64 pointer offset 0 size 3904 allocated at copy_process+0x1ac/0x14a4 > kmem_cache_alloc_node_noprof+0x208/0x4a8 > copy_process+0x1ac/0x14a4 > kernel_clone+0x70/0x380 > __arm64_sys_fork+0x40/0x7c > invoke_syscall+0x48/0x104 > el0_svc_common.constprop.0+0x40/0xe0 > do_el0_svc_compat+0x1c/0x34 > el0_svc_compat+0x2c/0x90 > el0t_32_sync_handler+0x88/0xac > el0t_32_sync+0x19c/0x1a0 > Free path: > kmem_cache_free+0x3c0/0x430 > free_task+0x54/0x80 > __put_task_struct+0x100/0x15c > __put_task_struct_rcu_cb+0x14/0x20 > rcu_core+0x264/0x680 > rcu_core_si+0x10/0x1c > handle_softirqs+0x100/0x244 > __do_softirq+0x14/0x20 > > Co-developed-by: Sarvesh Kadam > Signed-off-by: Sarvesh Kadam > Signed-off-by: Onkarnath > --- > arch/arm64/include/asm/system_misc.h | 1 + > arch/arm64/kernel/process.c | 11 +++++++++++ > arch/arm64/kernel/traps.c | 2 +- > 3 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/system_misc.h b/arch/arm64/include/asm/system_misc.h > index d316a804eb38..9cb9749d8853 100644 > --- a/arch/arm64/include/asm/system_misc.h > +++ b/arch/arm64/include/asm/system_misc.h > @@ -27,6 +27,7 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, > > struct mm_struct; > extern void __show_regs(struct pt_regs *); > +extern void __show_regs_alloc_free(struct pt_regs *regs); > > #endif /* __ASSEMBLER__ */ > > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > index fba7ca102a8c..7738ec8e5cd5 100644 > --- a/arch/arm64/kernel/process.c > +++ b/arch/arm64/kernel/process.c > @@ -199,6 +199,17 @@ static void print_pstate(struct pt_regs *regs) > } > } > > +void __show_regs_alloc_free(struct pt_regs *regs) > +{ > + int i; > + > + /* check for x0 - x31 only */ > + for (i = 0; i < 31; i++) { > + pr_alert("Register x%d information:", i); > + mem_dump_obj((void *)regs->regs[i]); > + } > +} The comment should say 'x31' rather than 'x30'. > + > void __show_regs(struct pt_regs *regs) > { > int i, top_reg; > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > index 914282016069..3b01379b8880 100644 > --- a/arch/arm64/kernel/traps.c > +++ b/arch/arm64/kernel/traps.c > @@ -189,7 +189,7 @@ static int __die(const char *str, long err, struct pt_regs *regs) > > print_modules(); > show_regs(regs); > - > + __show_regs_alloc_free(regs); > if (user_mode(regs)) > return ret; If the regs are user regs, then the registers do not contain kernel addresses. We shouldn't interpret the registers in that case. We use die() and __die() for many exceptions that are entirely unrelated to use-after-free (e.g. BTI exceptions), so this is going to be noisy for no benefit. Mark.