Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp773639pxb; Tue, 5 Apr 2022 22:44:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvSvF7msEV/mDnLbFwviGi/hsXmKn9KwRJip1HcY9iyV9LXnmrp1eeDrosC5GxoQ+02SU1 X-Received: by 2002:a17:902:e885:b0:156:b4e6:173c with SMTP id w5-20020a170902e88500b00156b4e6173cmr6929768plg.161.1649223884968; Tue, 05 Apr 2022 22:44:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649223884; cv=none; d=google.com; s=arc-20160816; b=Uz6UrVLh4FElzN+FnxlJ+gxjpzWtKqDC41k9ARcneEQROOvg1UD1vBd1U3bX5E9ubo zspNgSk3uXDxJdLRUEN19h2gfpfAKwCPEcDNiNusTvB4bVLOi5m61EFKjg4NjqqUL9Et mU9Sr5m3ONieTKLrw/TLoOU0lbJXpEtxT1Ahkd6OuCnDFeLiZ9wylt/gs2QS6Zo0RJwU ObZF+1on76Zso/iBQnXnuSi5OCuDkmmq6Srzva2F5/rnnV9h5Ij+JMvEsWf7SFyXruxI PNuZQQHvMmV3HfAMMIaGhCXc+brZvHWLD6sh15HU+Mk+kIz8sEN/4telu5EtrUsgKxB7 Oseg== 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=8BHfD4ekKNScVzBtLrQc01vCKsqTcH6PE6RPSUUGg+I=; b=p+xH818OluZ8cOCAgl+on4DW1iGt35QG5NDCh30uHcW/BUDr7XswZARo4ybLv6CTO8 3QNM2w8ccCAKVpMbwIpmAygd1dUPkqfsG2nBDPQ0gfiAE8sGZOUVHPLE+WTq9Frr7Mm8 yoFPC817+SUxiWN5i6W0IQ8Fic5fouCnHwEEYmqKxhu6kt+PfF3rG3qWjVCkV8u6iTni LZjzboeqaixnqL20shQBYAcXsqo7sYAfvr6G4K7x4jwIS38+vsYJDLWArZc6q2BlM3SE S390BdvqJ7OQrzMx67L+rYi3Q+OJRoXJcQn13dlshrzwRFHiTdI7RCv0hW5RK24CAScU g/bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wHKRjwe6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id bc20-20020a656d94000000b003836f6959b0si10045713pgb.522.2022.04.05.22.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 22:44:44 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wHKRjwe6; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BEBE5467E20; Tue, 5 Apr 2022 21:57:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1846294AbiDFCDo (ORCPT + 99 others); Tue, 5 Apr 2022 22:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351659AbiDEKKO (ORCPT ); Tue, 5 Apr 2022 06:10:14 -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 2CF3BC4E29; Tue, 5 Apr 2022 02:55:52 -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 9F565B817D3; Tue, 5 Apr 2022 09:55:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DC17C385A2; Tue, 5 Apr 2022 09:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152550; bh=DY4XAKL26rlSLT9GnWVUUFFZgtewayqgtln5Q3okulk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wHKRjwe6/6XvUQy2rRHziS9jPJ1oNKOZITVZo2HAf4VJ11YccdPjpPcsKUaBiV2Cn AxMffQN63nletk4yNGAKCbF5CYbex48iz4mXSy6Zh6Oa2vQDuITO+Mm5pNfoXD3qsv rbjQNthV3Nx6jrHsamCnUu24yk2zFDg3vRYxnl4A= 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.15 816/913] ubifs: rename_whiteout: Fix double free for whiteout_ui->data Date: Tue, 5 Apr 2022 09:31:18 +0200 Message-Id: <20220405070404.291071243@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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 @@ -1425,8 +1425,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; }