public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Unloading a module with a function which is used by a static call
@ 2021-09-17 20:07 Denis Efremov
  2021-09-17 20:10 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Efremov @ 2021-09-17 20:07 UTC (permalink / raw)
  To: Linux-kernel, Peter Zijlstra, Josh Poimboeuf, Jason Baron

Hi,

I'm not sure, but is it intentional that we don't increase a module refcounter
when we call static_call_update()? Let's imagine that:

we load "Module A" with:
  void fire_a(...) {...}
  DEFINE_STATIC_CALL(fire, fire_a);
  EXPORT_STATIC_CALL_GPL(fire);
  static_call(fire)(); // from time-to-time
and load "Module B" that:
  void fire_b(...) {...}
  static_call_update(fire, &fire_b);

and then unload "Module B" without updating back "fire" to "fire_a".
"Module A" will try to call "fire_b" and will crash the kernel or
call something else instead. Maybe pointing static call to a default
value in static_call_del_module() with a WARN can be used instead
of module_get().

I reproduced this scenario here:
https://github.com/evdenis/static_calls_unload_test

Regards,
Denis Efremov

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Unloading a module with a function which is used by a static call
  2021-09-17 20:07 Unloading a module with a function which is used by a static call Denis Efremov
@ 2021-09-17 20:10 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2021-09-17 20:10 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Linux-kernel, Josh Poimboeuf, Jason Baron

On Fri, Sep 17, 2021 at 11:07:22PM +0300, Denis Efremov wrote:
> Hi,
> 
> I'm not sure, but is it intentional that we don't increase a module refcounter
> when we call static_call_update()? Let's imagine that:

For all intents and purposes, static_call_update() is the same as
assinging a function pointer. That also doesn't increment module counts.

If your case requires management of module refcounts, you get to do so.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-17 20:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-17 20:07 Unloading a module with a function which is used by a static call Denis Efremov
2021-09-17 20:10 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox