From: Viacheslav Dubeyko <slava@dubeyko.com>
To: glaubitz@physik.fu-berlin.de, frank.li@vivo.com, hch@lst.de
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
vdubeyko@coreweave.com, brauner@kernel.org,
linux-xfs@vger.kernel.org, Viacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH v5 4/5] hfsplus: return -EIO from hfsplus_map_extent() if no extent covers the block
Date: Tue, 17 Nov 2026 16:48:43 -0800 [thread overview]
Message-ID: <20261118004844.3849979-5-slava@dubeyko.com> (raw)
In-Reply-To: <20261118004844.3849979-1-slava@dubeyko.com>
hfsplus_ext_find_block() walks one 8-entry extent record and returns
the number of contiguous allocation blocks starting at the requested
offset. If the offset lies beyond all entries of the record, it sets
*dblock to 0 and returns 0. hfsplus_map_extent() ignores this and
returns success, so the caller gets allocation block 0 as the mapping.
This can only happen on a corrupted volume, for example when the
extents overflow b-tree lacks a record for a range that is below
alloc_blocks, or when the found record does not cover the requested
block. THe hfsplus_get_block() then maps the file block to allocation
block 0, which holds the boot blocks and the volume header. A read
returns that metadata as file data, and writeback of a dirty page
of such a file overwrites the volume header.
Return -EIO from hfsplus_map_extent() when hfsplus_ext_find_block()
finds no extent, for both the fork's first extents and the cached
extent record. The iomap conversion later in this series relies on
this too: __hfsplus_iomap_begin() derives the mapping length from
max_blocks, and a zero max_blocks would produce an invalid zero-length
mapping instead of an error.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
cc: Yangtao Li <frank.li@vivo.com>
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
---
fs/hfsplus/extents.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
index cdb337ba3924..bb5a1508498d 100644
--- a/fs/hfsplus/extents.c
+++ b/fs/hfsplus/extents.c
@@ -67,7 +67,7 @@ static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off,
}
off -= count;
}
- /* panic? */
+ /* 'off' lies beyond this extent record; callers treat 0 as an error */
*dblock = 0;
return 0;
}
@@ -273,6 +273,8 @@ int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,
*max_blocks = hfsplus_ext_find_block(hip->first_extents,
ablock,
dblock);
+ if (!*max_blocks)
+ return -EIO;
return 0;
}
@@ -300,6 +302,9 @@ int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,
if (was_dirty)
mark_inode_dirty(inode);
+ if (!*max_blocks)
+ return -EIO;
+
return 0;
}
--
2.53.0
next prev parent reply other threads:[~2026-11-18 0:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 0:48 [PATCH v5 0/5] hfsplus: convert regular file I/O to iomap Viacheslav Dubeyko
2026-11-18 0:48 ` [PATCH v5 1/5] iomap: add iomap_dio_end_io() helper Viacheslav Dubeyko
2026-11-18 0:48 ` [PATCH v5 2/5] hfsplus: move file related operations to file.c Viacheslav Dubeyko
2026-11-18 0:48 ` [PATCH v5 3/5] hfsplus: rework hfsplus_get_block() logic Viacheslav Dubeyko
2026-11-18 0:48 ` Viacheslav Dubeyko [this message]
2026-11-18 0:48 ` [PATCH v5 5/5] hfsplus: convert regular file I/O to iomap Viacheslav Dubeyko
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=20261118004844.3849979-5-slava@dubeyko.com \
--to=slava@dubeyko.com \
--cc=brauner@kernel.org \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=vdubeyko@coreweave.com \
/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
all inboxes | Powered by JetHome®