Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1727376ybz; Sat, 18 Apr 2020 07:16:21 -0700 (PDT) X-Google-Smtp-Source: APiQypLb5y28L042EPLoCgTmQrsoi0m5bsNQ8EghlxjHnAx/yPuF5/LTNYBQ6VMGZOFx1aOl0JF6 X-Received: by 2002:a17:906:4548:: with SMTP id s8mr7749714ejq.349.1587219381592; Sat, 18 Apr 2020 07:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587219381; cv=none; d=google.com; s=arc-20160816; b=BtGoV3Vf9Py2NJEal+Gyy1c6gE0jJrJvOQcWK29DdoXkcs9JbTpBZBDOrMmyNifB68 L+Li6eN6t4NKjFwUZ4KnyZyV+2aJ5M9sts5ABZxMxTK3+o49hx67y0fzDvGK5dS9+VCU sUMWnYQEgndZmKA4X+Pdt6kiPpmIxNoP0X0hly5Bm7WNZIbZDHZHDILvbZU7h1P8u3g7 Hlc2DgPkLwnOkd2dH97DliM/E69z8/6Uzo0xXtaddO9msdEzfzUOXj6Ik/gksTdzXzfH 5UXgjTb18Dg0ZYemKTAB+YZ8YPZQKRnNtmDgN4NnlnbOTCQKf3Y1X17dBJ/Ic/ZAPpzj G+gg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=no/5hEywtrjRzLPTvCqRn55daEzEM4cHZc3NOlRgfBg=; b=C4SBBt5482KTS2MDg//RwVB3ZH3jB/mMFTYKKMuodHnHhLSKixaVI3eK27njDl8k8j ImyreqcCDndsyxSL5V4Kh8p2McWNyM/xyQlO7JKTGIxfRo+GScHcw1Q9B8BFE5+hLvZL j54gltOnOAB7o/U6UnVM4fYV7bUMxn1ag9gQfKzeR7LGNHM1AYegAjRc3Fx1Od5YeSL1 WzjH88BfVtTCS870xRNIpLeiR/15CgJYETOJD+ilBaZ2v0MbJsyb+wYiE/gltZZQqGlf hUd0cI0PeFrGFwvf4QQsoqTWX5ktGDhhWa/L9DeLegYBPlGBnjc1C4XREbZ5rfXbBSuN VP6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iSd1kCmR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p18si16480085ejl.98.2020.04.18.07.15.59; Sat, 18 Apr 2020 07:16:21 -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=iSd1kCmR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726618AbgDROMG (ORCPT + 99 others); Sat, 18 Apr 2020 10:12:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:38288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbgDROKR (ORCPT ); Sat, 18 Apr 2020 10:10:17 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 88AE122286; Sat, 18 Apr 2020 14:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587219016; bh=ePMzA8G+GUVMHaLdyeNb6FpdBQ2qidUTn/hjMaGktEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iSd1kCmRoyBZC/fp92VVC1p6kmlzCOEMdUYrfSSyia1JXdyQuUH2Yal9RLocWVlaj puoSOMFrZaSsjCdF1JYSzLn2vqKAvuKf80wyMjEeXrdsXjj8VlhyAsvH1j+1UQsjrc Eo0JkH2HlnzIwu7RcmAb7ziAaRLckNcJFZ21+7a4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Simon Gander , Andrew Morton , Anton Altaparmakov , Linus Torvalds , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.5 52/75] hfsplus: fix crash and filesystem corruption when deleting files Date: Sat, 18 Apr 2020 10:08:47 -0400 Message-Id: <20200418140910.8280-52-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200418140910.8280-1-sashal@kernel.org> References: <20200418140910.8280-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit 25efb2ffdf991177e740b2f63e92b4ec7d310a92 ] 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: Sasha Levin --- fs/hfsplus/attributes.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c index e6d554476db41..eeebe80c6be4a 100644 --- a/fs/hfsplus/attributes.c +++ b/fs/hfsplus/attributes.c @@ -292,6 +292,10 @@ static int __hfsplus_delete_attr(struct inode *inode, u32 cnid, 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; -- 2.20.1