From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 128C5C433EF for ; Tue, 28 Dec 2021 12:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231454AbhL1MkU (ORCPT ); Tue, 28 Dec 2021 07:40:20 -0500 Received: from szxga08-in.huawei.com ([45.249.212.255]:30120 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231418AbhL1MkU (ORCPT ); Tue, 28 Dec 2021 07:40:20 -0500 Received: from dggpeml500020.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JNYvK6rwjz1DKHx; Tue, 28 Dec 2021 20:37:01 +0800 (CST) Received: from [10.174.177.174] (10.174.177.174) by dggpeml500020.china.huawei.com (7.185.36.88) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 28 Dec 2021 20:40:18 +0800 Subject: Re: [PATCH -next V3] ubi: fix race condition between ctrl_cdev_ioctl and ubi_cdev_ioctl To: Richard Weinberger CC: Miquel Raynal , Vignesh Raghavendra , linux-mtd , linux-kernel , , Hulk Robot , Baokun Li References: <20211105093022.1360601-1-libaokun1@huawei.com> <7e00eda5-3b35-6d3c-29fb-664b12cca6dd@huawei.com> <509065063.197038.1640293568550.JavaMail.zimbra@nod.at> From: "libaokun (A)" Message-ID: Date: Tue, 28 Dec 2021 20:40:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <509065063.197038.1640293568550.JavaMail.zimbra@nod.at> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.174] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500020.china.huawei.com (7.185.36.88) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/12/24 5:06, Richard Weinberger 写道: > ----- Ursprüngliche Mail ----- >> Von: "libaokun (A)" >> 在 2021/11/5 17:30, Baokun Li 写道: >> >> ping > Thanks for your patience. > >>> Hulk Robot reported a KASAN report about use-after-free: > [...] > >>> The cause of this problem is that commit 714fb87e8bc0 make device >>> "available" before it becomes accessible via sysfs. Therefore, we >>> roll back the modification. We will fix the race condition between >>> ubi device creation and udev by removing ubi_get_device in >>> vol_attribute_show and dev_attribute_show.This avoids accessing >>> uninitialized ubi_devices[ubi_num]. >>> >>> ubi_get_device is used to prevent devices from being deleted during >>> sysfs execution. However, now kernfs ensures that devices will not >>> be deleted before all reference counting are released. >>> The key process is shown in the following stack. > ubi_get_device() in dev_attribute_show() is used to detect whether > the ubi device got detached while the sysfs file is open. > > Hmm. I thought for sysfs this is not the case since sysfs does not implement > a release() method. So kernfs_drain_open_files() will return early. > But there is a good chance that I don't got all kernfs/sysfs details. > > Thanks, > //richard > . Thank you for your review! -- With Best Regards, Baokun Li