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-next>] [day] [month] [year] [list]
Message-ID: <1561034914-106990-1-git-send-email-nixiaoming@huawei.com>
Date:   Thu, 20 Jun 2019 20:48:32 +0800
From:   Xiaoming Ni <nixiaoming@...wei.com>
To:     <trond.myklebust@...merspace.com>, <anna.schumaker@...app.com>,
        <bfields@...ldses.org>, <jlayton@...nel.org>,
        <davem@...emloft.net>, <semen.protsenko@...aro.org>,
        <akpm@...ux-foundation.org>, <gregkh@...uxfoundation.org>,
        <vvs@...tuozzo.com>, <tglx@...utronix.de>
CC:     <nixiaoming@...wei.com>, <dylix.dailei@...wei.com>,
        <alex.huangjianhui@...wei.com>, <adobriyan@...il.com>,
        <mingo@...nel.org>, <viresh.kumar@...aro.org>, <luto@...nel.org>,
        <arjan@...ux.intel.com>, <Nadia.Derbey@...l.net>,
        <torvalds@...ux-foundation.org>, <stern@...land.harvard.edu>,
        <paulmck@...ux.vnet.ibm.com>, <linux-kernel@...r.kernel.org>,
        <linux-nfs@...r.kernel.org>, <netdev@...r.kernel.org>,
        <stable@...nel.org>
Subject: [PATCH v2 1/3] kernel/notifier.c: avoid duplicate registration

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() to avoid duplicate registration

Signed-off-by: Xiaoming Ni <nixiaoming@...wei.com>
---
 kernel/notifier.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/notifier.c b/kernel/notifier.c
index d9f5081..30bedb8 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);
-- 
1.8.5.6

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ