hfsplus: fix timestamp wrapping and support timestamps after 2040
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest3 patches 0 repliesNew
- v33 patches 0 repliesSuperseded
- v23 patches 0 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 1 patch | 6 replies | Superseded |
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | hfsplus: fix timestamp wrapped issuefs/ fs/ fs/ +1 more | +22 | 0 replies | |
| 2/3 | hfsplus: store timestamps after February 2040 in xattrsfs/ fs/ fs/ +5 more | +745 | 0 replies | |
| 3/3 | hfsplus: add KUnit tests for date/time conversionfs/ fs/ fs/ +1 more | +357 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH v4 0/3] hfsplus: fix timestamp wrapping and support timestamps after 2040
HFS+ keeps timestamps in 32-bit unsigned on-disk fields as the number of seconds since January 1, 1904. Such field can represent the time range from January 1, 1904 till February 6, 2040.
The current HFS+ driver treats any on-disk timestamp under HFSPLUS_UTC_OFFSET (January 1, 1970) as a time between 2040 and 2106. Also, it calculates the on-disk value by means of adding the time offset to the lower 32 bits of the timestamp. As a result, any timestamp before January 1, 1970 is converted completely wrong and xfstests' generic/258 fails.
This patchset fixes the timestamp wrapping issue and extends the supported time range beyond February 2040.
The first patch corrects the logic of __hfsp_mt2ut() and __hfsp_ut2mt(). The on-disk timestamp is interpreted as unsigned number of seconds since January 1, 1904. HFS_UTC_OFFSET, HFS_MIN_TIMESTAMP_SECS and HFS_MAX_TIMESTAMP_SECS are defined in include/linux/hfs_common.h, and hfsplus_fill_super() sets sb->s_time_min, sb->s_time_max and sb->s_time_gran. This patch fixes generic/258 but it restricts the supported time range by February 6, 2040.
The second patch stores the timestamps after February 2040 into internal extended attributes and raises sb->s_time_max to HFSPLUS_MAX_TIMESTAMP_SECS. Such timestamp is stored as the maximal on-disk value (0xFFFFFFFF) in the catalog record and the real value is kept in the xattr as big-endian 64-bit number of seconds since January 1, 1970:
linux_hfs.create_date_u64
linux_hfs.content_mod_date_u64
linux_hfs.attribute_mod_date_u64
linux_hfs.access_date_u64
It is Linux specific extension of HFS+ on-disk layout. However, it is backward compatible: Mac OS X sees the clamped timestamp (February 6, 2040) and an extended attribute. If the xattr is absent (for example, the record has been created by Mac OS X), then the driver reads the maximal on-disk value as February 6, 2040. The internal xattrs are hidden from listxattr() and they cannot be changed by user. The creation date is supported by the same logic, including the hard link records. Also, the second patch fixes the issue when the Attributes File, created in the middle of sync operation, is not recorded into the volume header.
The third patch adds the hfsplus_time KUnit test suite that checks the date/time conversion logic and the extended timestamp support.
v4
- Rebased on the current hfs tree. The creation of catalog records has been reworked meanwhile (__hfsplus_create_cat() is shared by hfsplus_create_cat() and hfsplus_create_cat_uni()), so the creation date xattr is now saved in __hfsplus_create_cat().
- Set sb->s_time_max to HFSPLUS_MAX_TIMESTAMP_SECS in the second patch. v3 kept HFS_MAX_TIMESTAMP_SECS, so VFS clamped every timestamp to February 6, 2040 before it reached the driver.
- Mark is_create_date_identical() as noinline_for_stack. Both of its calls were inlined into hfsplus_lookup(), whose frame exceeded 1024 bytes with KASAN (-Wframe-larger-than=).
- Tested on a KASAN and lockdep kernel: mtime, atime and creation dates of files, directories and hard links (1950, February 6, 2040 and one second later, 2050, 2106, 2200) are preserved across remount and fsck.hfsplus reports the volume as OK; the hfsplus_time and hfsplus_unicode KUnit suites pass; xfstests generic/001, 002, 013, 020, 075, 112, 236 and 258 pass.
v3
File time_test.c has been renamed into hfsplus_time_test.c and file unicode_test.c has been renamed into hfsplus_unicode_test.c with the goal to exclude modules name conflict.
https://lore.kernel.org/all/[email protected]/
Viacheslav Dubeyko (3):
hfsplus: fix timestamp wrapped issue
hfsplus: store timestamps after February 2040 in xattrs
hfsplus: add KUnit tests for date/time conversion
fs/hfs/hfs_fs.h | 13 -
fs/hfsplus/Makefile | 2 +-
fs/hfsplus/attributes.c | 85 ++++-
fs/hfsplus/catalog.c | 108 +++++-
fs/hfsplus/dir.c | 50 ++-
fs/hfsplus/hfsplus_fs.h | 52 ++-
fs/hfsplus/hfsplus_time_test.c | 354 ++++++++++++++++++
...{unicode_test.c => hfsplus_unicode_test.c} | 0
fs/hfsplus/inode.c | 299 ++++++++++++++-
fs/hfsplus/super.c | 8 +
fs/hfsplus/xattr.c | 202 ++++++++--
fs/hfsplus/xattr.h | 32 +-
include/linux/hfs_common.h | 13 +
13 files changed, 1118 insertions(+), 100 deletions(-)
create mode 100644 fs/hfsplus/hfsplus_time_test.c
rename fs/hfsplus/{unicode_test.c => hfsplus_unicode_test.c} (100%)base-commit: d4558e30b83d14f59e9cac85d9e83d662491de51
Signature · 1 line
2.53.0