From patchwork Sun Jun 28 01:39:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hin-Tak Leung X-Patchwork-Id: 6685571 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 371B6C05AC for ; Sun, 28 Jun 2015 01:39:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 341E720749 for ; Sun, 28 Jun 2015 01:39:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A43F20748 for ; Sun, 28 Jun 2015 01:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752127AbbF1Bjt (ORCPT ); Sat, 27 Jun 2015 21:39:49 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:35292 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751712AbbF1Bjp (ORCPT ); Sat, 27 Jun 2015 21:39:45 -0400 Received: by wiga1 with SMTP id a1so44510741wig.0 for ; Sat, 27 Jun 2015 18:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UbxJZreyjvtEx/5oYIePprwdBaHqKIeil27cxNH/aJk=; b=Ii7nO2hWKk+In3ecEsfs2pg9+0ZRcc8d6HHZh/HszBrbXL5EOGVllfqlaZxsnGhXC2 oEkqqNBlDdKQ+JVbxqoaCLMF5auRWpsBRu2qzypdziSSQN6t1qCeImQE1DgmC0/BP9bb dA743VetwH9okbtFxwyOOVGeUrFtVeZSt9TVzoPL2wTuS7XmYDyIgYM+TGRTBmg+XWkZ ZpN0EAmvctjm98JlOdeYKPWqwu9iToNocvKCxWxre09uEQzTR0hWjkHi0SPohV9Ejy4o qmoMyec0uhYr8yCKobWK/DTGSkDqPBsKBocxBMgqUhQsdr0Ybw2jc1EOwToVcgUo43Xa ibqQ== X-Received: by 10.180.8.41 with SMTP id o9mr9947568wia.83.1435455584369; Sat, 27 Jun 2015 18:39:44 -0700 (PDT) Received: from localhost.localdomain.localdomain (cpc2-cmbg17-2-0-cust389.5-4.cable.virginm.net. [86.30.137.134]) by mx.google.com with ESMTPSA id di9sm5293787wib.16.2015.06.27.18.39.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Jun 2015 18:39:43 -0700 (PDT) From: Hin-Tak Leung X-Google-Original-From: Hin-Tak Leung To: linux-fsdevel@vger.kernel.org Cc: Hin-Tak Leung , Sergei Antonov , Joe Perches , Al Viro , Christoph Hellwig , Andrew Morton Subject: [PATCH] hfs: fix B-tree corruption after insertion at position 0 Date: Sun, 28 Jun 2015 02:39:30 +0100 Message-Id: <1435455570-8577-3-git-send-email-HinTak.Leung@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1435455570-8577-1-git-send-email-HinTak.Leung@gmail.com> References: <1435455570-8577-1-git-send-email-HinTak.Leung@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hin-Tak Leung Fix B-tree corruption when a new record is inserted at position 0 in the node in hfs_brec_insert(). This is an identical change to the corresponding hfs b-tree code to Sergei Antonov's "hfsplus: fix B-tree corruption after insertion at position 0", to keep similar code paths in the hfs and hfsplus drivers in sync, where appropriate. Signed-off-by: Hin-Tak Leung Cc: Sergei Antonov Cc: Joe Perches Reviewed-by: Vyacheslav Dubeyko Anton Altaparmakov Cc: Al Viro Cc: Christoph Hellwig Cc: Andrew Morton --- fs/hfs/brec.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c index 9f4ee7f..6fc766d 100644 --- a/fs/hfs/brec.c +++ b/fs/hfs/brec.c @@ -131,13 +131,16 @@ skip: hfs_bnode_write(node, entry, data_off + key_len, entry_len); hfs_bnode_dump(node); - if (new_node) { - /* update parent key if we inserted a key - * at the start of the first node - */ - if (!rec && new_node != node) - hfs_brec_update_parent(fd); + /* + * update parent key if we inserted a key + * at the start of the node and it is not the new node + */ + if (!rec && new_node != node) { + hfs_bnode_read_key(node, fd->search_key, data_off + size); + hfs_brec_update_parent(fd); + } + if (new_node) { hfs_bnode_put(fd->bnode); if (!new_node->parent) { hfs_btree_inc_height(tree); @@ -166,9 +169,6 @@ skip: goto again; } - if (!rec) - hfs_brec_update_parent(fd); - return 0; } @@ -366,6 +366,8 @@ again: if (IS_ERR(parent)) return PTR_ERR(parent); __hfs_brec_find(parent, fd); + if (fd->record < 0) + return -ENOENT; hfs_bnode_dump(parent); rec = fd->record;