Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4967193imu; Mon, 12 Nov 2018 21:58:17 -0800 (PST) X-Google-Smtp-Source: AJdET5ctCSnuxY43eX5oK2OFUJHHUP9SeqHHO4bV1tcrAsKabpvOV3Na4F8K5UOTcKjYPtqx4aKh X-Received: by 2002:a63:5ec6:: with SMTP id s189mr3412598pgb.357.1542088697733; Mon, 12 Nov 2018 21:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088697; cv=none; d=google.com; s=arc-20160816; b=bP8THRm3qwfDRXYLrSS9CfroQayHJlN1hSQ4IMJjd2fWzCUcsh+wUkvsSAN4EFh25n DIn5JyC8T61URdKTbjZJxZ8Ullunet9kubMcn0pDpq18+rJQtiqp90TfDpH+LC5HjuSM 3ykoBa5y6qaQ/XwEAsn7DSM/IPSSI9n4An0wXM15c7MkCCVDsLmkd8YoTHM4x0E22i/F R8ucyAOe0M9cVZZjVysJgJba2sLdY3dBfoqsXPmbVV6O9N3S/G1U3NvO7puknl9NGWa9 ufX2WlPIWjYUMOC/VtxgpiJCovHmMQXi6R4NmP/V/0cLn+74AmcHavjx1n8vuFTutpoE STBA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zh+YrSbF1gdYoXyV7ZFEpWxr8fjfEjh00Aow32+Q3Nk=; b=ahk9/ksOOgw1OhUfsl8Jo3OqZvcHBMJJHNBYJNeK0k6Cvk0wyENsIL22JfzYGyjQGL DWm5DcfSVHpPVAmlyUw8cbxyw1FJ3eoIKiX1BzIIqyRdO451hrwfgpb/vlFSVRHz/HGU 3f9NyEMvM0KndpSchaEKpRs/MxI9eAjLDzD5MM/10um9Ydwh9MIZZbZlTymdPm3DlqFE mCqX4V8l6aeIOa6wdR1XFsCmF7YNVWqAnCEt9pH4IHBlr4rbYdRApAaby3icljBUA0P5 VRF+CdERzgUOcs531rNCIjhHiSAcSrVGyY/3IwzFCSRC1uG65n6HssU94OHbw9vniyBM 6ydw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B4FKuxfL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10-v6si15497990plh.416.2018.11.12.21.58.02; Mon, 12 Nov 2018 21:58:17 -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=B4FKuxfL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732895AbeKMPtC (ORCPT + 99 others); Tue, 13 Nov 2018 10:49:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:35918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732881AbeKMPtB (ORCPT ); Tue, 13 Nov 2018 10:49:01 -0500 Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B5C3322507; Tue, 13 Nov 2018 05:52:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088353; bh=X7Yg/5GxyWLymmEiEZv2G/hs42UCd4CSAmlWJxJR2/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B4FKuxfLvXHFxi7mSwEkUkI7TyAQcdSPm9Tx+oQvJhaHGCCdReWfvThd2WHb8Wpym cJEHXyPccKCW07V/haOh7VnkDBXtX2QHZgrODkxIxb88eSpf6ScO42eU0IiUN+KVEC BinWAn2xiSfYFcSn422PXoXoIYGgOMgMHgAjKhNs= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= , Christoph Hellwig , Andrew Morton , Linus Torvalds , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 06/17] hfsplus: prevent btree data loss on root split Date: Tue, 13 Nov 2018 00:52:12 -0500 Message-Id: <20181113055223.79060-6-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113055223.79060-1-sashal@kernel.org> References: <20181113055223.79060-1-sashal@kernel.org> 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: Ernesto A. Fernández [ 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 @@ static int hfs_brec_update_parent(struct hfs_find_data *fd) 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