Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5609188imu; Mon, 26 Nov 2018 02:58:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/WocWR1EEeRvkcR9xQZzqZ3x6gl51JGfvyn3KJv27qA61TKSApMQtpGGDMZGrqWpbOhl71F X-Received: by 2002:a17:902:820d:: with SMTP id x13mr27681630pln.229.1543229880232; Mon, 26 Nov 2018 02:58:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543229880; cv=none; d=google.com; s=arc-20160816; b=w9OUKhGo/zHLZClt4xGNe3r47aWFc3BfiX2mb192OtdOBgseciX9ovhn/QHStZLKJT QB2dDsGJWBG5RDvIfw/diV2V4CQYPsHfunwNiLFCZnpgoMgwACqHtEAkz47hNsK6Dw2w C4/N7p8bMaYH4z2Jmb8FZC3MTh8pfyhWrCSxhoqhmcMg/AmNzWhMS8e39NWiDX3BaPWX m1x4svLTVlXkz878crPE1T4fcbrUkkf5gWyz6F/vIZzSDxXQ/jztnlKVp+aNq6VaBL/1 o2XCKCOeMqqhkFJYghzc9HJSS306Bgy3T4XAm95lhsjkKR/enmh8RK15YyewmLFlcGGh xkbA== 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=cABdfzIFPqJ7iDsZ0gvyJJYuNhN8bpExWYt6B8f8E+0=; b=qASsZYX/e1bc8E86eHJKsw94ohaFptwIzYxY/ge5XFQarnlesRfNVB0zh9rByHvg41 aZwl+9HeF7uElsMfM5a9wh6h6RMUW9EutwdQ/oEdN5XSWtS6xAsH821FYmdh007BrBlg p83cyprrgEuRgP41HWIQgOg27/R9EKiTlckr27UEiHovCUTgYxARwgP4g8xG0gdOHIMP sxk8WQOHVL5tjf59/g6IwHUFpLMARxisj19Hrpt/3UfOESdtmgsrgV+Oo0NQ+Zls9SIv dMtuScPR0qqaKGifei4KFNgu5l77Kx9d0hdelENuT2v0Jx2ot6yB++N1jrhPS2osTNAg pByA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VyhyDp3/"; 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 l194si63676877pga.594.2018.11.26.02.57.45; Mon, 26 Nov 2018 02:58:00 -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="VyhyDp3/"; 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 S1727762AbeKZVst (ORCPT + 99 others); Mon, 26 Nov 2018 16:48:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:57528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbeKZVst (ORCPT ); Mon, 26 Nov 2018 16:48:49 -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 8815E21473; Mon, 26 Nov 2018 10:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543229705; bh=pSs6nqFMDjbrfbd+pgL3mnyVu2HASlaOMGB8wPg7/mo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VyhyDp3/tjzyO8cfD6rJouCMfC/OPwuxnFOfiMY0MunMF6mn/xdjMjfJ8OduaS+Pw V3ntKoynI7GG/U4CaIR8H1ziJhESLVhCiwYrexG+CwzIaEykjGgK3z7DIr6tCQl3S+ yK8flHQLpX2iDGVPMoetJGmjF94mcHTQdlK4N8A4= 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 39/70] hfs: prevent btree data loss on root split Date: Mon, 26 Nov 2018 11:50:54 +0100 Message-Id: <20181126105050.495229074@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 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