Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5615635imu; Mon, 26 Nov 2018 03:03:13 -0800 (PST) X-Google-Smtp-Source: AJdET5eAZ/qogkTomO0chn3cpyy0tQc555g/4i3ySuRXA3dCX/qKh8072MYwVHnk4k7OtDKeUoj3 X-Received: by 2002:a62:3948:: with SMTP id g69mr27785406pfa.114.1543230193163; Mon, 26 Nov 2018 03:03:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543230193; cv=none; d=google.com; s=arc-20160816; b=0K7nHR/8cTVKCHMXFDRSba1ojvqaObi6g7pG0+he/2B5rclxqLc72Y30cAmkuNssTv BT+o/LnhGsHg+K3MemUK/xL4KBz6YzGqHlZrIC9Uq+dXL7eyCFuJnAihNR00fdAFHll8 yXbiUg5fN9HTjQnwvuqUFbXFHan+P200vjatQ9MqIw8GbHMQxXr5BI6ujfebfUkXeNXG sw/crU266dj4VI6sIQ5d+1iU6wjQGElF/7zDkNYYIqtOh84ggtnLJNh1ruKJnGRAZbAS zn9pqByxW/L2sq1o6hNTW+HZS1p9C5boTPAmsodMOKzHdmKDgI5OlI+tiO72dtQ9JzkM GQlA== 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=+HNtzJToiBYUlTYeNFRsBt4+IQDXt5Kd/9uZJAXM0qw=; b=gOmhsvB6+xyMzxYtkxli2MSfYyrDX4VCzWXOBd9vjK9arhGmdZHTgvlJmfBCHKYiSk HxCXx3YOdx90niOdcO9qKtavkbdPoEG+77gnSpjL0Bmmw9AWB5BB/xuf128o4W5omu57 WrrN8WVX4G0Vf9+vZ0qqXpnx/xr4yntq4TgEuU8h9DfMQs/IP/d41/n3BBlDGiiPNWIo Iu9aELE3OoE/acyylNupQKf03nJalT6mOhN16Gh/nqIAamzi9hwpJ4GXRQzBefPTzUOp cVQ7PDfJHw1U6DtilLumAeIGN5H6lrWiZ6ZIAq/QndO6EX3MxtCIxDo3QuV+dtUjLbnn FpJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wnDBgMKm; 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 b128si17118925pfa.283.2018.11.26.03.02.49; Mon, 26 Nov 2018 03:03:13 -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=wnDBgMKm; 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 S1729776AbeKZVx5 (ORCPT + 99 others); Mon, 26 Nov 2018 16:53:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:35828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728039AbeKZVx4 (ORCPT ); Mon, 26 Nov 2018 16:53:56 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 E627B2146F; Mon, 26 Nov 2018 11:00:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543230011; bh=XpORD2Fpb8e40Tqor5LTIE05BH5MM4vsIfvfP6obS9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wnDBgMKmAsHfr2kjf1alVzY+M6a7XrQLM17pM/9oH+v663htMvrfq/+0+72e0NCl2 0me8KRVse6g7jtPu3/A3h61m2rg+MC1ZInYq+aYvdM8RbZWwTroHJE6ia2bD+8H7ov QbGIc9/InGG32RtlxwU3tuuBiX43O8xyCIzfqBOM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "=?UTF-8?q?Ernesto=20A . =20Fern=C3=A1ndez?=" , Christoph Hellwig , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 08/62] hfsplus: prevent btree data loss on root split Date: Mon, 26 Nov 2018 11:50:49 +0100 Message-Id: <20181126105051.630839670@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105050.592727680@linuxfoundation.org> References: <20181126105050.592727680@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 0a3021d4f5295aa073c7bf5c5e4de60a2e292578 ] Creating, renaming or deleting a file may cause catalog corruption and data loss. This bug is randomly triggered by xfstests generic/027, but here is a faster reproducer: truncate -s 50M fs.iso mkfs.hfsplus fs.iso mount fs.iso /mnt i=100 while [ $i -le 150 ]; do touch /mnt/$i &>/dev/null ((++i)) done i=100 while [ $i -le 150 ]; do mv /mnt/$i /mnt/$(perl -e "print $i x82") &>/dev/null ((++i)) done umount /mnt fsck.hfsplus -n fs.iso The bug is triggered whenever hfs_brec_update_parent() needs to split the root node. The height of the btree is not increased, which leaves the new node orphaned and its records lost. Link: http://lkml.kernel.org/r/26d882184fc43043a810114258f45277752186c7.1535682461.git.ernesto.mnd.fernandez@gmail.com Signed-off-by: Ernesto A. Fernández Cc: Christoph Hellwig Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/hfsplus/brec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c index 808f4d8c859c..d3f36982f685 100644 --- a/fs/hfsplus/brec.c +++ b/fs/hfsplus/brec.c @@ -428,6 +428,10 @@ skip: if (new_node) { __be32 cnid; + if (!new_node->parent) { + hfs_btree_inc_height(tree); + new_node->parent = tree->root; + } fd->bnode = hfs_bnode_find(tree, new_node->parent); /* create index key and entry */ hfs_bnode_read_key(new_node, fd->search_key, 14); -- 2.17.1