Thread (6 messages) flat view 6 messages, 4 authors, 2021-08-09

Re: [PATCH v2] once: Fix panic when module unload

From: Kefeng Wang <hidden>
Date: 2021-08-09 01:13:54
Also in: lkml

On 2021/8/6 23:22, Hannes Frederic Sowa wrote:
On Fri, Aug 6, 2021, at 10:21, Kefeng Wang wrote:
quoted
DO_ONCE
DEFINE_STATIC_KEY_TRUE(___once_key);
__do_once_done
   once_disable_jump(once_key);
     INIT_WORK(&w->work, once_deferred);
     struct once_work *w;
     w->key = key;
     schedule_work(&w->work);                     module unload
                                                    //*the key is
destroy*
process_one_work
   once_deferred
     BUG_ON(!static_key_enabled(work->key));
        static_key_count((struct static_key *)x)    //*access key, crash*

When module uses DO_ONCE mechanism, it could crash due to the above
concurrency problem, we could reproduce it with link[1].

Fix it by add/put module refcount in the once work process.

[1]
https://lore.kernel.org/netdev/eaa6c371-465e-57eb-6be9-f4b16b9d7cbf@huawei.com/ (local)

Cc: Hannes Frederic Sowa <redacted>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Reported-by: Minmin chen <redacted>
Signed-off-by: Kefeng Wang <redacted>
Acked-by: Hannes Frederic Sowa <redacted>
Thanks.
Thanks,
Hannes
.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help