Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp745391rdb; Thu, 19 Oct 2023 19:28:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRSqwloKwTx5jtew5wkf8wAzbGBO2dHkYlxg8TuZTE7vwRQVIC/m41BZIjNhJX+DIWgss2 X-Received: by 2002:a17:902:f543:b0:1ca:77e9:3863 with SMTP id h3-20020a170902f54300b001ca77e93863mr800413plf.31.1697768934458; Thu, 19 Oct 2023 19:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697768934; cv=none; d=google.com; s=arc-20160816; b=CTGH1oYu+0Q9gkiLwYgsanHzsx1VJbkk5MSdsSLzbrM17KOvVpzEVEWTd315h8FriR 2lV5NowPlBgywGwELHbO/7hC5j40E/5+o7BnfK1BktqkbsJLx+d1L4GPC3p2vstaCVBL 5NlYUuG97ZE+6gwHdWElUSldDnK2GaGLgeGZLRyk7+LMm54TvihgC03Wk1aee3w36N7F zC751hedW+S427ZI1yrEKNHKTd/UeTgriHg5HiMaxwHmllki9JUHUW8PdDAsCMl8QDTf bOXkaGRGDlrQ4jchKlZsz3oFkPL/Pjg80Cn3hmF9r6MaWt9MHgiswYXBFTmANRdFf77P lv6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=UhPckINZNDy7735Q8RbE9YMYWKvjRMZ1f9z+Q5NntGw=; fh=4QkgPGXnhXzkWX7niQRZj+C1C/AGVNoNQHRIcVNYFNw=; b=UIcampax+nX0/c+CsZ+oweigUNXSrLPoNJrpZm0GQb2OGgEBkZ5KJK7OFOUMfufLQC f5+7z/AzNqCMGcCjNyNP/iGxgiGWmCD1d+kBE2qPfU98dco4mECTzOHFlpVeAQpzRXMW dP2uNhSkkRRNFVKbw0wMoO8mrCF3r7bFYSQV/yhnlDTEchtcdCKszmPDfkcS+Fksa1ym /I5qfXhX4vWNEmgL8VDucHSTOHTEQunjViSk9ogIuNmydl5Vp6oTnrDt+vAbiLrKWQRe Rt+eM26GzUxLzjNeu8vrW9k6UNInlmYk5vUBtccCck+ZyBCihhI49MJ8cRxzm91HwzjV Xf8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id c10-20020a170902c1ca00b001ca4e2a35efsi766700plc.45.2023.10.19.19.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 19:28:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id C33028279EC9; Thu, 19 Oct 2023 19:28:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346845AbjJTC2o (ORCPT + 99 others); Thu, 19 Oct 2023 22:28:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235588AbjJTC2n (ORCPT ); Thu, 19 Oct 2023 22:28:43 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39E3512F for ; Thu, 19 Oct 2023 19:28:14 -0700 (PDT) Received: from kwepemm000013.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SBT0C5RDSzvQCn; Fri, 20 Oct 2023 10:23:23 +0800 (CST) Received: from [10.174.178.46] (10.174.178.46) by kwepemm000013.china.huawei.com (7.193.23.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 20 Oct 2023 10:28:09 +0800 Subject: Re: [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier To: Richard Weinberger , ZhaoLong Wang CC: Miquel Raynal , Vignesh Raghavendra , , Artem Bityutskiy , linux-mtd , linux-kernel , yi zhang , yangerkun References: <20231018121618.778385-1-wangzhaolong1@huawei.com> <1381458025.20897.1697747248632.JavaMail.zimbra@nod.at> From: Zhihao Cheng Message-ID: <891e554b-c133-6378-3a65-836fc9147e54@huawei.com> Date: Fri, 20 Oct 2023 10:27:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <1381458025.20897.1697747248632.JavaMail.zimbra@nod.at> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000013.china.huawei.com (7.193.23.81) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 19:28:52 -0700 (PDT) 在 2023/10/20 4:27, Richard Weinberger 写道: > ----- Ursprüngliche Mail ----- >> Von: "ZhaoLong Wang" >> An: "richard" , "Miquel Raynal" , "Vignesh Raghavendra" , >> dpervushin@embeddedalley.com, "Artem Bityutskiy" >> CC: "linux-mtd" , "linux-kernel" , "chengzhihao1" >> , "ZhaoLong Wang" , "yi zhang" , "yangerkun" >> >> Gesendet: Mittwoch, 18. Oktober 2023 14:16:18 >> Betreff: [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier > >> 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 >> mtd_read_oob >> 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 accesses 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 value of gluebi->desc may also be a negative error code, which >> triggers the page fault error. >> >> This patch has the following modifications: >> >> 1. Do not assign gluebi->desc to the error code. Use the NULL instead. >> >> 2. Always check the validity of gluebi->desc in gluebi_read() If the >> gluebi->desc is NULL, try to get MTD device. >> >> Such a modification currently works because the mutex "mtd_table_mutex" >> is held on all necessary paths, including the ftl_add_mtd() call path, >> open and close paths. Therefore, many race condition can be avoided. > > I see the problem, but I'm not really satisfied by the solution. > Adding this hack to gluebi_read() is not nice at all. Yes, it's jsut a workaround. At the begining, I prefer that increasing volume refcnt (by ubi_open_volume) in gluebi_create and releasing volume refcnt in gluebi_remove. It looks more reasonable that holding a refcnt of UBI volume when gluebi is alive. After looking through the code, the creation/destroying of gluebi is triggered by volume actions(UBI_VOLUME_ADDED/UBI_VOLUME_REMOVED), which means that: 1. gluebi_remove is depended on UBI_VOLUME_REMOVED(triggered by ubi_remove_volume) 2. ubi_remove_volume won't be executed until the refcnt of volume becomes 0(released by gluebi_remove) If we add new ioctls to control creation/destroying of gluebi, then gluebi mtd won't be automatically created when UBI volume is added. I'm not certain whether this change will effect existing startup process that depends on gluebi. > > Is there a strong reason why have to defer ubi_open_volume() to > gluebi_get_device()? > > Miquel, what do you think? > > Thanks, > //richard > > . >