Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp447980iog; Mon, 13 Jun 2022 06:10:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4v6CLnD6RJTaxYxnN+5uzmpCSBvVBKa4MYOHQRwKWrnwxixTF//CroklMtnYDGr9Uoqmd X-Received: by 2002:a05:6a00:84b:b0:51c:21e3:b542 with SMTP id q11-20020a056a00084b00b0051c21e3b542mr39441825pfk.31.1655125413004; Mon, 13 Jun 2022 06:03:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125413; cv=none; d=google.com; s=arc-20160816; b=qa29RPhTvK8UEZPetO6QPShE1Wk1ujYQdmZYCEjEaKx2sY0P/jI7wemTz8Bw6zrLKA 20XW45OJRPd8qZenJdDv1pBHCTx74WYBK/a5kFudYw5Nt2VZQQs9GAAPiI45yDQiV3ze Pl/MWoPPq4HLrf3X9OrS+n5VRF/OqgCWTAcFXKFwb/kCey6q/AvX+LGR9PRl9/SyURaS AQf+/hsi8G6tO4tgsI+Td7XGu8NTU86RbdQ+fqoMFMyqLyOvNd3FzzPpyXPBJ+R//oiP 2/YiY7xrx0i+59/+vK3OmlsC2LMOqrrirdelPwZvoUQsfU32oG/uSbOQ69DQV1oH5MvN 4zAQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YA4z8c7clotrhbk0bsjOuelR00W1hjLaciWdwDPYi3U=; b=aykMMFdjMJxJvkVibFUIP1qKiTpPMUWRe6w/X3vE9Zh4VEcXec9ImP9cYb47y+UkKg 2M4T7UTGTV3PDKX214KW6wA9NnIwyRggwRYXGKSPwKGEuV2ZD8vyukEHGrjFqYjRMCVI 9vqTIThj4m/1SKw8vFAsTa6TzC2b+s9yGin3xQ4E7IbYenvqRgm9vvaUUKTRkIJ9tbB8 Idj0GJlJw8755d8JouQTi1/FCvYAie0lnu6yrfS9BUxOC0G/WzWbQ3Naa4BPNtzEF2B9 8HjuaYKQtXu/w73c3A3k56gempkdlHfTrtJELGzsewA5DDbAm1Atb7sHlhD7WpHDePbv S17w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WY7iocI6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a17090270c900b00163e2b5e3fbsi9695748plt.145.2022.06.13.06.03.18; Mon, 13 Jun 2022 06:03:32 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WY7iocI6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351539AbiFMLE3 (ORCPT + 99 others); Mon, 13 Jun 2022 07:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350383AbiFMKyv (ORCPT ); Mon, 13 Jun 2022 06:54:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29AED1EC72; Mon, 13 Jun 2022 03:31:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B9DD160FB1; Mon, 13 Jun 2022 10:31:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE4D4C34114; Mon, 13 Jun 2022 10:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116273; bh=o7pGxIWwS9XsgJFBoYbgEMRnyrW1PeHRlM/SCQ7s4h8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WY7iocI6f6x/DjQ4wSfSwZUWrgwvt/hCzzKTRkiHM6GqcZsES9aLBQcy3iUaSYWHW 9A6sY3g5Kp6MPVhe4Ps3JAYcc7Q5TIjdz1K4DoH1qXeph0wfjcUAtGX4Pd5mZThXPO JKYKzsVnSvEuRY+vIqMINX5KkotImlFFowXtG68E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Richard Weinberger , Sasha Levin Subject: [PATCH 4.14 162/218] ubi: ubi_create_volume: Fix use-after-free when volume creation failed Date: Mon, 13 Jun 2022 12:10:20 +0200 Message-Id: <20220613094925.511296129@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Zhihao Cheng [ Upstream commit 8c03a1c21d72210f81cb369cc528e3fde4b45411 ] There is an use-after-free problem for 'eba_tbl' in ubi_create_volume()'s error handling path: ubi_eba_replace_table(vol, eba_tbl) vol->eba_tbl = tbl out_mapping: ubi_eba_destroy_table(eba_tbl) // Free 'eba_tbl' out_unlock: put_device(&vol->dev) vol_release kfree(tbl->entries) // UAF Fix it by removing redundant 'eba_tbl' releasing. Fetch a reproducer in [Link]. Fixes: 493cfaeaa0c9b ("mtd: utilize new cdev_device_add helper function") Link: https://bugzilla.kernel.org/show_bug.cgi?id=215965 Signed-off-by: Zhihao Cheng Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- drivers/mtd/ubi/vmt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index 8f641448a97a..d32144c0098a 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -315,7 +315,6 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) ubi->volumes[vol_id] = NULL; ubi->vol_count -= 1; spin_unlock(&ubi->volumes_lock); - ubi_eba_destroy_table(eba_tbl); out_acc: spin_lock(&ubi->volumes_lock); ubi->rsvd_pebs -= vol->reserved_pebs; -- 2.35.1