Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp182657imw; Fri, 15 Jul 2022 00:29:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vKS9JMLFZUhtBWz2P7ldyruJ9Tu+nqbcyrmKFWkpbMaR+wKFNIaxtVPuSlv+yC3/qwdkIJ X-Received: by 2002:a17:902:f792:b0:168:e97b:3c05 with SMTP id q18-20020a170902f79200b00168e97b3c05mr12029724pln.94.1657870145471; Fri, 15 Jul 2022 00:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657870145; cv=none; d=google.com; s=arc-20160816; b=jNvNR0rjjK+hLHVW/V4pLfv8hy8NOV+dbanQAVWtJGXH4dZqK72pGn9r0ftE2xZe+3 pKwWxuTJBic/5x+mXj5xarSBAVe6kp6KEdcuMg9PZHmlWsRx8cGgg2VYvTLPvke/unUA OsiPuGR+tOjLvi4uB9spEh0M07miJQKfsHBbZ6bR7kabWmHRPh+BfQ38Mg4rXqjhmcM3 1LNXNyLG/WHJK/GFnlfZFJWTvXsAEqti7yrJp3bUOZzuV+aJYUkkn/0qPy9nMu0P7B5Q 3+OIK+AMlZiN8z9svfLDCZ7OWpER2tfCG1w5DuwFMXTJ7ED/VEbCsSNFYt56bPFtlr21 M2mw== 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=FMKKmncAZIcKsiGNT4mpB+6bxXqHs4rJSt1j0QBsIwQ=; b=jzu5VFyu+OGdJ6UftIhmowGhNudl59kg1C0YWQ4XN+yjZOJxOJKdg2VsuVqA9VRFLD /gNpTUBFFINk6ghOKvNTsP1BVPbv03FjNvn6NCG7xMWDZzg6Cw1ENOseM9CfX6e4HqXd 8HYTWS88AFEw6+UlZkAyev8XYXtla3MH7uvso33Y4R5AKg+icLnI1VW7UzO5lUoHaKRk q0OgzpovBD3oVon69blX4ijsMjuAskI4hSogRttGQTkZaAuAmF3H5pfBMImfoCbCG9zC rV8jj+Fnon6FHoWA9acWjRpygWUqzPZHo+fUd2xj59x3oN7vh+Y+w9RnNG27akP/UwTh ruGg== 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 r145-20020a632b97000000b00419b645cf0asi3401098pgr.262.2022.07.15.00.28.50; Fri, 15 Jul 2022 00:29:05 -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 S231521AbiGOHL1 (ORCPT + 99 others); Fri, 15 Jul 2022 03:11:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiGOHLZ (ORCPT ); Fri, 15 Jul 2022 03:11:25 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E63B17653 for ; Fri, 15 Jul 2022 00:11:22 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LkjBg2GjQz1L8W0; Fri, 15 Jul 2022 15:08:43 +0800 (CST) Received: from dggphis33418.huawei.com (10.244.148.83) 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; Fri, 15 Jul 2022 15:11:19 +0800 From: Gaosheng Cui To: , , , CC: , , , Subject: [PATCH -next] mtd/ftl: Fix uaf in ftl_remove_dev() Date: Fri, 15 Jul 2022 15:11:19 +0800 Message-ID: <20220715071119.2321463-1-cuigaosheng1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.244.148.83] 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,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 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 = { -- 2.25.1