Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4895624pxb; Tue, 2 Nov 2021 18:22:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhJxCVMLSefe+ARgn8UttoiqIiTW7j9lLGp2oSCnsCqSH0cJjvydOLXwb7PGGy7ejDYK0o X-Received: by 2002:a50:9eab:: with SMTP id a40mr57022888edf.281.1635902569895; Tue, 02 Nov 2021 18:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635902569; cv=none; d=google.com; s=arc-20160816; b=aKymdjhLsggSf/hWVl9SJ8MN60VC4Q2A6bkIY3MdeKzxrrbL3r2nRPAfbuoQJucsUg Qbihmp5KxvtXbH2i3z8jXzidiDW/2u9w5tPgOMM90efkXDukU632LTLjX5c3v74Fts7W IeyNP5cWa7WK9lccmwyK6lSbZbh04QTfvT6NLgVMbeIioF5EfzKAAjI5Xus1aMIFnc0R 07x9yDg/y/e30YiLbGJxAVe0UjGLiC+4qGqdgUkRwLHwtiHhNXaVom2l2ljFM6jmcWfD tR5cQSHrhUgRP77DBlJ8Fw+Xm7tGMkQdy/4Ax5laGtNqvtFV8aX9NeFoxLfXDtYFEmrw WSFA== 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=EE1Va1khKIllkWhxyabIVpT9BhHjoNEtYtuJ6FU9moQ=; b=CzOtSsqYdcqJ/vJEUlzioPa2kQ4usJLSvF2bZfYZuKZRuQJIWWjZ2exCgNxuo2+mSP eEOb7+ImjFyY9etTpo3sPMk+TQgtq0HBB/eG09eUnbvZd+AM9dtVaq9iY3qTZOl6jkyI zDk53cRQjesZo8IfX2u12ix7JFpiDVr2ETrIQqne4NIcQn8LdJI4qH+g+9rZXoXrgSsZ I1EqzOQk/FiaHdXZUxDXDckc+5C0oAUzqUcZ6x/OPFS9/9hCzCg+sOx7dLZj0YQ8m25I z+OCE2QrA7RB6mJSUpDvd1R5pbsMWzewH6Fk3GXTzJPUPGeeaTLdcqxpHByjz9d+Yckd 7Rvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b8si1438844edz.555.2021.11.02.18.22.05; Tue, 02 Nov 2021 18:22:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231450AbhKCBWo (ORCPT + 99 others); Tue, 2 Nov 2021 21:22:44 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:27101 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229844AbhKCBWn (ORCPT ); Tue, 2 Nov 2021 21:22:43 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HkTRF10q4z1DHBw; Wed, 3 Nov 2021 09:18:01 +0800 (CST) Received: from dggpeml500020.china.huawei.com (7.185.36.88) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Wed, 3 Nov 2021 09:20:05 +0800 Received: from huawei.com (10.175.127.227) 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.15; Wed, 3 Nov 2021 09:20:04 +0800 From: Baokun Li To: , , , , CC: , , , Subject: [PATCH -next V2 0/2] ubi: fix race between ctrl_cdev_ioctl and ubi_cdev_ioctl Date: Wed, 3 Nov 2021 09:32:47 +0800 Message-ID: <20211103013249.498805-1-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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 The lock held by ctrl_cdev_ioctl is ubi_devices_mutex, but the lock held by ubi_cdev_ioctl is ubi->device_mutex. Therefore, the two locks can be concurrent. ubi_attach_mtd_dev in ctrl_cdev_ioctl may be race with ubi_create_volume and ubi_remove_volume in ubi_cdev_ioctl. Because ubi_attach_mtd_dev has similar ubi_free_volume and ubi_open_volume. These two functions are called in uif_init and uif_close, and we'll fix both races in this patch set. Another function in ctrl_cdev_ioctl, ubi_detach_mtd_dev, uses reference counting and ubi_devices_lock to avoid race in concurrency cases, so we do not need to fix it. V1->V2: Add race in uif_close Baokun Li (2): ubi: fix race between volume operations and uif_init ubi: fix race between volume operations and uif_close drivers/mtd/ubi/build.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.31.1