Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8633176ybi; Tue, 9 Jul 2019 20:09:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxafJE7xc7yUTU6nKUdh5KkHKOEsv4fiYn/WRGcO7zD1jktKi5jymJ+0RawcxbMbTmGplG2 X-Received: by 2002:a63:5a4d:: with SMTP id k13mr33357405pgm.174.1562728193268; Tue, 09 Jul 2019 20:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562728193; cv=none; d=google.com; s=arc-20160816; b=pZiVNSi8rMNQ/xkMQdfxxktS95Gj3yoyPPe2UitSH2enlsU/QMOc3QWchgJMzwU9IF huvsrB3vPPL9GZmRfQs2tPozyXKFUGYtKr3kx/ggw27bapNL3v70skkAMV5uYjMXvHhe JNiwsZGRbm4Ywwz5lOJrO4cgoxIagDGPRtdqaJx9vH0Ayu4UdNBLLmYfjcIdiCCFrB4s B74iErdmHr+rJBiu13BK7A04wgrkLXei3tuNoJRhUCVXkxqKnx7Lpx0BBbYlhHfRrF75 GM+bZ0iG7GtuoNH8UhWyZgilU4pboLLIn0HQOsssByd/BhgWN8mlTqa0ezXNlluCFTAg pqrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=RoE15rJDSm/JulLws/ppSMRVLsusryCGiq6CT1PSzz4=; b=B2i4RALNdr8AQnWwXffOkwYKHivrKqozVEB2b3xAUxtYRdkMsuR+uft4kABGLxpkPB Da6EWzg1qn8HAzuxIyd5FJJjIxIph+T/AifsZ6RawaB0/eHLYIQPla8K4XSjUgGqSy7k EMRNUXewRFMeGzmdn7ETE0vM/N7WrHbdfdzm2gx8Qpi5SkSikpAAf0UKTbYRBduG9Ezq VZm3Y0jPMOfsqZJg+RtF1s2RaCLgjMuXqEAQ3ERr0qliP5FPVQgY2OVeSLC49YU2Zaoj 7YhclQezoTbxCK9HOTXsPw98xZZZX4ydyaSgDvk/Yd91wSFu3LA1fqwZQVXZYRo3rB4N C1Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si807781pgq.298.2019.07.09.20.09.26; Tue, 09 Jul 2019 20:09:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725956AbfGJDJY (ORCPT + 99 others); Tue, 9 Jul 2019 23:09:24 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2249 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725935AbfGJDJY (ORCPT ); Tue, 9 Jul 2019 23:09:24 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B20CB753DD21332D48C9; Wed, 10 Jul 2019 11:09:18 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.439.0; Wed, 10 Jul 2019 11:09:10 +0800 From: Xiaoming Ni To: , , , , , , , , , , , , , , , , , , , , CC: , , , , , Subject: [PATCH v3 0/3] kernel/notifier.c: avoid duplicate registration Date: Wed, 10 Jul 2019 11:09:07 +0800 Message-ID: <1562728147-30251-1-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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. so. need add a check in in notifier_chain_register() to avoid duplicate registration v1: * use notifier_chain_cond_register replace notifier_chain_register v2: * Add a check in notifier_chain_register() to avoid duplicate registration * remove notifier_chain_cond_register() to avoid duplicate code * remove blocking_notifier_chain_cond_register() to avoid duplicate code v3: * Add a cover letter. Xiaoming Ni (3): kernel/notifier.c: avoid duplicate registration kernel/notifier.c: remove notifier_chain_cond_register() kernel/notifier.c: remove blocking_notifier_chain_cond_register() include/linux/notifier.h | 4 ---- kernel/notifier.c | 41 +++-------------------------------------- net/sunrpc/rpc_pipe.c | 2 +- 3 files changed, 4 insertions(+), 43 deletions(-) -- 1.8.5.6