Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2834391ybg; Mon, 28 Oct 2019 03:12:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFuKdVyWtGz++8hSK1sdWl8GLBvt+TWNRuxMZgmQecUbAWj4a8bIQFSNGiHB+I8mY2onso X-Received: by 2002:a17:906:aad9:: with SMTP id kt25mr5429950ejb.129.1572257551963; Mon, 28 Oct 2019 03:12:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572257551; cv=none; d=google.com; s=arc-20160816; b=XJMxoVcZD0cng7Zs5RMEu3G8wy+RXRG/Htbz0cS8eD4PbRf+HSJZccpBZO+YAAE+Q4 TDp+CrU70IBumVnp/N6Tu0Sd1lt4frt3PtDg+8J0cg4toWvFozfkxTUqp/PjjkuCJ+Qa VazqxJkBRvyVFOLmeFmRAA2XglEFXXyUtC8ZLoZx5bK+g0pi+xA1UlHZoU9M4SyUvihK iGjt8QBIflz3mZCYy8RCSKuO8AL/3RMeJdvDEIpZSgKZche5xO+qkdXoOMeJoTFlc8eS yIMKqE8a7CBj8qOFf6ZgDSoc3xkKHyNKTUTwOev2BG6x6kUray/9qhACKhb24VNzZ2Uo ZfGQ== 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=jXEBdE4i+Dc01xxAHWbY81bFj+QkYdUqwBbMuKo+GMs=; b=LFa3nAhc5iMYyrSiGtLpR4ZrW3aqjges65z0swlGmgsLG1GYNyFcxLuN3Nu7fBbD9n GZ1hY+e7/u/ue1uI5Zr5eNHhOb39eDhNG6537vw8GdQWhe/wdRh3c3GOxoQVVJgwxBQh cDIS+kQst40IDDzHivqPGYDzWHJyk2fB+7fTnKdCT1bBpW1i3e/x8kEiQHsJME4EYc+h 3ia8O9boNiuNKEas92LHKU8uZehu2rv4OGR07sud6CwZnUHz+6uoo8pHjWYkCkxuD79J XghDHWaD95kOpopJ+N2LKP6phbsreI6jHN62rpRyJeyS41PcujHNgkMbnB0QCFlINrm4 IFDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tYSFzwW6; 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 e10si6077547ejk.416.2019.10.28.03.12.08; Mon, 28 Oct 2019 03:12:31 -0700 (PDT) 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=tYSFzwW6; 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 S1732913AbfJ0V0U (ORCPT + 99 others); Sun, 27 Oct 2019 17:26:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:48240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732897AbfJ0V0R (ORCPT ); Sun, 27 Oct 2019 17:26:17 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (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 28EF221D81; Sun, 27 Oct 2019 21:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572211576; bh=u5oSFv9xULQGQzEcqZj57rkL26YvaNycrDuA8jm+gcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tYSFzwW6NDOPO6yf/9Ax9sJy+CX2js88MzZTghoxWhNYi7vFUc6PvBR5fLf3AYrDQ WD6dW6nGTwUdfnWMNQxWMJvlWbb4oVix1TupRgoXc7PL0kwaSY0zLu4+lL91/CJDrO +j+Sf6JN4iBsyaUH4lmR4GwRwqIFoJ4GEzJglbrI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba Subject: [PATCH 5.3 184/197] Btrfs: fix qgroup double free after failure to reserve metadata for delalloc Date: Sun, 27 Oct 2019 22:01:42 +0100 Message-Id: <20191027203406.419609792@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203351.684916567@linuxfoundation.org> References: <20191027203351.684916567@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: Filipe Manana commit c7967fc1499beb9b70bb9d33525fb0b384af8883 upstream. If we fail to reserve metadata for delalloc operations we end up releasing the previously reserved qgroup amount twice, once explicitly under the 'out_qgroup' label by calling btrfs_qgroup_free_meta_prealloc() and once again, under label 'out_fail', by calling btrfs_inode_rsv_release() with a value of 'true' for its 'qgroup_free' argument, which results in btrfs_qgroup_free_meta_prealloc() being called again, so we end up having a double free. Also if we fail to reserve the necessary qgroup amount, we jump to the label 'out_fail', which calls btrfs_inode_rsv_release() and that in turns calls btrfs_qgroup_free_meta_prealloc(), even though we weren't able to reserve any qgroup amount. So we freed some amount we never reserved. So fix this by removing the call to btrfs_inode_rsv_release() in the failure path, since it's not necessary at all as we haven't changed the inode's block reserve in any way at this point. Fixes: c8eaeac7b73434 ("btrfs: reserve delalloc metadata differently") CC: stable@vger.kernel.org # 5.2+ Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/delalloc-space.c | 1 - 1 file changed, 1 deletion(-) --- a/fs/btrfs/delalloc-space.c +++ b/fs/btrfs/delalloc-space.c @@ -371,7 +371,6 @@ int btrfs_delalloc_reserve_metadata(stru out_qgroup: btrfs_qgroup_free_meta_prealloc(root, qgroup_reserve); out_fail: - btrfs_inode_rsv_release(inode, true); if (delalloc_lock) mutex_unlock(&inode->delalloc_mutex); return ret;