From: "Matthew Bystrin" <dev.mbstr@gmail.com>
To: "Jiakai Xu" <xujiakai2025@iscas.ac.cn>,
<linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>
Cc: "Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Chunyan Zhang" <zhangchunyan@iscas.ac.cn>,
"Matthew Bystrin" <dev.mbstr@gmail.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Paul Walmsley" <pjw@kernel.org>,
"Samuel Holland" <samuel.holland@sifive.com>
Subject: Re: [PATCH] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe
Date: Thu, 14 May 2026 17:21:36 +0300 [thread overview]
Message-ID: <DIIGT2B04NER.LLGB7WGGPC2N@gmail.com> (raw)
In-Reply-To: <20260514100711.838895-1-xujiakai2025@iscas.ac.cn>
Hi, Jiakai!
Thanks for your valid correction!
Jiakai Xu, May 14, 2026 at 13:07:
> -static inline int fp_is_valid(unsigned long fp, unsigned long sp)
> +static inline int fp_is_valid(unsigned long fp, unsigned long sp,
> + struct task_struct *task)
> {
> unsigned long low, high;
>
> + if (!task)
> + task = current;
> +
I would suggest to move this `if` into walk_stackframe() function in order to do
this only once before walking loop.
> low = sp + sizeof(struct stackframe);
> - high = ALIGN(sp, THREAD_SIZE);
> + high = (unsigned long)task_stack_page(task) + THREAD_SIZE;
Also after grepping `task_stack_page` I've noticed that pt_regs structure is
located at the end of stack. Maybe it is a good idea to adjust border even
"lower" to check that sp does not points inside pt_regs? (see task_pt_regs
macro)
> return !(fp < low || fp > high || fp & 0x07);
> }
--
Best regards,
Matt
next prev parent reply other threads:[~2026-05-14 14:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-14 10:07 [PATCH] riscv: stacktrace: fix stack-out-of-bounds in walk_stackframe Jiakai Xu
2026-05-14 14:21 ` Matthew Bystrin [this message]
2026-05-15 1:36 ` Jiakai Xu
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=DIIGT2B04NER.LLGB7WGGPC2N@gmail.com \
--to=dev.mbstr@gmail.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=samuel.holland@sifive.com \
--cc=xujiakai2025@iscas.ac.cn \
--cc=zhangchunyan@iscas.ac.cn \
/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