Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5609203imu; Mon, 26 Nov 2018 02:58:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/U50WTrPsELPtnERGIPEZKii17ulD2qZzBW4EqZ+Z30RNT97UyowR2xTbYDDOIDq8iW1GD3 X-Received: by 2002:a63:ec4b:: with SMTP id r11mr23783327pgj.44.1543229881089; Mon, 26 Nov 2018 02:58:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543229881; cv=none; d=google.com; s=arc-20160816; b=SqswmUBrW5QG/9AyGVqqo+xz76KYRFMzXQXiVABpBDGn1aLc1uYFC/WspnSQ/xswGJ dIVPNuyzOwKPeB91vm4q+hhL2QnsyA17K5r4zFzn+eY/3TDp+pQMh/MXgSlBFDv4iKlz sI1jktTk+wbnKQijpUjdX6TGcCQ94lOwYQFrhqagN4bmyqAq0HS/I4T9vqFwwS2teD/j nnaRwFsVcKVSvuxVrdsQGSDFBp8R7yNwYbNmuceWUUpPYaZyLfKq3qolxS89MeOhdQcb huE3wWjALgm3a+GlOi5u8K1ubsOrjfz2ymQnzckjrm3rRzGPG/x05mVAK4H+94fRaGqR QmiA== 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=zS+XfA7LRddU8Ag1p2UQxrOKsLY6aQwf7rjshwM4Jdc=; b=TRjO3mHGs11Ilhihp+yrRAu0DZ2YKWr4t5E3njleVZ1AQNL2dbp9Z2abnF/t9zOAnT J2fae5gJjav9UZ2YrCzs0eIIRc8GOcJP/gb00feVr3ylXH3ItyBLhdDlfl2eGUtx5fmh k2IY9ni9WAT6HFPhzvOCIxclClsyLDapH40qmYIED0cPXMgM2g5sOdcs73A1j9zmCEPF y9OV+L9OSNxbmAF8DSyEapbsKvBxUfNlW5Bp67Hed6q/5J0c4XCdI15YADy4pEY5DsrR t/mC34doOS+av3WX3D8yDushipPljDkBwXksT/skiZy908GRE/jkUIRmapxAqtl06Hok xGHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YIYUlYWZ; 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 b65si60462599pgc.259.2018.11.26.02.57.46; Mon, 26 Nov 2018 02:58:01 -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=YIYUlYWZ; 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 S1727785AbeKZVsw (ORCPT + 99 others); Mon, 26 Nov 2018 16:48:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:57592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbeKZVsv (ORCPT ); Mon, 26 Nov 2018 16:48:51 -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 1D3582147D; Mon, 26 Nov 2018 10:55:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543229707; bh=4yJBc3b7W9cE62JAuvhhHZeOGSNIe4as5cRxLSAkeXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YIYUlYWZDIBqLvKZNyymGQN0NEn6eXOTZaMnVrAkT0mPvnre6KcgCbUf+kUuG80E1 CUKCA0R1CFlFJPUrFP2TxShjs09VvUCrrJuoDc5L8DXtedzQANM//C1HL7jx/48pnm HbOYAPdJv5Fa0zkJn/1MmMXdGYuBKs68gvQp4lNc= 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.4 40/70] hfsplus: prevent btree data loss on root split Date: Mon, 26 Nov 2018 11:50:55 +0100 Message-Id: <20181126105050.582972382@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105046.722096341@linuxfoundation.org> References: <20181126105046.722096341@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.4-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 754fdf8c6356..1002a0c08319 100644 --- a/fs/hfsplus/brec.c +++ b/fs/hfsplus/brec.c @@ -427,6 +427,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