Skip to content

Commit

Permalink
kernel/notifier.c: intercept duplicate registrations to avoid infinit…
Browse files Browse the repository at this point in the history
…e loops

Registering the same notifier to a hook repeatedly can cause the hook
list to form a ring or lose other members of the list.

  case1: An infinite loop in notifier_chain_register() can cause soft lockup
          atomic_notifier_chain_register(&test_notifier_list, &test1);
          atomic_notifier_chain_register(&test_notifier_list, &test1);
          atomic_notifier_chain_register(&test_notifier_list, &test2);

  case2: An infinite loop in notifier_chain_register() can cause soft lockup
          atomic_notifier_chain_register(&test_notifier_list, &test1);
          atomic_notifier_chain_register(&test_notifier_list, &test1);
          atomic_notifier_call_chain(&test_notifier_list, 0, NULL);

  case3: lose other hook test2
          atomic_notifier_chain_register(&test_notifier_list, &test1);
          atomic_notifier_chain_register(&test_notifier_list, &test2);
          atomic_notifier_chain_register(&test_notifier_list, &test1);

  case4: Unregister returns 0, but the hook is still in the linked list,
         and it is not really registered. If you call
         notifier_call_chain after ko is unloaded, it will trigger oops.

If the system is configured with softlockup_panic and the same hook is
repeatedly registered on the panic_notifier_list, it will cause a loop
panic.

Add a check in notifier_chain_register(), intercepting duplicate
registrations to avoid infinite loops

Link: http:https://lkml.kernel.org/r/[email protected]
Signed-off-by: Xiaoming Ni <[email protected]>
Reviewed-by: Vasily Averin <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Cc: Anna Schumaker <[email protected]>
Cc: Arjan van de Ven <[email protected]>
Cc: J. Bruce Fields <[email protected]>
Cc: Chuck Lever <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Jeff Layton <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Nadia Derbey <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Sam Protsenko <[email protected]>
Cc: Alan Stern <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Trond Myklebust <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: Xiaoming Ni <[email protected]>
Cc: YueHaibing <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
nixiaoming authored and torvalds committed Dec 5, 2019
1 parent d717e7d commit 1a50cb8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kernel/notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ static int notifier_chain_register(struct notifier_block **nl,
struct notifier_block *n)
{
while ((*nl) != NULL) {
WARN_ONCE(((*nl) == n), "double register detected");
if (unlikely((*nl) == n)) {
WARN(1, "double register detected");
return 0;
}
if (n->priority > (*nl)->priority)
break;
nl = &((*nl)->next);
Expand Down

0 comments on commit 1a50cb8

Please sign in to comment.