Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4820077ybl; Wed, 22 Jan 2020 05:22:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzBHWvb63fMbW2kFhYAUXdXqHgVcYbgLAap7ARHOTciYmqPgqeeUBTWPh9Y7KPRgR0VDT3y X-Received: by 2002:aca:5588:: with SMTP id j130mr6583757oib.122.1579699349836; Wed, 22 Jan 2020 05:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579699349; cv=none; d=google.com; s=arc-20160816; b=u7mg7GIk86fj/mWx2r7kiYTQyijDAfY0dVNqqoDTwH4ncKUrOVApcXG4+xeHiAvb8I WF2T4/gHv8q0bMsVgSh7dA4wqBxR9ohQAWm3AjcF01CnbSk06xTdr8WTcb/060MweBDw csmWiMuWmOfNIPTMZPJRFLNsWsDAYhNe29SolcIyOxhXHD/O2RAHUWletfXPUzZMcwWU oual/SbwbRb6/cySDSaYLqWILQLK/2fGm1DdiRgOlwrBJu4nFDsH4nFiFwdiIE4Np0G+ 0RwpwLd/XD2ItmEMtTvs38fb5jyAJF7DO6pr3aQhads7Z9McPcTkxnD3iYWwMO5XjPAZ SNiQ== 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=N9/kTzMNUqhYdt+xrrgAGLtb929gEZatUzQ3MK4P8ms=; b=RRZ+RtM8u8/p3PB+DXUcKl9Xytk1mqSm0ONB6goL+56e7bT1JpPsRRZdS6tpMK/x3N r3TpVAW6KDgurb2G1mf0Bl3DON196Bhz2Wp1jHgCCAF7xrsO0XK3VUAU0zB/gundmI6I 6VMZ2XslVOE/M6iW6O5AC000l/o4iy7srRTlUuC0rNuu0bvO4UeBpd1tOXiJtsQQpLR7 1jNgA9vvUs3/yiiQIPThXAqFoyCgRO0zLTeEniszjkVaSvxyt7iPOj2jfpTgGpEAQrvE wvG6r/+1fnNJYoEt8K4OoaeL/gv3Z7vTiYhuJBe+qLe2oOBrgKN3aryOIxjqt2SWVliY VaSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yQGbUa0p; 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 g25si24258816otp.20.2020.01.22.05.22.17; Wed, 22 Jan 2020 05:22:29 -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=yQGbUa0p; 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 S1729451AbgAVNUo (ORCPT + 99 others); Wed, 22 Jan 2020 08:20:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:37082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729527AbgAVNUm (ORCPT ); Wed, 22 Jan 2020 08:20:42 -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 B3D4720678; Wed, 22 Jan 2020 13:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699242; bh=i00MMTH6MNa35g4XCiL+6Tw0DJKIbDfNKONbh/FSUdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yQGbUa0pwLjnEp9/S2sW/wLPXPqxc6tzkNCGuAHUqGmj559EAHJOejRmopokuawCD BviBiOxXr22Q58iFpHDSIwtwLPhjOoE9TRjgo+CijJQsR6Midf2UgYFmUpPosOkmJG MARnVtV7mEuimy21xwCwDPpgwoiv0M+s7HiDKoVg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 5.4 085/222] btrfs: do not delete mismatched root refs Date: Wed, 22 Jan 2020 10:27:51 +0100 Message-Id: <20200122092839.796601078@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: Josef Bacik commit 423a716cd7be16fb08690760691befe3be97d3fc upstream. btrfs_del_root_ref() will simply WARN_ON() if the ref doesn't match in any way, and then continue to delete the reference. This shouldn't happen, we have these values because there's more to the reference than the original root and the sub root. If any of these checks fail, return -ENOENT. CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/root-tree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c @@ -376,11 +376,13 @@ again: leaf = path->nodes[0]; ref = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref); - - WARN_ON(btrfs_root_ref_dirid(leaf, ref) != dirid); - WARN_ON(btrfs_root_ref_name_len(leaf, ref) != name_len); ptr = (unsigned long)(ref + 1); - WARN_ON(memcmp_extent_buffer(leaf, name, ptr, name_len)); + if ((btrfs_root_ref_dirid(leaf, ref) != dirid) || + (btrfs_root_ref_name_len(leaf, ref) != name_len) || + memcmp_extent_buffer(leaf, name, ptr, name_len)) { + err = -ENOENT; + goto out; + } *sequence = btrfs_root_ref_sequence(leaf, ref); ret = btrfs_del_item(trans, tree_root, path);