From patchwork Tue Nov 1 09:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Zhongjin X-Patchwork-Id: 13596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2851018wru; Tue, 1 Nov 2022 02:48:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM40XJDfmdBKVSncr3U896tvCKSpfudqcn7+jpeT+F6G5b3+eY5wnZTCVATE9Cwwl0J/az1w X-Received: by 2002:a17:902:d503:b0:187:2294:d513 with SMTP id b3-20020a170902d50300b001872294d513mr9092564plg.54.1667296130417; Tue, 01 Nov 2022 02:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667296130; cv=none; d=google.com; s=arc-20160816; b=mJUXVyembq7heXHuiSNkNr7iMEqysa4L3Dr7tNVZEbwrWtiIcVB1i85zGxk+GFInTn urzmrvj4IgU/C8rplQvzUajmYkqLmN+LAQtFRFZc0Fv3SuEljPmouNKHMAC0j5qiaNH5 P1WoIEysbnCT00MNsce/bMa/Z8q7FTwRC9z/dtzrvXeGC2bRHKI+IsGdJWRn7PoL2Pcm t7A8mIumOpvJFBudWZJYA4GnBCKA23pQgpQUVEfXgariU9rTgC1TzWlSgHN4y9/Dtaqi AcBRhjIlTt0XpXhI2ZHdfAat7vuU5gs0ofr5h+L+oWsl8JAbM02zIDtnJT9BQOok6kB3 6zgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=I52ANwathRqv+s8Fj5l+0c7sxY2damRf42X6tdexw6k=; b=KXJxYhE33NfmnP8wrxoAOn/V1NI7tur2Ep/Ba9hMe8mKctFQ23869svKLJBoDVpSQF SMMdGkatAyWq3b3oCf1MLp+JzZ/9SIlA+6kCMjreO9yzltEeEG7qfI5yfNuHNQ5Vcq7H IhOinCBouwLBLhuRAZQH5p84D+674g4JZlDyVxnqdCl5AFDubsSbQv1azZiiOzsQ/Hr6 IS3ySRZWxjHBIdrttqWm8bJyNqYsGAHKQLcyMGZL0bMCUJoHBjqZ9wGloEs/+Sh21mUc wm8ZziHBq8Twh4Xa44ml0BrWGRVkrj0KEskF3yhOJdtbNRndpd/DfaODG0EXUuI4Ihn+ h41g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a170902db0500b00186bb39ff55si12787411plx.427.2022.11.01.02.48.37; Tue, 01 Nov 2022 02:48:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230500AbiKAJmB (ORCPT + 99 others); Tue, 1 Nov 2022 05:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbiKAJl0 (ORCPT ); Tue, 1 Nov 2022 05:41:26 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FEC21A211; Tue, 1 Nov 2022 02:40:48 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N1lKk3JrZzpW4d; Tue, 1 Nov 2022 17:37:14 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 1 Nov 2022 17:40:40 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 1 Nov 2022 17:40:40 +0800 From: Chen Zhongjin To: , , CC: , , , , , , , , Subject: [PATCH] net/smc: Fix possible leaked pernet namespace in smc_init() Date: Tue, 1 Nov 2022 17:37:22 +0800 Message-ID: <20221101093722.127223-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748286707234291745?= X-GMAIL-MSGID: =?utf-8?q?1748286707234291745?= In smc_init(), register_pernet_subsys(&smc_net_stat_ops) is called without any error handling. If it fails, registering of &smc_net_ops won't be reverted. And if smc_nl_init() fails, &smc_net_stat_ops itself won't be reverted. This leaves wild ops in subsystem linkedlist and when another module tries to call register_pernet_operations() it triggers page fault: BUG: unable to handle page fault for address: fffffbfff81b964c RIP: 0010:register_pernet_operations+0x1b9/0x5f0 Call Trace: register_pernet_subsys+0x29/0x40 ebtables_init+0x58/0x1000 [ebtables] ... Fixes: 194730a9beb5 ("net/smc: Make SMC statistics network namespace aware") Signed-off-by: Chen Zhongjin Reviewed-by: Tony Lu Reviewed-by: Wenjia Zhang --- net/smc/af_smc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 3ccbf3c201cd..e12d4fa5aece 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -3380,14 +3380,14 @@ static int __init smc_init(void) rc = register_pernet_subsys(&smc_net_stat_ops); if (rc) - return rc; + goto out_pernet_subsys; smc_ism_init(); smc_clc_init(); rc = smc_nl_init(); if (rc) - goto out_pernet_subsys; + goto out_pernet_subsys_stat; rc = smc_pnet_init(); if (rc) @@ -3480,6 +3480,8 @@ static int __init smc_init(void) smc_pnet_exit(); out_nl: smc_nl_exit(); +out_pernet_subsys_stat: + unregister_pernet_subsys(&smc_net_stat_ops); out_pernet_subsys: unregister_pernet_subsys(&smc_net_ops);