Re: [PATCH v3] x86: profiling: remove lock functions profiling in profile_pc

From: Josh Poimboeuf
Date: Fri Apr 28 2023 - 00:45:59 EST


On Sun, Apr 23, 2023 at 09:27:44AM +0800, Chen Zhongjin wrote:
> 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 will get return address for caller if current function
> is lock function. For !CONFIG_FRAME_POINTER it uses a hack way to get
> the caller by directly reading sp[0] or sp [1].
> It not works when KASAN is enabled because KASAN pushes data on stack
> which makes sp[0/1] become KASAN red zone. Then profile_pc reads wrong
> memory and triggers KASAN warning frequently.
>
> This hack might be ok when first added at 2006 but now it's different:
>
> 1. There are some lock functions which have frame longer than two stack
> slots. For these functions sp[0/1] is not a legal return address even
> KASAN is not enabled.
> 2. !CONFIG_FRAME_POINTER is more used today because UNWINDER_ORC.
> 3. Lock function caller information can be prfiled by perf better.
>
> Since profile as a low level facility it's not proper to depend on
> complex generic unwinder to get the next frame. As lock profiling is
> no longer useful, it's fine to remove it.

In that case we can remove the in_lock_functions() check from all the
other arches' implementations of profile_pc().

--
Josh