Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4820177ybl; Wed, 22 Jan 2020 05:22:35 -0800 (PST) X-Google-Smtp-Source: APXvYqy3ovz97rDqAqMfl8qTR+tlm3TIk7YrJN0mn4uw4IiM2mt96dff/EjbFQCh/CPKvCZZx0L5 X-Received: by 2002:a9d:6f07:: with SMTP id n7mr7132533otq.112.1579699355643; Wed, 22 Jan 2020 05:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699355; cv=none; d=google.com; s=arc-20160816; b=PrVZbhjVy3Ef9RatSggWq9GDmzOGn9RumHvZ+YImIV5cCIpD0/bTmn49EjJG8dsqpB EJrDcdvt8b+aY7yK07Zirvwck8pw39CD7KC/l8gd9q79yBm9z2EEAjrzvPn4AclVlmqu PyeI6SR0nSPIbPDTu+JAVpYQmdK1M5iSgS7O8K2bawlAXptue6q04DnGFCFYSR2Pk0S+ H8UYa/rOrQ4WFTXO483yEiq+yVESVX4OOUZ1H355SYxF49mBD0l57pdO661NaJEmIbGq P+sbuXanbLgUlZ5BL0w01kHeo62GYjxRc8gNNpkA6viWNcPp+KvzR774xnVBNtILHfx0 vb8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O8/Mhvzh3MdDVGP0OyfDYdERAN4dqOAFgDa/H84lMqE=; b=h6tepnrScNIYZ3lncPFFjZWuT4XU2Uk06XU9FyY4iJDgOJl1QhF6Nkf+rXgc3CCAnM eCbF1T6wQeHhKHegp99v5pzIMiqAEh9C9w4vZE+Ulz0TEkXJakEiFTM9qLWjyJwTXa97 kXdUwi3qBIhTH+45iJqXqlgdrEWB0qB2uawxX+GN4IqpLvdqHBmzN0w7VmOL3oazalRh SX4fAQ5Iw3/0nEgEwHR5uexknCHQlQ1gHRTspGpLof9qnerMXhrEFQyQRB66IfhtaX0C fJUt6Wh/MzOtU07el0iRAooQlwuyjuL3v/dobCCr7UPvPanUTgMeCtXEsGmx5Gy3EJx3 df8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JePgdlN8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 12si20181378oiz.131.2020.01.22.05.22.23; Wed, 22 Jan 2020 05:22:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JePgdlN8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728913AbgAVNUv (ORCPT + 99 others); Wed, 22 Jan 2020 08:20:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:37236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729130AbgAVNUt (ORCPT ); Wed, 22 Jan 2020 08:20:49 -0500 Received: from localhost (unknown [84.241.205.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 206C420704; Wed, 22 Jan 2020 13:20:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699248; bh=DvpWguXOaO9qZ5/G7dCXQkTSGzgL7lHWKUKhKMkLb9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JePgdlN8rU7w5698IThxmnURvFox9n8EFpASFkmCUx6rARwVxzFhw2ChNCZf2qbqW i+j99532Jf676b3lv2IPq1wei5Sy8N96SNGKx4NQJwOA2vv6JMHwTtg0PXLTz800ZB kfMHtKV+dlpWzfWAqNGNb+G/UX0/XC9eDzCG+Hyw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Johannes Thumshirn , David Sterba Subject: [PATCH 5.4 087/222] btrfs: fix memory leak in qgroup accounting Date: Wed, 22 Jan 2020 10:27:53 +0100 Message-Id: <20200122092839.946009315@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092833.339495161@linuxfoundation.org> References: <20200122092833.339495161@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Thumshirn commit 26ef8493e1ab771cb01d27defca2fa1315dc3980 upstream. When running xfstests on the current btrfs I get the following splat from kmemleak: unreferenced object 0xffff88821b2404e0 (size 32): comm "kworker/u4:7", pid 26663, jiffies 4295283698 (age 8.776s) hex dump (first 32 bytes): 01 00 00 00 00 00 00 00 10 ff fd 26 82 88 ff ff ...........&.... 10 ff fd 26 82 88 ff ff 20 ff fd 26 82 88 ff ff ...&.... ..&.... backtrace: [<00000000f94fd43f>] ulist_alloc+0x25/0x60 [btrfs] [<00000000fd023d99>] btrfs_find_all_roots_safe+0x41/0x100 [btrfs] [<000000008f17bd32>] btrfs_find_all_roots+0x52/0x70 [btrfs] [<00000000b7660afb>] btrfs_qgroup_rescan_worker+0x343/0x680 [btrfs] [<0000000058e66778>] btrfs_work_helper+0xac/0x1e0 [btrfs] [<00000000f0188930>] process_one_work+0x1cf/0x350 [<00000000af5f2f8e>] worker_thread+0x28/0x3c0 [<00000000b55a1add>] kthread+0x109/0x120 [<00000000f88cbd17>] ret_from_fork+0x35/0x40 This corresponds to: (gdb) l *(btrfs_find_all_roots_safe+0x41) 0x8d7e1 is in btrfs_find_all_roots_safe (fs/btrfs/backref.c:1413). 1408 1409 tmp = ulist_alloc(GFP_NOFS); 1410 if (!tmp) 1411 return -ENOMEM; 1412 *roots = ulist_alloc(GFP_NOFS); 1413 if (!*roots) { 1414 ulist_free(tmp); 1415 return -ENOMEM; 1416 } 1417 Following the lifetime of the allocated 'roots' ulist, it gets freed again in btrfs_qgroup_account_extent(). But this does not happen if the function is called with the 'BTRFS_FS_QUOTA_ENABLED' flag cleared, then btrfs_qgroup_account_extent() does a short leave and directly returns. Instead of directly returning we should jump to the 'out_free' in order to free all resources as expected. CC: stable@vger.kernel.org # 4.14+ Reviewed-by: Qu Wenruo Signed-off-by: Johannes Thumshirn [ add comment ] Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/qgroup.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2423,8 +2423,12 @@ int btrfs_qgroup_account_extent(struct b u64 nr_old_roots = 0; int ret = 0; + /* + * If quotas get disabled meanwhile, the resouces need to be freed and + * we can't just exit here. + */ if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) - return 0; + goto out_free; if (new_roots) { if (!maybe_fs_roots(new_roots))