Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5463835rwb; Wed, 17 Aug 2022 18:51:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR5LH+HleizVZ9s/fjavs6zyeYyc/L+0b7cL8PLqtpStmTLoCrSYN6xP8XiI5s8dkxWMXVjb X-Received: by 2002:a05:6402:550c:b0:443:7d15:d57f with SMTP id fi12-20020a056402550c00b004437d15d57fmr544786edb.147.1660787506041; Wed, 17 Aug 2022 18:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660787506; cv=none; d=google.com; s=arc-20160816; b=Golh8qn3E1+EqfBMukbyrGzMVkd4JZl4nbvDDLWWXUQbfH05dmqHLVg432p8VFIOSb ZSK+X3X6grRRq87Cgfz340J9hSIzzsq309ssU3QWKCHc7WMsg+lEWGc8h6vLwb8f/miA rhUbA5IbEHh16vv56ekW5CfdkaxweCugGC9vccv63a1XD+O0g7C2mVVhppXUGC64OPYl Mm3iZbAH6sOftMT75xyJu2Ar9sz7ocavf43XNUFKSTiCjQxnVIczoHnlgQY2GQaFAYpQ bgfWqfRSK7vwdnwNnDu9rTauplAQkHT6B4N/l19fNPyqGIIvZm7udNtpheCGxSCgPWWi Pd6w== 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=swdZmuIoR4eE089LIUSKEaVSp6ZV+b7F+DTbPtCCWbI=; b=RTDgPpyUAo84uirYE/Msw62eWwYuES+5Gq+OkkyxunydO+wMGAL3rts8fIYj7+IBUJ LySsr4M1lo+ozZ6NAiKpQYQ09bN+sbsjvubqsCcuNCqP3io4YGdPyrm06UTHjBZaJo48 BKXvhIgCWMeXLXLUO39dUUQYR6yELvkFP6StoDuuiplaiau3/j68UCDfSXN+MPi1Tlr+ 0iH1XVfwBHcdidIdVltr92K28pW9qZuetJzxdGv35NbDr4pFyZnlEmtwrBExi3lFuH1Z jyxbq8wzEEyaqfbk/Z62XsD9lQBvVy5XoQKXVvII/O4Ka8iYiWSgN1getztRINbw3RPe FuGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020a50cd08000000b00445ce894db3si229155edi.492.2022.08.17.18.51.20; Wed, 17 Aug 2022 18:51:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242656AbiHRBcT (ORCPT + 99 others); Wed, 17 Aug 2022 21:32:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240101AbiHRBcR (ORCPT ); Wed, 17 Aug 2022 21:32:17 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8971A1D17 for ; Wed, 17 Aug 2022 18:32:16 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M7S1t222PzXdjM; Thu, 18 Aug 2022 09:28:02 +0800 (CST) Received: from [10.67.110.176] (10.67.110.176) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 18 Aug 2022 09:32:14 +0800 Subject: Re: [PATCH -next] mtd/ftl: Fix uaf in ftl_remove_dev() To: , , , CC: , , , References: <20220715071119.2321463-1-cuigaosheng1@huawei.com> From: cuigaosheng Message-ID: Date: Thu, 18 Aug 2022 09:32:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20220715071119.2321463-1-cuigaosheng1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.176] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org PING ?? 2022/7/15 15:11, Gaosheng Cui ะด??: > del_mtd_blktrans_dev will reclaim the resources of mtd_blktrans_dev, > and call kfree(dev) in blktrans_dev_put to release the memory of > mtd_blktrans_dev, so when ftl_freepart reclaims the memory of other > member pointers of the partition_t, it will trigger the uaf problem, > Fix it by moving ftl_freepart in front of del_mtd_blktrans_dev. > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Signed-off-by: Gaosheng Cui > --- > drivers/mtd/ftl.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c > index 200271bdc7aa..bec56070039d 100644 > --- a/drivers/mtd/ftl.c > +++ b/drivers/mtd/ftl.c > @@ -1039,8 +1039,12 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) > > static void ftl_remove_dev(struct mtd_blktrans_dev *dev) > { > + struct partition_t *partition; > + > + partition = container_of(dev, struct partition_t, mbd); > + > + ftl_freepart(partition); > del_mtd_blktrans_dev(dev); > - ftl_freepart((partition_t *)dev); > } > > static struct mtd_blktrans_ops ftl_tr = {