From: Maninder Singh <maninder1.s@samsung.com>
To: Maninder Singh <maninder1.s@samsung.com>,
"jpoimboe@kernel.org" <jpoimboe@kernel.org>,
"peterz@infradead.org" <peterz@infradead.org>,
"tglx@kernel.org" <tglx@kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"bp@alien8.de" <bp@alien8.de>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"luto@kernel.org" <luto@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>,
Rohit Thapliyal <r.thapliyal@samsung.com>
Subject: RE: [PATCH 1/1] x86: dumpstack: take stack reference before accessing it
Date: Mon, 23 Mar 2026 10:35:37 +0530 [thread overview]
Message-ID: <20260323050537epcms5p3c96d8f60d896dbee3fa78abe4fa855b6@epcms5p3> (raw)
In-Reply-To: <20260311052144.2692271-1-maninder1.s@samsung.com>
ping! Any inputs to this, if it is an actual issue or not ?
> --------- Original Message ---------
> Sender : Maninder Singh <maninder1.s@samsung.com>
> Date : 2026-03-11 10:51 (GMT+5:30)
> Title : [PATCH 1/1] x86: dumpstack: take stack reference before accessing it
>
>
> with THREAD_INFO_IN_TASK, stack of task can be
> freed earlier than task (even if task's reference is taken),
> and it needs separate reference with try_get_task_stack()
> before using the stack.
>
> Added a dummy code to save task_struct to reproduce the race in kernel:
>
> $ sleep 10 &
> $ take reference of sleep in kernel code in parallel
>
> rcu_read_lock();
> for_each_process(p) {
> if (!strcmp(p->comm, "sleep")) {
> check_task = p;
> get_task_struct(check_task);
> }
> }
> rcu_read_unlock();
>
> // in mean time here sleep binary will be exited,
> now call show_stack for it.
>
> show_stack(check_task, NULL, KERN_EMERG);
>
> //OOPs here
>
> [ 49.887151] BUG: unable to handle page fault for address: ffffb57400213de8
> ...
> [ 49.889329] CPU: 0 UID: 0 PID: 68 Comm: cat Not tainted 7.0.0-rc2-next-20260302-00003-gb7e059f3a5ae-dirty #49 PREEMPT(lazy)
> [ 49.889789] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
> [ 49.890204] RIP: 0010:__unwind_start+0x118/0x1c0
> ....
> [ 49.893485] Call Trace:
> [ 49.893700] <TASK>
> [ 49.893810] __show_trace_log_lvl+0x31f/0x360
> [ 49.893988] ? mas_store_prealloc+0x99/0x2c0
> [ 49.894169] meminfo_proc_show+0xdd/0x9a0
> [ 49.894312] ? seq_open+0x3b/0x60
> [ 49.894435] ? __pfx_meminfo_proc_show+0x10/0x10
> [ 49.894568] ? file_ra_state_init+0x10/0x30
> [ 49.894731] ? __pte_offset_map+0x16/0xd0
> [ 49.894871] ? seq_read_iter+0x38e/0x4b0
> [ 49.895004] seq_read_iter+0x109/0x4b0
> [ 49.895125] copy_splice_read+0x18f/0x330
> [ 49.895272] splice_direct_to_actor+0xb4/0x250
>
> Thus taking reference of task's stack before accessing it in
> show_stack() similar to get_wchan() and stack_trace_save_tsk().
>
> Fixes: 68f24b08ee89 ("sched/core: Free the stack early if CONFIG_THREAD_INFO_IN_TASK")
> Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
> ---
> original discussion for sending this patch for comment: https://lkml.org/lkml/2026/3/5/299
>
> arch/x86/kernel/dumpstack.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
> index b10684dedc58..3d44db836cd3 100644
> --- a/arch/x86/kernel/dumpstack.c
> +++ b/arch/x86/kernel/dumpstack.c
> @@ -190,6 +190,9 @@ static void __show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
> int graph_idx = 0;
> bool partial = false;
>
> + if (!try_get_task_stack(task))
> + return;
> +
> printk("%sCall Trace:\n", log_lvl);
>
> unwind_start(&state, task, regs, stack);
> @@ -301,6 +304,8 @@ static void __show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
> if (stack_name)
> printk("%s </%s>\n", log_lvl, stack_name);
> }
> +
> + put_task_stack(task);
> }
>
> static void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
> --
> 2.34.1
prev parent reply other threads:[~2026-03-23 5:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20260311052153epcas5p3caa5436954e9a2d2e9ec504fe1278a89@epcas5p3.samsung.com>
2026-03-11 5:21 ` Maninder Singh
[not found] ` <CGME20260311052153epcas5p3caa5436954e9a2d2e9ec504fe1278a89@epcms5p3>
2026-03-23 5:05 ` Maninder Singh [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323050537epcms5p3c96d8f60d896dbee3fa78abe4fa855b6@epcms5p3 \
--to=maninder1.s@samsung.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=r.thapliyal@samsung.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®