From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4D3CC433E1 for ; Wed, 29 Jul 2020 09:17:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9F5420838 for ; Wed, 29 Jul 2020 09:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596014275; bh=6GFI1yTa7Uzq3OAZBgytEHif8APnSN1Zb6mjxM//sI8=; h=From:To:Subject:Date:List-ID:From; b=UpWn2K4iPmlNIENFwB5IgYgNpCWAtxbZOFKUAuPzExQD2UvFF7eHKsn4C9XjWnDMw /7CLR5MhMJh44nEnzfUYamIKRAGsGiFzWe7SnSGPij5VHB7qDo70RMTVCKRdoe/oWZ GGB8jM4czQcA3eMsmq1o58OWJvSga2nv+9dbZWHY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727777AbgG2JRy (ORCPT ); Wed, 29 Jul 2020 05:17:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:57512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726336AbgG2JRx (ORCPT ); Wed, 29 Jul 2020 05:17:53 -0400 Received: from debian8.Home (bl8-197-74.dsl.telepac.pt [85.241.197.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E19A521883 for ; Wed, 29 Jul 2020 09:17:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596014273; bh=6GFI1yTa7Uzq3OAZBgytEHif8APnSN1Zb6mjxM//sI8=; h=From:To:Subject:Date:From; b=YE9u4wXP6sgeUrmqigzXPh9nrWILwE0ssCm/vqvqEVJX4XdExS/+NtOUx2Itu6LYH zT6G583fxctDOmqZClvd+56oTwMWr2YDre68wUKE+MkvBw604vZPdwLpuxO1P9WaGT /mXsbLYSa3emX4eCM9yTFf1X40SGEMEIYDswV9kw= From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs: fix memory leaks after failure to lookup checksums during inode logging Date: Wed, 29 Jul 2020 10:17:50 +0100 Message-Id: <20200729091750.2538306-1-fdmanana@kernel.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana While logging an inode, at copy_items(), if we fail to lookup the checksums for an extent we release the destination path, free the ins_data array and then return immediately. However a previous iteration of the for loop may have added checksums to the ordered_sums list, in which case we leak the memory used by them. So fix this by making sure we iterate the ordered_sums list and free all its checksums before returning. Fixes: 3650860b90cc2a ("Btrfs: remove almost all of the BUG()'s from tree-log.c") Signed-off-by: Filipe Manana --- fs/btrfs/tree-log.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 20334bebcaf2..f1812f5baec4 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4035,11 +4035,8 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, fs_info->csum_root, ds + cs, ds + cs + cl - 1, &ordered_sums, 0); - if (ret) { - btrfs_release_path(dst_path); - kfree(ins_data); - return ret; - } + if (ret) + break; } } } @@ -4052,7 +4049,6 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, * we have to do this after the loop above to avoid changing the * log tree while trying to change the log tree. */ - ret = 0; while (!list_empty(&ordered_sums)) { struct btrfs_ordered_sum *sums = list_entry(ordered_sums.next, struct btrfs_ordered_sum, -- 2.26.2