lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200918020110.2063155-72-sashal@kernel.org>
Date:   Thu, 17 Sep 2020 21:56:52 -0400
From:   Sasha Levin <sashal@...nel.org>
To:     linux-kernel@...r.kernel.org, stable@...r.kernel.org
Cc:     Xiaoming Ni <nixiaoming@...wei.com>,
        Vasily Averin <vvs@...tuozzo.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Alexey Dobriyan <adobriyan@...il.com>,
        Anna Schumaker <anna.schumaker@...app.com>,
        Arjan van de Ven <arjan@...ux.intel.com>,
        "J . Bruce Fields" <bfields@...ldses.org>,
        Chuck Lever <chuck.lever@...cle.com>,
        "David S . Miller" <davem@...emloft.net>,
        Jeff Layton <jlayton@...nel.org>,
        Andy Lutomirski <luto@...nel.org>,
        Ingo Molnar <mingo@...nel.org>,
        Nadia Derbey <Nadia.Derbey@...l.net>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        Sam Protsenko <semen.protsenko@...aro.org>,
        Alan Stern <stern@...land.harvard.edu>,
        Thomas Gleixner <tglx@...utronix.de>,
        Trond Myklebust <trond.myklebust@...merspace.com>,
        Viresh Kumar <viresh.kumar@...aro.org>,
        YueHaibing <yuehaibing@...wei.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Sasha Levin <sashal@...nel.org>
Subject: [PATCH AUTOSEL 5.4 072/330] kernel/notifier.c: intercept duplicate registrations to avoid infinite loops

From: Xiaoming Ni <nixiaoming@...wei.com>

[ Upstream commit 1a50cb80f219c44adb6265f5071b81fc3c1deced ]

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@huawei.com
Signed-off-by: Xiaoming Ni <nixiaoming@...wei.com>
Reviewed-by: Vasily Averin <vvs@...tuozzo.com>
Reviewed-by: Andrew Morton <akpm@...ux-foundation.org>
Cc: Alexey Dobriyan <adobriyan@...il.com>
Cc: Anna Schumaker <anna.schumaker@...app.com>
Cc: Arjan van de Ven <arjan@...ux.intel.com>
Cc: J. Bruce Fields <bfields@...ldses.org>
Cc: Chuck Lever <chuck.lever@...cle.com>
Cc: David S. Miller <davem@...emloft.net>
Cc: Jeff Layton <jlayton@...nel.org>
Cc: Andy Lutomirski <luto@...nel.org>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Nadia Derbey <Nadia.Derbey@...l.net>
Cc: "Paul E. McKenney" <paulmck@...nel.org>
Cc: Sam Protsenko <semen.protsenko@...aro.org>
Cc: Alan Stern <stern@...land.harvard.edu>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Trond Myklebust <trond.myklebust@...merspace.com>
Cc: Viresh Kumar <viresh.kumar@...aro.org>
Cc: Xiaoming Ni <nixiaoming@...wei.com>
Cc: YueHaibing <yuehaibing@...wei.com>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
 kernel/notifier.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/notifier.c b/kernel/notifier.c
index 157d7c29f7207..f6d5ffe4e72ec 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -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);
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ