Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5630877imu; Mon, 26 Nov 2018 03:15:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/WjKVVT2YhzbTeeYv0xO2zGR9S4JEofFRp+BVEDKqVBegkQWK6i9/bvLvDKLCwyQ2kMDF3V X-Received: by 2002:a17:902:930b:: with SMTP id bc11mr27792040plb.17.1543230903515; Mon, 26 Nov 2018 03:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543230903; cv=none; d=google.com; s=arc-20160816; b=02fHL2mZy8CFMe5XbkjxsydociaCjZwaHKTOwMHAHqrMNrWRW0t1xz/4XoHRSJjcPE mmnbql2MFFvDaCpnDxCMZVxK8Klw15h7Q5YjCKCFbhxftlvx+pjR8fW9hZyVxAZdmM7R OiELIVuedsz440PwiPQcKkKhvdY1sEE+HqPN+P6YT/7MryW2jlzKQWLrgH4KZOIOnehW xsFPIkRHGS5WW5B9t9v4lhmdxmaOZ4c15HNiofdaCgI6bx0WLK2JDh7DThpxmn6bQRME M8QY/vf2YKtG+uIi+IILc0HFEe6exIvrxhLC0UaElYysNDF7BWiLnXXSeK0k8EuGWGSA OAcQ== 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=8SI7E6BwFPIUxXv65zRUYfjkflFW5dOOWfaqjK12QhQ=; b=Q0yLlfoPMzW8u2Gb7NlPiRPgsYmE9YqVkxjHWKK1EmMmzpBg+6g7GUhtY+bZnQg3kf cAB4oXpD+0X4cdqN96fMb9G1yhAGwIBi8/puyc2TYWdsZWEWo6Lyf11wEf4nUMJQpjrc /Gbu5NZlynLrqlacm86LxsauUIDkvESyZSaaddRq6lwwMhk4Yl80G65WXLXEyhWYVc0F cYIC7ShJXpYny6Z82M7PRY4/6xqAU+BlqvayIHaEJID7CW3LqGz+PS6u3zrDhLoVo+QK 8M5f28pNCRjYr8YEux/v+Vjy3cSCw5vI+28+cxAZAdruNApMXNGFa9pD3V329SFT1rzK OaNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="xy4KT/V6"; 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 z20si157pgv.159.2018.11.26.03.14.48; Mon, 26 Nov 2018 03:15:03 -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="xy4KT/V6"; 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 S1730298AbeKZVzh (ORCPT + 99 others); Mon, 26 Nov 2018 16:55:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:38308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbeKZVzg (ORCPT ); Mon, 26 Nov 2018 16:55:36 -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 050F121104; Mon, 26 Nov 2018 11:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543230111; bh=W3UiworFngjpMu7FdNZMKzPQHAJsNR/354E8ByF7Wc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xy4KT/V6fwmdsC61j9PgVXm35UhuYfsEIPlW+fB9cA8E//liRJcoATChhfQGkFmuU p269j8EIc+ektKxmaYbLc60b0oBdhJczLpdy+zThDjcodPeJ8T9VJtVn99KlZjx11W KUhblfgj5u6VGgUeiGDhDpoDtRbTYET+wge9O8LI= 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.19 013/118] hfs: prevent btree data loss on root split Date: Mon, 26 Nov 2018 11:50:07 +0100 Message-Id: <20181126105100.366867733@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105059.832485122@linuxfoundation.org> References: <20181126105059.832485122@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.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit d057c036672f33d43a5f7344acbb08cf3a8a0c09 ] This 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. It is not possible for this to happen on a valid hfs filesystem because the index nodes have fixed length keys. For reasons I ignore, the hfs module does have support for a number of hfsplus features. A corrupt btree header may report variable length keys and trigger this bug, so it's better to fix it. Link: http://lkml.kernel.org/r/9750b1415685c4adca10766895f6d5ef12babdb0.1535682463.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/hfs/brec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c index 9a8772465a90..da25c49203cc 100644 --- a/fs/hfs/brec.c +++ b/fs/hfs/brec.c @@ -425,6 +425,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