From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Simon Gander <simon@tuxera.com>,
Andrew Morton <akpm@linux-foundation.org>,
Anton Altaparmakov <anton@tuxera.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Sasha Levin <sashal@kernel.org>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH AUTOSEL 4.4 16/19] hfsplus: fix crash and filesystem corruption when deleting files
Date: Sat, 18 Apr 2020 10:44:33 -0400 [thread overview]
Message-ID: <20200418144436.10818-16-sashal@kernel.org> (raw)
In-Reply-To: <20200418144436.10818-1-sashal@kernel.org>
From: Simon Gander <simon@tuxera.com>
[ 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 <simon@tuxera.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Anton Altaparmakov <anton@tuxera.com>
Cc: <stable@vger.kernel.org>
Link: http://lkml.kernel.org/r/20200327155541.1521-1-simon@tuxera.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/hfsplus/attributes.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c
index d7455ea702878..0c4548d8cd0ba 100644
--- a/fs/hfsplus/attributes.c
+++ b/fs/hfsplus/attributes.c
@@ -291,6 +291,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
next prev parent reply other threads:[~2020-04-18 14:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-18 14:44 [PATCH AUTOSEL 4.4 01/19] iommu/amd: Fix the configuration of GCR3 table root pointer Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 02/19] scsi: lpfc: Fix kasan slab-out-of-bounds error in lpfc_unreg_login Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 03/19] ceph: return ceph_mdsc_do_request() errors from __get_parent() Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 04/19] ceph: don't skip updating wanted caps when cap is stale Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 05/19] pwm: rcar: Fix late Runtime PM enablement Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 06/19] ASoC: dpcm: allow start or stop during pause for backend Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 07/19] scsi: iscsi: Report unbind session event when the target has been removed Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 08/19] ASoC: Intel: atom: Take the drv->lock mutex before calling sst_send_slot_map() Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 09/19] kernel/gcov/fs.c: gcov_seq_next() should increase position index Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 10/19] ipc/util.c: sysvipc_find_ipc() " Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 11/19] s390/cio: avoid duplicated 'ADD' uevents Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 12/19] pwm: renesas-tpu: Fix late Runtime PM enablement Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 13/19] pwm: bcm2835: Dynamically allocate base Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 14/19] iommu/vt-d: Silence RCU-list debugging warning in dmar_find_atsr() Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 15/19] ocfs2: no need try to truncate file beyond i_size Sasha Levin
2020-04-18 14:44 ` Sasha Levin [this message]
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 17/19] libata: Return correct status in sata_pmp_eh_recover_pm() when ATA_DFLAG_DETACH is set Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 18/19] ALSA: ice1724: Fix invalid access for enumerated ctl items Sasha Levin
2020-04-18 14:44 ` [PATCH AUTOSEL 4.4 19/19] ALSA: hda: Fix potential access overflow in beep helper Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200418144436.10818-16-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=anton@tuxera.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simon@tuxera.com \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).