From patchwork Fri Aug 31 03:58:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ernesto_A=2E_Fern=C3=A1ndez?= X-Patchwork-Id: 10583079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5036514BD for ; Fri, 31 Aug 2018 03:58:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FC572BD3F for ; Fri, 31 Aug 2018 03:58:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32B432BD94; Fri, 31 Aug 2018 03:58:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF4792BD3F for ; Fri, 31 Aug 2018 03:58:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727139AbeHaIDt (ORCPT ); Fri, 31 Aug 2018 04:03:49 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:46800 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726974AbeHaIDs (ORCPT ); Fri, 31 Aug 2018 04:03:48 -0400 Received: by mail-qt0-f196.google.com with SMTP id d4-v6so13160755qtn.13 for ; Thu, 30 Aug 2018 20:58:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding; bh=yQPyyF/ucUtxOonlryyUA9MvB5i9ABogHw+FF7xuVls=; b=h0tmfGmnwy7+Kbe29S0fD2XWn7bix7KlZ07jlV27D4W++P/eMWETcDdvSo5qrW8n31 Lo1pvbeNW1QdXRhMMoAhAUgXeU9e7vcXEp+aE33ta0i7sgVl//Kq5Z3opq3pe/2uVAYn h9gSwyAZQvMvKf4NKSazYIlm/IGeaWS/HyHx7Dix3OSFBPH9oyJbjNf7FdBc8JzMR62n T7iNW0P9RXuEEBEWmAWwR1Rta9yzWVrlED2YRObXYq6oAdB2HDdJ5+gZDRAGKK3MdZ/p wTIRfcZG/ZtFkERizFMRw3bE5tKx6mwc8vCtH24ZvT3n9Zl6/564VsMdi3Bl0h/3G06C Jiag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding; bh=yQPyyF/ucUtxOonlryyUA9MvB5i9ABogHw+FF7xuVls=; b=ALbsmnz2WoFgedzxAbPejvKAh3O84HYzy+J+wBAVhQ0cACiQTgFlwLzTuZV/Yp97An PaGretkHVnDIDQMbPhfOppiwZKgFP2xUyAFfn2mZwoNpWiQfcZRhfuvmegHXoEp2FhQL pjcljdKv0Edvt7edVy5d0J/+X/Amy4IlFXYtkZsEBcwH1csQC9Q0iPdI+I70dYRNo6Ns XTXj/WwQElM+6ARY89f1KJrJxRhY3p8ujR2Im97/DHW2pF/GcwJO9KxIqPZXTL6WFsHJ wndfDDjgPWeAl+qgdqCVe1wvq+OfUzs4ZuJuzannQGc1qtENnzmAEv3+f9ZRCQjdzcn8 FGtQ== X-Gm-Message-State: APzg51AzMnoXFrFys42yRKt8iH0YO7Bcq+dFIkPct2xIigJi8wvk3m3J fZLT8uXb7rjr/s+o7TIy277dcddH X-Google-Smtp-Source: ANB0VdYeCJipMFXHkIZTQHtjfVK15ijQCKGdUQLEFa7Qidoa7ChtqqwyqNCBVxWo+1FmlcAYeBt9ng== X-Received: by 2002:ac8:392e:: with SMTP id s43-v6mr14318512qtb.68.1535687904768; Thu, 30 Aug 2018 20:58:24 -0700 (PDT) Received: from eaf ([181.47.179.0]) by smtp.gmail.com with ESMTPSA id b134-v6sm5350530qka.63.2018.08.30.20.58.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Aug 2018 20:58:24 -0700 (PDT) Date: Fri, 31 Aug 2018 00:58:19 -0300 From: Ernesto =?utf-8?q?A=2E_Fern=C3=A1ndez?= To: linux-fsdevel@vger.kernel.org Cc: Andrew Morton Subject: [PATCH 1/6] hfsplus: prevent btree data loss on root split Message-ID: <26d882184fc43043a810114258f45277752186c7.1535682461.git.ernesto.mnd.fernandez@gmail.com> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Ernesto A. Fernández --- fs/hfsplus/brec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c index ed8eacb34452..aa17a392b414 100644 --- a/fs/hfsplus/brec.c +++ b/fs/hfsplus/brec.c @@ -429,6 +429,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);