Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp983192pxb; Wed, 6 Apr 2022 06:01:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk6WFtz3/MYfmrJa1tHLSvjaCT6zMfAeUguAjzAt5jJnynzTDTYotpLCWWo8jiEh1gb6X7 X-Received: by 2002:a02:6a6b:0:b0:323:fcf9:2227 with SMTP id m43-20020a026a6b000000b00323fcf92227mr4360787jaf.137.1649250104007; Wed, 06 Apr 2022 06:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649250104; cv=none; d=google.com; s=arc-20160816; b=MkwZyKWNbiy+7OWWiCkbL47t66YjXD7+DY5M2a1U6j8k3rJlF1h4hpGcyDZ97Zsqtd Ub1BKARqVv9LWd5fo8a9YYeYP+nfjBmv2ujCxbYRWZFRkyWk8nvx0Mw+vo19+KacBlOF xchc4noIm0ZBoMdokRIoyMztqIsVhXFDTXi8Jqqm1Bb0pPrerGuQBSxCzCxoaQyCiN3S TQ08ScOeQT1ACAFAzVImsJT4PZSkU1dsutxCTkMqaddGRKq4X7k2lDNxqDQntJ5aYWTB 2J2S4mRtR3Z+aVOLuRH8Lk62s6OstELJHky1bI6MNQkp6BMefgPpQ2e8RwZ6fG+v/aM0 GhIQ== 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=ibV1qASvJT54t6xjY8PjYltpYP2QCk6H07/v4scIq58=; b=pMic1Ie1c4AUYvAWPL6dxxQMxpHPKEtCtQ+dKXwFJZQ/CpKPLk1nwYl3rG1ktm6sMp vaksrpNcitnZkqQhOAfXN9bnO8H+ij9yA4Lf7mElv0p7qJSCzEPr7n/IiaYwXpi2oxVw peMslH3QZW/piZIZ1e3bTkw1DOuV3TdlXVQmwzO+CH+/xCM8BjBVivobLvR1Y0Gmhxuo MMNr57EgYXzdLXXC6DsP30Pk7gef5ehDZ7tJPlIM3F1UKkqucuS7rz+jKhs//pxTYx76 rvCVZCT5OtUmx0Nvw59kOJCwJdBhm8XhiGGY2L7ocGkU2eb7GPvkMgIFwJF9gfNhpDFq VICQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wPrLFDo6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v13-20020a056638358d00b003236d67a304si8483180jal.21.2022.04.06.06.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:01:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wPrLFDo6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E409C563C93; Wed, 6 Apr 2022 03:18:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382667AbiDEVjB (ORCPT + 99 others); Tue, 5 Apr 2022 17:39:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344780AbiDEKkN (ORCPT ); Tue, 5 Apr 2022 06:40:13 -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 5967D2CC84; Tue, 5 Apr 2022 03:25:22 -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 16995B81C8A; Tue, 5 Apr 2022 10:25:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84E3AC385A0; Tue, 5 Apr 2022 10:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649154319; bh=kGwJY3ChgwKrJH3wgv8722md30dZcRAVn1RUxtVBoOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wPrLFDo6va+UOBGTou+gbJtKc/tn8kcERjz3GEKet6ksveNoU8GO5MSAp3pJ946+N TG33vfmJkCzhypZPnpGMiD0ZrT7CLNJYH3ZXuyr26yDujhlpcAWSJnhoiYk7+ksbVk fZcQji4MSIpwwZ8xc5mSNE/ZivyE40mQ+fBHgo5w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhihao Cheng , Richard Weinberger Subject: [PATCH 5.10 538/599] ubifs: rename_whiteout: Fix double free for whiteout_ui->data Date: Tue, 5 Apr 2022 09:33:52 +0200 Message-Id: <20220405070314.852777176@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070258.802373272@linuxfoundation.org> References: <20220405070258.802373272@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 commit 40a8f0d5e7b3999f096570edab71c345da812e3e upstream. 'whiteout_ui->data' will be freed twice if space budget fail for rename whiteout operation as following process: rename_whiteout dev = kmalloc whiteout_ui->data = dev kfree(whiteout_ui->data) // Free first time iput(whiteout) ubifs_free_inode kfree(ui->data) // Double free! KASAN reports: ================================================================== BUG: KASAN: double-free or invalid-free in ubifs_free_inode+0x4f/0x70 Call Trace: kfree+0x117/0x490 ubifs_free_inode+0x4f/0x70 [ubifs] i_callback+0x30/0x60 rcu_do_batch+0x366/0xac0 __do_softirq+0x133/0x57f Allocated by task 1506: kmem_cache_alloc_trace+0x3c2/0x7a0 do_rename+0x9b7/0x1150 [ubifs] ubifs_rename+0x106/0x1f0 [ubifs] do_syscall_64+0x35/0x80 Freed by task 1506: kfree+0x117/0x490 do_rename.cold+0x53/0x8a [ubifs] ubifs_rename+0x106/0x1f0 [ubifs] do_syscall_64+0x35/0x80 The buggy address belongs to the object at ffff88810238bed8 which belongs to the cache kmalloc-8 of size 8 ================================================================== Let ubifs_free_inode() free 'whiteout_ui->data'. BTW, delete unused assignment 'whiteout_ui->data_len = 0', process 'ubifs_evict_inode() -> ubifs_jnl_delete_inode() -> ubifs_jnl_write_inode()' doesn't need it (because 'inc_nlink(whiteout)' won't be excuted by 'goto out_release', and the nlink of whiteout inode is 0). Fixes: 9e0a1fff8db56ea ("ubifs: Implement RENAME_WHITEOUT") Signed-off-by: Zhihao Cheng Signed-off-by: Richard Weinberger Signed-off-by: Greg Kroah-Hartman --- fs/ubifs/dir.c | 2 -- 1 file changed, 2 deletions(-) --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1423,8 +1423,6 @@ static int do_rename(struct inode *old_d err = ubifs_budget_space(c, &wht_req); if (err) { - kfree(whiteout_ui->data); - whiteout_ui->data_len = 0; iput(whiteout); goto out_release; }