Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp601199pxb; Tue, 5 Apr 2022 15:33:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4yXoYIoeiziEJujQtqdXkEO0k9/ISCtdeLCmTzTZ4D+1fqgRnKwiZbt0jR4GgAk/r9Hj0 X-Received: by 2002:a17:90a:448d:b0:1ca:1ff6:da22 with SMTP id t13-20020a17090a448d00b001ca1ff6da22mr6683686pjg.12.1649198002660; Tue, 05 Apr 2022 15:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649198002; cv=none; d=google.com; s=arc-20160816; b=TT76IKvtgPiPFYTl9+z0hS4TQa0QiWDPlGWpAmnkh8T3kSicnKV902qxnQq/1OZCjI C/jOVreTULFytv68tGGFBmz/ptUqNiOObAwXhYfVa7sn7D9Bh1ltKcn8Ti0CAom0aHIM 7gUfUPQ1GYM8eSHZf2bXfF0royG9P5IMT+dNPtf29d/5vBeNrBoNS652TVz9bhWntpnb rxk4QbDEvydsr/6jZ2UffMc7uHg3FzZjRNqXxs6JzYeiC8zFPlRKcxCMVJJClzGFXz23 YPpdGBdXImtvWuOVG2AE9501eWepvUyg9d50w0+7d1U8mgHoGkMcFKfi4exmILAhlVQt k04A== 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=fhqCOEdAJUcTRK/8NEp6dMD8k0MVYktvbSHdirI+TdUKN3fniL2fUiy22psp+as8v/ fHr0FDg3O4RZu3PmIYpNWojHTpBS5oTntORwcB8Jk8uaaCBvwxVCFZVnGzUgU/8aAc7t 5gHRo8+PgpawMT3YfnwlpzPaOg5Dr7dYZ+ZPMru/gxZ02bzpdbxwGVG45YB/DpNFukbw 8zWkg8FhQvrtI4k/8pM3cePy6kfPMZce/R7ReRjWr1aUJOjiNkgP6dUKUNiPQY8++1F3 Y7A3VcSvhf6/W71syY3CA1wSZoU+qTw0NcZLEPth8VgbOuPfzD/qldk5e2llw/W0eHHb kIRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vK0S4FO0; 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 u7-20020a634547000000b0039845840ff2si14080435pgk.41.2022.04.05.15.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:33:22 -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=vK0S4FO0; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D135C20DB0B; Tue, 5 Apr 2022 15:15:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388905AbiDENdJ (ORCPT + 99 others); Tue, 5 Apr 2022 09:33:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346096AbiDEJX3 (ORCPT ); Tue, 5 Apr 2022 05:23:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D833B53C3; Tue, 5 Apr 2022 02:12:56 -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 E553BB80DA1; Tue, 5 Apr 2022 09:12:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F263C385A2; Tue, 5 Apr 2022 09:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149973; bh=DY4XAKL26rlSLT9GnWVUUFFZgtewayqgtln5Q3okulk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vK0S4FO0QQoOEZlEiTHTSfuv+kJLbxWdtIVfHIpflV8+ZG1lIN1MrSNjrk5dMB6zS KIedVDM2nyV6sl+E7rmHQ9i+9PWHpS6Zj5qfYzhGHuhLkAN81cqDa2ijvVFxBceODX 7+TRymeDfJMiATFYDJ5hhYPIwFg6vJhUtbCtMD1U= 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.16 0907/1017] ubifs: rename_whiteout: Fix double free for whiteout_ui->data Date: Tue, 5 Apr 2022 09:30:20 +0200 Message-Id: <20220405070421.147160509@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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; }