Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp836070rdh; Thu, 26 Oct 2023 18:16:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4BHu3YQuAw1btM0T+lSnBvOoGunrXTEMA300sf9O30TP83jdSRFVvtIzjQPL/+aJGeamx X-Received: by 2002:a54:4883:0:b0:3b2:f2e0:1ecd with SMTP id r3-20020a544883000000b003b2f2e01ecdmr1096854oic.4.1698369374169; Thu, 26 Oct 2023 18:16:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698369374; cv=none; d=google.com; s=arc-20160816; b=e1BJ9lu5XnxFXgLInLE4knc8nhb9iATM1wRMYHc5EgF7ZAaxWZ+C6x8sgye0ZSYIW6 hbazev2bAopEWLE7yc/ffTfC9diqZP7uxGGDHPOs7ReUHlxAfzh6dMvlaUgPyWMT+was 4wDsB+Nffdqr333EgJ9kYKBYN/7h4p3iCydeSIm5/hIWnMllYq85o6iFw1HqdoyUSGlJ VdQgifuo2JVZ5sW5sRXj1dR6gnO2WBmE+6zFyjjs0YQp2TqI0YsreiMX20DKqqKtyuI8 GY3Rn9e/Bqo31U1KFBbp9WDKV4YF6RXXW6moDiOsJIVK238FSylDgdyFWRxgVYjDyhkj 2Qpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=HCosStxbqbNLIbsQ1PPDYUjO7N+kr3QtIXd4Vffk78s=; fh=iwWgiMy5DJhGHDpB78W5pROru0OMoSPO3ZwPDRChLCE=; b=ms6CgZwpviwy2JQmRotN3OGg9oth+1y6MlJlkFEzCGvGFFEH1QmefdDPuhOFWEsihh d2qFpCqZcDJrB9pVIirTgHdvsZU/ya/56ngdBBYu1dSiGF3us2FHR4TeAIgH5CxbN9gX Qg4ZE316e4IdhBuELxAS1WlO6NI1BFJ1FIkl2UkZUX1RGk4Ru12aRu9Tx1ufMkzY2cUe vq2wga93x+P0AoNLHwRId5ZmxRW/81A7HpOfap0avYXTJS9rwB10zVlWLebfVDKVDHqN MHLUkI+fZGhhL8kzC3KF8Gkonk0ZUHyaGy7B8eD3VKSwTEQ91KkVpTnGdvI3P4HbH+bX ZIpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f124-20020a0dc382000000b0059e886b12d6si916534ywd.398.2023.10.26.18.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 18:16:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6A9FF81DF97E; Thu, 26 Oct 2023 18:16:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbjJ0BQF (ORCPT + 99 others); Thu, 26 Oct 2023 21:16:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjJ0BQD (ORCPT ); Thu, 26 Oct 2023 21:16:03 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC14B1BB for ; Thu, 26 Oct 2023 18:16:00 -0700 (PDT) Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SGl5q4bdPzrTlN; Fri, 27 Oct 2023 09:13:03 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 27 Oct 2023 09:15:58 +0800 From: ZhaoLong Wang To: , , , , CC: , , , , , Subject: [PATCH v3] mtd: Fix gluebi NULL pointer dereference caused by ftl notifier Date: Fri, 27 Oct 2023 09:20:33 +0800 Message-ID: <20231027012033.50280-1-wangzhaolong1@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 26 Oct 2023 18:16:11 -0700 (PDT) If both flt.ko and gluebi.ko are loaded, the notiier of ftl triggers NULL pointer dereference when trying to access ‘gluebi->desc’ in gluebi_read(). ubi_gluebi_init ubi_register_volume_notifier ubi_enumerate_volumes ubi_notify_all gluebi_notify nb->notifier_call() gluebi_create mtd_device_register mtd_device_parse_register add_mtd_device blktrans_notify_add not->add() ftl_add_mtd tr->add_mtd() scan_header mtd_read mtd_read_oob mtd_read_oob_std gluebi_read mtd->read() gluebi->desc - NULL Detailed reproduction information available at the link[1], The solution for the gluebi module is to run jffs2 on the UBI volume without considering working with ftl or mtdblock.[2]. Therefore, this problem can be avoided by preventing gluebi from creating mtdblock devices. Fixes: 2ba3d76a1e29 ("UBI: make gluebi a separate module") Link: https://bugzilla.kernel.org/show_bug.cgi?id=217992 [1] Link: https://lore.kernel.org/lkml/441107100.23734.1697904580252.JavaMail.zimbra@nod.at/ [2] Signed-off-by: ZhaoLong Wang --- drivers/mtd/mtd_blkdevs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index ff18636e0889..5bc32108ca03 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -463,7 +463,7 @@ static void blktrans_notify_add(struct mtd_info *mtd) { struct mtd_blktrans_ops *tr; - if (mtd->type == MTD_ABSENT) + if (mtd->type == MTD_ABSENT || mtd->type == MTD_UBIVOLUME) return; list_for_each_entry(tr, &blktrans_majors, list) @@ -503,7 +503,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) mutex_lock(&mtd_table_mutex); list_add(&tr->list, &blktrans_majors); mtd_for_each_device(mtd) - if (mtd->type != MTD_ABSENT) + if (mtd->type != MTD_ABSENT && mtd->type != MTD_UBIVOLUME) tr->add_mtd(tr, mtd); mutex_unlock(&mtd_table_mutex); return 0; -- 2.31.1