Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5612019imu; Mon, 26 Nov 2018 03:00:36 -0800 (PST) X-Google-Smtp-Source: AJdET5c4gOKf4wL7ezSkp2s3cqtCv8JEs/gvjhDaYKm4BYT03S9yDHsLogqvJ7pQjz38emClqfQN X-Received: by 2002:aa7:85d7:: with SMTP id z23mr28292990pfn.205.1543230035939; Mon, 26 Nov 2018 03:00:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543230035; cv=none; d=google.com; s=arc-20160816; b=PBkLayL7gd5FlJ1ntqCsdei23HLWBDtFoo5l3VnXg/AIlSob/xB1dn8Dkl391Rq74D MFMa5J6zedgM29CHoEUAiS4Kc4REWB79Q7TtbhbpP0FTZaq6MO8jRUF2PV1ru1t+OwT7 NEW4G4Mrm2ZJQ2NFLtrmWjzz6FhAFAE3j3PoF/Ke8qxNKrAn0b0LpoqGTEtubWYypS/P 3NawdU3PyJSysPC3McD3CqwbSe5T6gyqClq4UFoOkfho0c7FY2LqwFydMd3w1zzeTZm3 taWUJT54relnWOFmumH00dERlbviiHeNxQArJFuZ00VWZdVGM6b5P9JiVhL5XZ/gxLjA sOFg== 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=VHXLOkMTlaVmEwrH/Pqsdz6ouxz84IRwrr2zHOSGHtU=; b=Va3fK1sqQrU2G9x55IgeMcBPtMf2fXRqgB30gL/9rP2LWrh9DtbEEZ6x/OnPnMBhkf UkLpCbE9x0rqjxH1YxMOKQeOHN5g3BQsAwaNhgARSi84bdrvH5cp23gOqKNxGs1HP0B5 iue/yfCDDkewc7jFVYAs9wz9i7ahqJVwmejpHnoKgHhyKI6Ns0ZNEblybzZb1ixCsmTw 3LA0PpN//hd73EZA/a21ws/pKQH2swzNIVTYppg4AH1E1qRy3QXSxDVwTy3rwSRwgMot cDNNrwjxLMvTIg7McZkESbyw+IqZ0X+Af8DqqtZ7aJg3S10hNES6uiXiqmVBgzDBEO9r 3KGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aziKDl5J; 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 e8si51381433pgn.325.2018.11.26.03.00.20; Mon, 26 Nov 2018 03:00:35 -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=aziKDl5J; 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 S1728993AbeKZVva (ORCPT + 99 others); Mon, 26 Nov 2018 16:51:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:60910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbeKZVv3 (ORCPT ); Mon, 26 Nov 2018 16:51:29 -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 668752089F; Mon, 26 Nov 2018 10:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543229864; bh=7Hd6Dt3DmAdCdfbq7TCO/RreanY7vlWNxc6udsB/ETw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aziKDl5J/RRl7WBLiYLvmwTOAtvM+l8PHovLOtKucMFCO/nAT/3C4njJBtRCoT65k 0I6SZXAuutSBdZSg4ZMAjAtf78X4hQiIfui9CrKFhaqSs+lViTLKnRgtFNBIvap+Tj BarPxoxMpexiG6X+FlJtEdjItXlqWJxEs6e8Cqbc= 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.9 03/46] hfs: prevent btree data loss on root split Date: Mon, 26 Nov 2018 11:50:52 +0100 Message-Id: <20181126105045.966457422@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105045.447291262@linuxfoundation.org> References: <20181126105045.447291262@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.9-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 2a6f3c67cb3f..2e713673df42 100644 --- a/fs/hfs/brec.c +++ b/fs/hfs/brec.c @@ -424,6 +424,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