Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5646177imu; Mon, 26 Nov 2018 03:28:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uxl/5D57NA4WRMZAo8Zi+n78n5CNT8BGPk3/QuZeZKifk63QFId17J9ito1J+m+igSsFUY X-Received: by 2002:a63:7f4f:: with SMTP id p15mr24610062pgn.296.1543231723217; Mon, 26 Nov 2018 03:28:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543231723; cv=none; d=google.com; s=arc-20160816; b=mmV2DFJogGiXLh2w2gDQ2qR6rXPZnMmjAWlGPdZ2ymGYZJCsM50znC6Uw1yFUegNhe AW9BG+0mTLd1KMuP7/VDF52tNz/+MPeZlu8r7B5oeKyoicGzPtHdr7asxx7LHOIEiUXr qn98W/HapAGhNYomn18wgApdZVlWaVg5z/A9Rg4Tj2hjdMLc8Uhl7OclvsAFXWbhLXj4 gvbFkNgg0DeSPyBVAktB0EAXV2A152sXGqsDlh2mGLilDa5lZRIhamX4MYKPHLX1EzJ9 8f+RGBcpg5aF9YXgU6gkbmGkxbWXkFxEcmAxIiYPKUmVBsP3cEJlucpVlyOgOvYsNk6d 0WPg== 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=GgFqEXVWoGZeXzOPDQZyTEG1NTcOskFH2JYmC6EvTqg=; b=A9h57tK5koYQzTUDM3RrNlkGclF03Vo6IaTSqhbAQ6cd5ikEf+dxOlr+shDwxsR6x7 sEQ7S+ZTEPL0iYhHCAcVpFleLp10if3EJ/mAY5HrJZrorFbQzM0afqhAGzpt/LnjzoG7 VxziZDdQMCybQ9OojD/6TI4z38HT9SiVFBHrbg06z33zpRnA+Z/A2wpqB8DOhUR+qpZE rF/bEIIEiVYdlPTCLiB5ceu7+dtQ8rqq5+xjSo/YOD8eNkvAtoX2Q4LsfECNcbCXF/25 wszCdYNTk0QRXNUmpLkaM69ZdCAg7cPqwR87iQ5T0GElOxa6CfCl32NPxKnk5xjimRNZ 9Rug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BWqwvItv; 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 c7si27853plz.118.2018.11.26.03.28.17; Mon, 26 Nov 2018 03:28:43 -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=BWqwvItv; 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 S1726996AbeKZVrY (ORCPT + 99 others); Mon, 26 Nov 2018 16:47:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:55562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726138AbeKZVrY (ORCPT ); Mon, 26 Nov 2018 16:47:24 -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 A711920817; Mon, 26 Nov 2018 10:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543229620; bh=QcxgaZI8Q/cNWh2Xq1XWK2y8QOte/9JbCCWp3CiLJF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BWqwvItvutSY+rsaqbOhcjRg3xVi0h9Kbh0P0l1iPjsUjGAw64VT4zg4mq5etaXln PyhhBMOs2W29Y3RqkuwtBuQsD4ZG+sWgED+4n7vboaGYFvV82ssasuHkikLK+ZyMKw empwnIJmvIaRICauVsCuwQE8wK//lHzaaBX6rneQ= 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 3.18 03/24] hfs: prevent btree data loss on root split Date: Mon, 26 Nov 2018 11:50:57 +0100 Message-Id: <20181126105030.256797058@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105029.790599475@linuxfoundation.org> References: <20181126105029.790599475@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 3.18-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