linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Edward AD <twuufnxlz@gmail.com>
To: alex@ghiti.fr
Cc: alexghiti@rivosinc.com, aou@eecs.berkeley.edu, conor@kernel.org,
	gregkh@linuxfoundation.org, guoren@kernel.org,
	jirislaby@kernel.org, linux-kernel@vger.kernel.org,
	linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org,
	liushixin2@huawei.com, palmer@dabbelt.com,
	paul.walmsley@sifive.com,
	syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com, twuufnxlz@gmail.com
Subject: [PATCH] riscv: fix out of bounds in walk_stackframe
Date: Fri, 29 Sep 2023 07:12:40 +0800	[thread overview]
Message-ID: <20230928231239.2144579-2-twuufnxlz@gmail.com> (raw)
In-Reply-To: <f74665d1-4d28-01a2-5694-b06fde202d39@ghiti.fr>

Add vmalloc and kernel addresses check to prevent invalid access.

Closes: https://lore.kernel.org/all/20230926105949.1025995-2-twuufnxlz@gmail.com/
Fixes: 5d8544e2d007 ("RISC-V: Generic library routines and assembly")
Reported-and-test-by: syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com
Link: https://lore.kernel.org/all/0000000000000170df0605ccf91a@google.com/T/
Signed-off-by: Edward AD <twuufnxlz@gmail.com>
---
 arch/riscv/kernel/stacktrace.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
index 64a9c093aef9..031a4a35c1d0 100644
--- a/arch/riscv/kernel/stacktrace.c
+++ b/arch/riscv/kernel/stacktrace.c
@@ -54,6 +54,9 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
 			break;
 		/* Unwind stack frame */
 		frame = (struct stackframe *)fp - 1;
+		if ((is_vmalloc_addr(frame) && !pfn_valid(page_to_pfn(vmalloc_to_page(frame)))) || 
+		     !virt_addr_valid(frame))
+			break;
 		sp = fp;
 		if (regs && (regs->epc == pc) && (frame->fp & 0x7)) {
 			fp = frame->ra;
-- 
2.25.1


  reply	other threads:[~2023-09-28 23:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 16:36 [syzbot] [serial?] KASAN: stack-out-of-bounds Read in sched_show_task syzbot
2023-09-26 10:59 ` [PATCH] riscv: fix out of bounds in walk_stackframe Edward AD
2023-09-26 11:12   ` Conor Dooley
2023-09-26 11:43 ` Edward AD
2023-09-26 11:49   ` Greg KH
2023-09-28  8:02   ` Alexandre Ghiti
2023-09-28  8:15     ` Alexandre Ghiti
2023-09-28 23:12       ` Edward AD [this message]
2023-09-29  6:04         ` Greg KH
2023-09-29 23:05           ` [PATCH] Test for riscv fixes Edward AD
2023-09-30  6:13             ` Greg KH
2023-09-30  8:24               ` Conor Dooley
2023-10-02 10:20                 ` Aleksandr Nogikh
2023-09-29  6:05         ` [PATCH] riscv: fix out of bounds in walk_stackframe Greg KH
2023-09-29  8:25         ` Alexandre Ghiti
2023-09-29 23:05           ` [PATCH] Test for riscv fixes Edward AD
2023-10-02  7:13             ` Alexandre Ghiti
2023-10-02 13:41               ` Mark Rutland
2023-10-06 11:38                 ` Alexandre Ghiti

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=20230928231239.2144579-2-twuufnxlz@gmail.com \
    --to=twuufnxlz@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=alexghiti@rivosinc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=guoren@kernel.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=liushixin2@huawei.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=syzbot+8d2757d62d403b2d9275@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /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;
as well as URLs for NNTP newsgroup(s).