Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp309451rdb; Tue, 19 Dec 2023 18:43:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiP+o+/p/J5qWMoo4f1p4QNsYM1MJs8ho6ewcmq/LlpjohUCT1bkOlvaKkj7NP4VlfZW1U X-Received: by 2002:a05:6a20:1016:b0:18f:97c:8a49 with SMTP id gs22-20020a056a20101600b0018f097c8a49mr21266875pzc.116.1703040192977; Tue, 19 Dec 2023 18:43:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703040192; cv=none; d=google.com; s=arc-20160816; b=WsaldDX+tRKwHTEqAOPuuHSG8CRmMOAsI+xsuV12zjCpYn2v0hAeRfwtanIvxLTif/ OSp775syV9D1ujTLh5gpgCp55m/Z9UGysPxr7xiWXdTWqTnUD1UYg0L9uey9mZgWWWkS EHt+GmpDP88Zid4nZ9/vfRwDa6K7adVdLcXwGWYmCLlFoxDekgebsgr9p/LqRrVv4q1M PFsPSr+5uYBv+aNU1i7ZBIYsBQNOTAyL9jS/OgNsuN8qVBjOWdA33ZgP+JsET6XsCZhy BwZCSBs97fxAh5lUH/loXHo52zhg7rH3i//sj4Ofjf+XmMUXIZjJkIgzafZl8s+6QRQB ymYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=t0kt8Z+sxwwhFfKRqyM/rKbb1VAub4cI3EBqlnZdrAw=; fh=8eezRb4bvDfq5bN6+9A7U0dNc7JS76XSmHiRlYhKkiQ=; b=KW+W02FewD9vfJD6fQ5Yt267a1JeuEy5H81WBN6NLmygbSnlvTtDSRt1lTM5A0LG2E 6cV4QAflG7O+z18VlTR34L7HjujSMKw//JGxU0cawToleNpV2tgnDALJPSIsbDvxxJSH 4PoefQwf2H1j63Uh3lsQLdTJ/WDMrv6jF56KVrrgwwlqgrykxQUDvQL564mm2WR6TTfv u2HqEKnKdtfs8dGHQbDi8wHqAh884jXHcPvnzEvqU2i7oH3Qi4jmjzYKtkKiRoCNQWgT /pxwDaRsWfWWB5uJb4srJ5bsLdQpQfucjDEfGqhrLW+iRU9ZPrJ9EI4zbOL+ySELEOxJ 4q8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-6294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a7-20020a631a47000000b005bd335981e2si20216593pgm.678.2023.12.19.18.43.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 18:43:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-6294-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6294-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 989FB288AFF for ; Wed, 20 Dec 2023 02:43:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 961BD883C; Wed, 20 Dec 2023 02:43:07 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1EF67497 for ; Wed, 20 Dec 2023 02:43:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4SvyXR18DQz1wnwQ; Wed, 20 Dec 2023 10:42:47 +0800 (CST) Received: from dggpemd200001.china.huawei.com (unknown [7.185.36.224]) by mail.maildlp.com (Postfix) with ESMTPS id 6CE0F140412; Wed, 20 Dec 2023 10:43:01 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpemd200001.china.huawei.com (7.185.36.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Wed, 20 Dec 2023 10:43:00 +0800 From: ZhaoLong Wang To: , , , , CC: , , , , , Subject: [PATCH V4] mtd: Fix gluebi NULL pointer dereference caused by ftl notifier Date: Wed, 20 Dec 2023 10:46:19 +0800 Message-ID: <20231220024619.2138625-1-wangzhaolong1@huawei.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemd200001.china.huawei.com (7.185.36.224) If both ftl.ko and gluebi.ko are loaded, the notifier 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], In the normal case, obtain gluebi->desc in the gluebi_get_device(), and access gluebi->desc in the gluebi_read(). However, gluebi_get_device() is not executed in advance in the ftl_add_mtd() process, which leads to NULL pointer dereference. 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 the mtdblock device after creating mtd partition of the type MTD_UBIVOLUME. 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 Reviewed-by: Zhihao Cheng Acked-by: Richard Weinberger --- 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