Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp577616iog; Mon, 13 Jun 2022 08:28:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz03a0Lehdw0x2j8v/Z/z0Toee6aq+oSg3/WZaATADOygP7osiMzTtxZN79ECVrn9Y6m3zJ X-Received: by 2002:aa7:dcc4:0:b0:42d:c666:62b5 with SMTP id w4-20020aa7dcc4000000b0042dc66662b5mr321783edu.206.1655134107043; Mon, 13 Jun 2022 08:28:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134107; cv=none; d=google.com; s=arc-20160816; b=XsDA2wzh2rlFdT2AFnnoNWOOnLSFf9W0hi3tAvO9hRuCwJzjTtxNHaOf3nPjYU1TRY 9A4VdgNJI5Ym1eVHNS5P1iyvdKRvv0f09ArkI5Qv7sB2QOxjA0RmRGxAlsqvkRj/z5Xr LUSCwXSFInqRcpqpjeM/wD42Nrl4vEmi6bTPYSbbPPVEdK8Ie1lo+NWuEnqafhcSQ7eK CWws+O7Jr07vhtS+lzTlDqZAXhX6wGe6tAiWVmTk5KSP629i+AWUDLP28Ls0czdHl5+p JMyf+lz5fQcGaBOZ8Q5Wgd4Gukspl8kB7wxGUeNRgHbrW2v1Cs+AEC6kb/VTJnREKR+Y z7Bw== 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=kmj1uNT9iWy//YnymMsrk4yCIx7KB9TllGxkaBrofdc=; b=FMVgizK/mQ1toc74UIPuxqCjZ7yp/p3r73Yk1Smd5/7N7/5Fc0CH3/1l0Drv5Bp5JR jFLa9OwmEE+mCBR7KvQumDR5FQOvAcPDQL5ScVl+M4xSibJCXGczk8khktWna0Zb/XJ5 YJmk265x+dP+KPftcEjmDoS+Nx7x4DotSu9kMvVJWiPTGTPqh30FQF2vg/8lFACw55Rn +gc7C/UfrJkme1E/3dcm7o/U1M5jhAFKYsmqQ+avRLHjwX42aSYK7Uh7VLkegaBRD+z0 3THORZRmT/NbzLtxwFAYD+52Cf3ApDcZVk+voOVOGAKv/LtYKicWquaSpb8gw0kiUfQN L48g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y7U0ol3P; 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 sh38-20020a1709076ea600b00711d49f9985si8500895ejc.755.2022.06.13.08.28.01; Mon, 13 Jun 2022 08:28:27 -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=Y7U0ol3P; 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 S1355263AbiFMLkN (ORCPT + 99 others); Mon, 13 Jun 2022 07:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355217AbiFMLay (ORCPT ); Mon, 13 Jun 2022 07:30:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23B9F419A2; Mon, 13 Jun 2022 03:46:53 -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 ams.source.kernel.org (Postfix) with ESMTPS id 90E08B80D3B; Mon, 13 Jun 2022 10:46:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EECD6C34114; Mon, 13 Jun 2022 10:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117210; bh=4uPzDoDtm+L7EnFXiMH8EH9hH4YgpoC0Sl0c04Rut6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y7U0ol3PnFCqdlMk6Sc4gMiolQ3gP0DGc6AkmSK9jX0QjAaPPZHJ70yqb1PHGUsu8 I2nJhWT7SmMunHlRGqZEI4HMYjSYqfaPit2WafYc0yZ3uIbxylRGeEwjykFfMiqU8X LejUMaA3IJv9CLjVp5H9U9S6Bhb1MDCFyNYy1FOQ= 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 5.4 328/411] ubi: ubi_create_volume: Fix use-after-free when volume creation failed Date: Mon, 13 Jun 2022 12:10:01 +0200 Message-Id: <20220613094938.562932574@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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 1bc7b3a05604..6ea95ade4ca6 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -309,7 +309,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