Re: [PATCH] static_call: Handle module init failure correctly in static_call_del_module()

From: Thomas Gleixner
Date: Wed Sep 04 2024 - 03:08:29 EST


On Wed, Sep 04 2024 at 11:32, Jinjie Ruan wrote:
> On 2024/9/4 6:58, Thomas Gleixner wrote:
>> + /*
>> + * If the key was not updated due to a memory allocation
>> + * failure in __static_call_init() then treating key::sites
>> + * as key::mods in the code below would cause random memory
>> + * access and #GP. In that case all subsequent sites have
>> + * not been touched either, so stop iterating.
>> + */
>> + if (static_call_key_sites(key))
>> + break;
>> +
>
> Hi, Thomas,
>
> This patch seems not solve the issue, with this patch, the below problem
> also occurs when inject fault when modprobe amdgpu:

That's a different problem.

Oops: general protection fault, probably for
non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN NOPTI

It's dereferencing a NULL pointer at 0x1. That's odd because bit 0 is
set, which looks like a sites pointer. So static_call_key_sites() should
return true, but obviously does not. So how does that happen?

It can't be a built-in key, so it's a module local one with key::sites
== 0x1. So static_call_key_sites() sees bit 0 set, and then returns
key::sites & ~0x01, which is obviously NULL. So the condition is false
and the code below uses key::mods == 0x1....

So the check must be:

if (!static_call_key_has_mods(key))
break;

I missed the module local case completely in my analysis. Can you please
modify the condition and retest?

Thanks,

tglx