Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp642284ybz; Wed, 22 Apr 2020 05:20:45 -0700 (PDT) X-Google-Smtp-Source: APiQypJq1b+3rmLu5sUWyhDMxc8W/gpKmahLj/9BEZBJYrK1eOwnfIhYt8ORJfOAB/jmT/iDO/0B X-Received: by 2002:a17:906:48ce:: with SMTP id d14mr24277248ejt.113.1587558045115; Wed, 22 Apr 2020 05:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587558045; cv=none; d=google.com; s=arc-20160816; b=1Kqc0nPBgm8jzlIfb2dyFTeORCO1fmxxn+nAlOYR543Y3Bz8P97/2xPqnR6kIR4c51 uMgPunnoEkfrHPEGWUkagPnwwsXapH1NLGJv3DjY6Iz5hSf2qS9aA/rf/p+g1s/tAAF6 0fkOLJ1rzpD9AxTqAKU5nfaIUA9tVtFae5UpB9fKv9S1rOIhIyn9FVtjk/ppQFZkJNdK gFKfWVr53mOAGwBWn7IMZjCQ4k+zKN9G4tynymcEhrMv/xSJVEgqCw6huhspfX2uPN8S 2DMyG+JRgzDuJc40QsXpeZNPUaNkVuRNnpPjcJloWQtHjHsFGCsHILdUSSugUyj5lVzW sTIw== 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=n0K/mUWu53HQ7o4Z46khMnSfJi7erThWnxO0YZhpftk=; b=JuHr/7cgfzgY9KckYN4TEGYmHwZM6us595FCMrJIDeq72maeKYC14jZ+OfLEAQfjQr Jdvh+JE0fmcnOsc5Aa6fuSPCuW+BuFyxVLw/iVyPzjvrVwVMFORdtexZffGJhG4Nstcv QIkAL7v/OHEdPq5X+eXenXau/eKjkRjWAEbtQCxBtA7X/7/tTWYoBnLn6rh+sb1uWyVH WB1Vtx7Jbe12qpwkh/hS6M0aBfmANaDqfBVj5I7YomonUi32tDO1CS6SVh1pyEqBaDXc O5UcJVb1IJhv/8/+owy3xenSXJF4JQN7EzbsGlullt+hUA46Cve4ly88lnJL2kdcFEFT M4iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lvn4vTwu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si3755746edn.181.2020.04.22.05.20.20; Wed, 22 Apr 2020 05:20:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lvn4vTwu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727901AbgDVKLj (ORCPT + 99 others); Wed, 22 Apr 2020 06:11:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43534 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729206AbgDVKLa (ORCPT ); Wed, 22 Apr 2020 06:11:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 AD28F2075A; Wed, 22 Apr 2020 10:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587550290; bh=SoVqO3bK3jHNnFnqoHbBV+IZFxZYUJeXCaLy+Ihncvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lvn4vTwuWvVK6NBiQcgDW1fIS0ss+l5+m9+aT8JMtNskukyhLe3q5y82XCLbOVEqY ADKKPxgZpWyHGskwOZQ/eQrhlaK1TYnPDCAeYAZdEZjfkuOxRo9wDVS+a9hD7CRntz yQXvSZsZj9eV6h27lvcXQJpe+vZjwEUKtejPeRKA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Simon Gander , Andrew Morton , Anton Altaparmakov , Linus Torvalds Subject: [PATCH 4.14 085/199] hfsplus: fix crash and filesystem corruption when deleting files Date: Wed, 22 Apr 2020 11:56:51 +0200 Message-Id: <20200422095106.605369560@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095057.806111593@linuxfoundation.org> References: <20200422095057.806111593@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Simon Gander commit 25efb2ffdf991177e740b2f63e92b4ec7d310a92 upstream. When removing files containing extended attributes, the hfsplus driver may remove the wrong entries from the attributes b-tree, causing major filesystem damage and in some cases even kernel crashes. To remove a file, all its extended attributes have to be removed as well. The driver does this by looking up all keys in the attributes b-tree with the cnid of the file. Each of these entries then gets deleted using the key used for searching, which doesn't contain the attribute's name when it should. Since the key doesn't contain the name, the deletion routine will not find the correct entry and instead remove the one in front of it. If parent nodes have to be modified, these become corrupt as well. This causes invalid links and unsorted entries that not even macOS's fsck_hfs is able to fix. To fix this, modify the search key before an entry is deleted from the attributes b-tree by copying the found entry's key into the search key, therefore ensuring that the correct entry gets removed from the tree. Signed-off-by: Simon Gander Signed-off-by: Andrew Morton Reviewed-by: Anton Altaparmakov Cc: Link: http://lkml.kernel.org/r/20200327155541.1521-1-simon@tuxera.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/hfsplus/attributes.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/hfsplus/attributes.c +++ b/fs/hfsplus/attributes.c @@ -292,6 +292,10 @@ static int __hfsplus_delete_attr(struct return -ENOENT; } + /* Avoid btree corruption */ + hfs_bnode_read(fd->bnode, fd->search_key, + fd->keyoffset, fd->keylength); + err = hfs_brec_remove(fd); if (err) return err;