Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2084151rwi; Tue, 1 Nov 2022 03:45:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5C95PRWhLWP6rTxn9jklqWEZtHbvKIdgAgqPwn2c+c8h3iBFKKZleFwoDMH7t/m6Yvi9Lj X-Received: by 2002:a50:871a:0:b0:461:52a9:1da6 with SMTP id i26-20020a50871a000000b0046152a91da6mr18316698edb.94.1667299509682; Tue, 01 Nov 2022 03:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667299509; cv=none; d=google.com; s=arc-20160816; b=g90t59efmVtN0QGdY////EMBi8gSUKdl4NkoSxIHrcS/Mu6kmyfi87AxbrFh/4eHlh 1TkLQjPcYiodkTcHHDAvhwqG10JS5k+bcMAnqMzLmW/aLoIr+IFzj2kEl4LIRAsj90SX tPS9b5LKQw4wZSXdwBGgVBU6mgF9HBjqa0UDyfaqxAUHx+Blb11SVY1q/9Jf7iIdXTWI 4LiRj9ePH35/2j4UMSTsZbGj/Nce6e4LWXordaT18e2YHHsSG+VKSy8dzb40m70EyYWs PqaDaECvnrzfhVRWUPHN8qXh+J0rUDejzImSSL787uOP83cEmgEgt9RdjVUWqvJj+jq4 5PXg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji8-20020a170907980800b0073306ff26besi12594751ejc.969.2022.11.01.03.44.45; Tue, 01 Nov 2022 03:45:09 -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 + 97 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 Content-Type: text/plain 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 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 --- 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); -- 2.17.1