Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1125723ybl; Wed, 4 Dec 2019 17:34:09 -0800 (PST) X-Google-Smtp-Source: APXvYqyRnLrTyrqvK4ydCAk+MCGMZOihpSpBnlItZBhNNT+zhINEgQm9gdiZ+jCKoO8bdVUgkOTg X-Received: by 2002:a05:6830:95:: with SMTP id a21mr4663511oto.167.1575509649031; Wed, 04 Dec 2019 17:34:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575509649; cv=none; d=google.com; s=arc-20160816; b=jcpP0R61q7S/u8VEUqo+fuFrVMMvjW/RgXfwMPUF7WkP19P/njIfQd0EKbZHOBpRdJ +QNK2YUyZx934FxBpnS7la/se2LUtCKK1cK3MlLTMiasEmiBLg+B+bg+WIoy8PlolnuL nEx6Bh7G1cNmxeFTLN43WeKKCj67JA2P3c9RX4JNRvpwJi5WwRKzk5gApTOt3VobGgQ7 17eojA8hyeC+RmqkRfTHBmK6MDmHzAm8mRQ5OQlw1d57v5hk28pgxasy9K6QOMt9JBbz iRwMAciYRt3J9pUYJu4dOKDwnHrLbP3FOKBcVT1I8+y/fbQwnAv6HpFfnvDorJei9SEh 0QvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=XihpytF5tVF1s8Qk/tkoOUGvUGjLIQG7K+8VgrJAnp8=; b=KRGfqJ+pZv83YnKkD3RCA257Ul3Ek9zGlJauX5KHJdOUwIwd/W79ff/JJB29RNoBtT i8+42tpbnbeXSNHsuXpD+c0POskGwMQJ104n8OvI7CwEkW9+bteyP6mKKNJuQWPFfFC6 bGiOT9Z8vxbepWyZ1i4T8R57UHq3FdxQT7Ir3SUQa36/t8PTGzuXJVwGuGM0/xMHsvSx w2Jr51fGZbOxlvfUBcprXfhl4HVhIhS7seDNr/bAbntD4g6CRdaF4Sd9NOK+QHe2Wrf6 /ANe88q71HzEyIpYTXjHPzyfo4u5n5uRw9ci6dmuRE9svzp+EcSuuGXGJ/HthB8kP21v NQfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si4238867otq.262.2019.12.04.17.33.56; Wed, 04 Dec 2019 17:34:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728419AbfLEBdZ (ORCPT + 99 others); Wed, 4 Dec 2019 20:33:25 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7634 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728098AbfLEBdZ (ORCPT ); Wed, 4 Dec 2019 20:33:25 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 83A93A039167D4FE9EDB; Thu, 5 Dec 2019 09:33:23 +0800 (CST) Received: from [127.0.0.1] (10.133.219.224) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Thu, 5 Dec 2019 09:33:19 +0800 Subject: Re: [PATCH] UBI: fix use after free in ubi_remove_volume() From: Hou Tao To: Wen Yang , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra CC: , , References: <20191130093317.31352-1-wenyang@linux.alibaba.com> <65b49705-e28c-e077-c0de-c5167e34d1c5@huawei.com> Message-ID: <58208ceb-4d72-c4a1-8a2b-9e38854e3672@huawei.com> Date: Thu, 5 Dec 2019 09:33:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <65b49705-e28c-e077-c0de-c5167e34d1c5@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.133.219.224] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2019/12/3 21:13, Hou Tao wrote: > Reviewed-by: Hou Tao > Sorry for my early conclusion. The reference of ubi_volume had already been increased in ubi_open_volume() in ubi_cdev_ioctl(), so this reference dropped in ubi_remove_volume() will not be the last one, and there will no use-after-free problem. Regards, Tao > On 2019/11/30 17:33, Wen Yang wrote: >> We can't use "vol" after it has been freed. >> >> Fixes: 493cfaeaa0c9 ("mtd: utilize new cdev_device_add helper function") >> Signed-off-by: Wen Yang >> Cc: Richard Weinberger >> Cc: Miquel Raynal >> Cc: Vignesh Raghavendra >> Cc: linux-mtd@lists.infradead.org >> Cc: linux-kernel@vger.kernel.org >> --- >> drivers/mtd/ubi/vmt.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c >> index 139ee13..8ff1478 100644 >> --- a/drivers/mtd/ubi/vmt.c >> +++ b/drivers/mtd/ubi/vmt.c >> @@ -375,7 +375,6 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) >> } >> >> cdev_device_del(&vol->cdev, &vol->dev); >> - put_device(&vol->dev); >> >> spin_lock(&ubi->volumes_lock); >> ubi->rsvd_pebs -= reserved_pebs; >> @@ -388,6 +387,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl) >> if (!no_vtbl) >> self_check_volumes(ubi); >> >> + put_device(&vol->dev); >> + >> return 0; >> >> out_err: >> > > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/ > >