The patch titled Subject: kernel/notifier.c: intercept duplicate registrations to avoid infinite loops has been added to the -mm tree. Its filename is kernel-notifierc-intercepting-duplicate-registrations-to-avoid-infinite-loops.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kernel-notifierc-intercepting-duplicate-registrations-to-avoid-infinite-loops.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kernel-notifierc-intercepting-duplicate-registrations-to-avoid-infinite-loops.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Xiaoming Ni <nixiaoming@xxxxxxxxxx> Subject: kernel/notifier.c: intercept duplicate registrations to avoid infinite 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://lkml.kernel.org/r/1568861888-34045-2-git-send-email-nixiaoming@xxxxxxxxxx Signed-off-by: Xiaoming Ni <nixiaoming@xxxxxxxxxx> Reviewed-by: Vasily Averin <vvs@xxxxxxxxxxxxx> Reviewed-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Cc: Alexey Dobriyan <adobriyan@xxxxxxxxx> Cc: Anna Schumaker <anna.schumaker@xxxxxxxxxx> Cc: Arjan van de Ven <arjan@xxxxxxxxxxxxxxx> Cc: J. Bruce Fields <bfields@xxxxxxxxxxxx> Cc: Chuck Lever <chuck.lever@xxxxxxxxxx> Cc: David S. Miller <davem@xxxxxxxxxxxxx> Cc: Jeff Layton <jlayton@xxxxxxxxxx> Cc: Andy Lutomirski <luto@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: Nadia Derbey <Nadia.Derbey@xxxxxxxx> Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxxxxxxxxxx> Cc: Sam Protsenko <semen.protsenko@xxxxxxxxxx> Cc: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Trond Myklebust <trond.myklebust@xxxxxxxxxxxxxxx> Cc: Viresh Kumar <viresh.kumar@xxxxxxxxxx> Cc: Xiaoming Ni <nixiaoming@xxxxxxxxxx> Cc: YueHaibing <yuehaibing@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/notifier.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/kernel/notifier.c~kernel-notifierc-intercepting-duplicate-registrations-to-avoid-infinite-loops +++ a/kernel/notifier.c @@ -23,7 +23,10 @@ static int notifier_chain_register(struc 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); _ Patches currently in -mm which might be from nixiaoming@xxxxxxxxxx are kernel-notifierc-intercepting-duplicate-registrations-to-avoid-infinite-loops.patch kernel-notifierc-remove-notifier_chain_cond_register.patch kernel-notifierc-remove-blocking_notifier_chain_cond_register.patch