From: Chen Zhongjin <chenzhongjin@huawei.com>
To: <x86@kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
<dave.hansen@linux.intel.com>, <hpa@zytor.com>,
<chenzhongjin@huawei.com>, <akpm@linux-foudation.org>,
<ben-linux@fluff.org>, <wuchi.zero@gmail.com>
Subject: [PATCH 1/2] x86: profiling: remove lock functions hack for !FRAME_POINTER
Date: Mon, 10 Apr 2023 10:22:25 +0800 [thread overview]
Message-ID: <20230410022226.181812-2-chenzhongjin@huawei.com> (raw)
In-Reply-To: <20230410022226.181812-1-chenzhongjin@huawei.com>
Syzbot has been reporting the problem of stack-out-of-bounds in
profile_pc for a long time:
https://syzkaller.appspot.com/bug?extid=84fe685c02cd112a2ac3
profile_pc tries to get pc if current regs is inside lock function. For
!CONFIG_FRAME_POINTER it used a hack way to get the pc from stack, which
is not work with ORC. It makes profile_pc read illeagal address, return
wrong result, and frequently triggers KASAN.
Since lock profiling can be handled with much better other tools, It's
reasonable to remove lock functions hack for !FRAME_POINTER kernel.
Suggested-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
---
arch/x86/kernel/time.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
index e42faa792c07..e08fac7bb71e 100644
--- a/arch/x86/kernel/time.c
+++ b/arch/x86/kernel/time.c
@@ -29,22 +29,10 @@ unsigned long profile_pc(struct pt_regs *regs)
{
unsigned long pc = instruction_pointer(regs);
- if (!user_mode(regs) && in_lock_functions(pc)) {
#ifdef CONFIG_FRAME_POINTER
+ if (!user_mode(regs) && in_lock_functions(pc))
return *(unsigned long *)(regs->bp + sizeof(long));
-#else
- unsigned long *sp = (unsigned long *)regs->sp;
- /*
- * Return address is either directly at stack pointer
- * or above a saved flags. Eflags has bits 22-31 zero,
- * kernel addresses don't.
- */
- if (sp[0] >> 22)
- return sp[0];
- if (sp[1] >> 22)
- return sp[1];
#endif
- }
return pc;
}
EXPORT_SYMBOL(profile_pc);
--
2.17.1
next prev parent reply other threads:[~2023-04-10 2:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-10 2:22 [PATCH 0/2] Fix two bugs for profile Chen Zhongjin
2023-04-10 2:22 ` Chen Zhongjin [this message]
2023-04-10 19:34 ` [PATCH 1/2] x86: profiling: remove lock functions hack for !FRAME_POINTER Dave Hansen
2023-04-12 7:01 ` Chen Zhongjin
2023-04-12 10:01 ` David Laight
2023-04-13 7:53 ` Chen Zhongjin
2023-04-19 16:17 ` Josh Poimboeuf
2023-04-19 15:43 ` Josh Poimboeuf
2023-04-10 2:22 ` [PATCH 2/2] profiling: Check prof_buffer in profile_tick() Chen Zhongjin
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=20230410022226.181812-2-chenzhongjin@huawei.com \
--to=chenzhongjin@huawei.com \
--cc=akpm@linux-foudation.org \
--cc=ben-linux@fluff.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=wuchi.zero@gmail.com \
--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®