From patchwork Wed Jan 22 09:27:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233353 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=-5.7 required=3.0 tests=DATE_IN_PAST_03_06, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 38DB4C2D0DB for ; Wed, 22 Jan 2020 13:31:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0644120678 for ; Wed, 22 Jan 2020 13:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579699875; bh=i00MMTH6MNa35g4XCiL+6Tw0DJKIbDfNKONbh/FSUdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=URD7cVvHKK+Y3LvUwbWqaQHut46kJ8BUXvKTv7uJgct5MkCYyYMcn/T+r3a549B+N 4FIG9byvA7sMHbjVjkcKnAVJrZZwUfFHAcEKh8t7xn4ipjpwbdHkQLZESVbLvxeIWR yjOsv7NFPessyWC0Y5oRh5WXKsuM95LzlAFe0L88= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729263AbgAVNUn (ORCPT ); Wed, 22 Jan 2020 08:20:43 -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 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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);