| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/14 04:39 | flow | patch-triage |
3mArgs:null Results: {
"EnableConfigs": [
"HFSPLUS_FS",
"BLOCK"
],
"FocusSymbols": [
"hfsplus_read_timestamp",
"hfsplus_get_timestamp_xattr",
"hfsplus_set_timestamp_xattr",
"hfsplus_remove_timestamp_xattr",
"hfsplus_set_attr_cnid",
"hfsplus_cat_write_inode",
"hfsplus_cat_read_inode",
"hfsplus_create_cat"
],
"KMSANReasoning": "The patch series adds 64-bit timestamp support to HFS+ by storing timestamps beyond February 2040 in internal extended attributes (\"linux_hfs.*\") and clamping on-disk 32-bit timestamps, along with corresponding KUnit test coverage.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and leaks of uninitialized kernel data to user space. In this patch:\n 1. All newly introduced stack structures (`struct hfsplus_timestamps`, `struct hfsplus_xattr_changes`, `struct timespec64`) are explicitly zero-initialized (`= {0}`).\n 2. In-memory inode timestamp fields (`birthdate`, `create_date`) are initialized to 0 in `hfsplus_iget()` and populated on inode read or creation.\n 3. The `statx` creation timestamp (`stat-\u003ebtime`) has both `tv_sec` and `tv_nsec` fully initialized in `hfsplus_getattr()`.\n 4. Dynamic allocations in `hfsplus_build_xattr_name()` use `kzalloc()`.\n 5. Inode/xattr record builders like `hfsplus_attr_build_record()` and `hfsplus_cat_build_record()` zero-fill record memory before writing.\n 6. Return/output arguments in helper functions (`hfsplus_read_timestamp()`, `hfsplus_get_timestamp_xattr()`) are always initialized before use, and internal xattrs are filtered from `listxattr` and user-facing APIs.\n- KASAN and standard sanitizers already adequately cover any risks related to buffer limits, memory allocations, or B-tree traversal/record bounds.\n\nTherefore, this patch series does not introduce uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies the HFS+ filesystem driver to extend timestamp support past February 2040 using hidden internal xattrs. This touches core filesystem operations including catalog creation, inode reading/writing, on-demand attributes file creation, and btree manipulation during inode writeback. The code is fully reachable in standard QEMU/virtualized environments by mounting or manipulating crafted HFS+ filesystem images and warrants fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/14 04:39 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit b4c9108390579ca1cf61016eb15d8e4bd23c1cac\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Oct 14 04:39:58 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h\nindex e250f87a5e336..659b0ba733d49 100644\n--- a/fs/hfs/hfs_fs.h\n+++ b/fs/hfs/hfs_fs.h\n@@ -255,19 +255,6 @@ extern int hfs_mac2asc(struct super_block *sb,\n /* super.c */\n extern void hfs_mark_mdb_dirty(struct super_block *sb);\n \n-/*\n- * There are two time systems. Both are based on seconds since\n- * a particular time/date.\n- *\tUnix:\tsigned little-endian since 00:00 GMT, Jan. 1, 1970\n- *\tmac:\tunsigned big-endian since 00:00 GMT, Jan. 1, 1904\n- *\n- * HFS implementations are highly inconsistent, this one matches the\n- * traditional behavior of 64-bit Linux, giving the most useful\n- * time range between 1970 and 2106, by treating any on-disk timestamp\n- * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.\n- */\n-#define HFS_UTC_OFFSET 2082844800U\n-\n static inline time64_t __hfs_m_to_utime(__be32 mt)\n {\n \ttime64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);\ndiff --git a/fs/hfsplus/Makefile b/fs/hfsplus/Makefile\nindex f2a9ae697e811..7cb0a5ef9831c 100644\n--- a/fs/hfsplus/Makefile\n+++ b/fs/hfsplus/Makefile\n@@ -10,4 +10,4 @@ hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btre\n \t\tattributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o\n \n # KUnit tests\n-obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += unicode_test.o\n+obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += hfsplus_unicode_test.o hfsplus_time_test.o\ndiff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c\nindex 7c2e589d45538..51b18d780f2c0 100644\n--- a/fs/hfsplus/attributes.c\n+++ b/fs/hfsplus/attributes.c\n@@ -206,7 +206,8 @@ int hfsplus_attr_exists(struct inode *inode, const char *name)\n }\n \n static\n-int hfsplus_create_attr_nolock(struct inode *inode, const char *name,\n+int hfsplus_create_attr_nolock(struct inode *inode, u32 cnid,\n+\t\t\t\tconst char *name,\n \t\t\t\tconst void *value, size_t size,\n \t\t\t\tstruct hfs_find_data *fd,\n \t\t\t\thfsplus_attr_entry *entry_ptr)\n@@ -215,12 +216,12 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,\n \tint entry_size;\n \tint err;\n \n-\thfs_dbg(\"name %s, ino %llu\\n\",\n-\t\tname ? name : NULL, inode-\u003ei_ino);\n+\thfs_dbg(\"name %s, ino %llu, cnid %u\\n\",\n+\t\tname ? name : NULL, inode-\u003ei_ino, cnid);\n \n \tif (name) {\n \t\terr = hfsplus_attr_build_key(sb, fd-\u003esearch_key,\n-\t\t\t\t\t\tinode-\u003ei_ino, name);\n+\t\t\t\t\t\tcnid, name);\n \t\tif (err)\n \t\t\treturn err;\n \t} else\n@@ -229,7 +230,7 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,\n \t/* Mac OS X supports only inline data attributes. */\n \tentry_size = hfsplus_attr_build_record(entry_ptr,\n \t\t\t\t\tHFSPLUS_ATTR_INLINE_DATA,\n-\t\t\t\t\tinode-\u003ei_ino,\n+\t\t\t\t\tcnid,\n \t\t\t\t\tvalue, size);\n \tif (entry_size == HFSPLUS_INVALID_ATTR_RECORD) {\n \t\tif (size \u003e HFSPLUS_MAX_INLINE_DATA_SIZE)\n@@ -289,8 +290,8 @@ int hfsplus_create_attr(struct inode *inode,\n \tif (err)\n \t\tgoto failed_create_attr;\n \n-\terr = hfsplus_create_attr_nolock(inode, name, value, size,\n-\t\t\t\t\t \u0026fd, entry_ptr);\n+\terr = hfsplus_create_attr_nolock(inode, (u32)inode-\u003ei_ino, name,\n+\t\t\t\t\t value, size, \u0026fd, entry_ptr);\n \tif (err)\n \t\tgoto failed_create_attr;\n \n@@ -347,18 +348,19 @@ static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,\n }\n \n static\n-int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,\n+int hfsplus_delete_attr_nolock(struct inode *inode, u32 cnid,\n+\t\t\t\tconst char *name,\n \t\t\t\tstruct hfs_find_data *fd)\n {\n \tstruct super_block *sb = inode-\u003ei_sb;\n \tint err;\n \n-\thfs_dbg(\"name %s, ino %llu\\n\",\n-\t\tname ? name : NULL, inode-\u003ei_ino);\n+\thfs_dbg(\"name %s, ino %llu, cnid %u\\n\",\n+\t\tname ? name : NULL, inode-\u003ei_ino, cnid);\n \n \tif (name) {\n \t\terr = hfsplus_attr_build_key(sb, fd-\u003esearch_key,\n-\t\t\t\t\t\tinode-\u003ei_ino, name);\n+\t\t\t\t\t\tcnid, name);\n \t\tif (err)\n \t\t\treturn err;\n \t} else {\n@@ -373,7 +375,7 @@ int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,\n \t} else if (err)\n \t\treturn err;\n \n-\terr = __hfsplus_delete_attr(inode, inode-\u003ei_ino, fd);\n+\terr = __hfsplus_delete_attr(inode, cnid, fd);\n \tif (err)\n \t\treturn err;\n \n@@ -403,7 +405,7 @@ int hfsplus_delete_attr(struct inode *inode, const char *name)\n \tif (err)\n \t\tgoto out;\n \n-\terr = hfsplus_delete_attr_nolock(inode, name, \u0026fd);\n+\terr = hfsplus_delete_attr_nolock(inode, (u32)inode-\u003ei_ino, name, \u0026fd);\n \tif (err)\n \t\tgoto out;\n \n@@ -481,12 +483,12 @@ int hfsplus_replace_attr(struct inode *inode,\n \tif (err)\n \t\tgoto failed_replace_attr;\n \n-\terr = hfsplus_delete_attr_nolock(inode, name, \u0026fd);\n+\terr = hfsplus_delete_attr_nolock(inode, (u32)inode-\u003ei_ino, name, \u0026fd);\n \tif (err)\n \t\tgoto failed_replace_attr;\n \n-\terr = hfsplus_create_attr_nolock(inode, name, value, size,\n-\t\t\t\t\t \u0026fd, entry_ptr);\n+\terr = hfsplus_create_attr_nolock(inode, (u32)inode-\u003ei_ino, name,\n+\t\t\t\t\t value, size, \u0026fd, entry_ptr);\n \tif (err)\n \t\tgoto failed_replace_attr;\n \n@@ -497,3 +499,54 @@ int hfsplus_replace_attr(struct inode *inode,\n \thfsplus_destroy_attr_entry(entry_ptr);\n \treturn err;\n }\n+\n+/*\n+ * Create or replace the xattr @name of catalog record @cnid.\n+ * The @inode is used only for access to the superblock and for\n+ * marking the attributes tree as dirty. It is the caller's\n+ * responsibility to set HFSPLUS_XATTR_EXISTS in the catalog record.\n+ */\n+int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,\n+\t\t\t const char *name,\n+\t\t\t const void *value, size_t size)\n+{\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\tstruct hfs_find_data fd;\n+\thfsplus_attr_entry *entry_ptr;\n+\tint err = 0;\n+\n+\thfs_dbg(\"name %s, ino %llu, cnid %u\\n\",\n+\t\tname ? name : NULL, inode-\u003ei_ino, cnid);\n+\n+\tif (!HFSPLUS_SB(sb)-\u003eattr_tree) {\n+\t\tpr_err(\"attributes file doesn't exist\\n\");\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tentry_ptr = hfsplus_alloc_attr_entry();\n+\tif (!entry_ptr)\n+\t\treturn -ENOMEM;\n+\n+\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\n+\tif (err)\n+\t\tgoto failed_init_set_attr;\n+\n+\t/* Fail early and avoid ENOSPC during the btree operation */\n+\terr = hfs_bmap_reserve(fd.tree, fd.tree-\u003edepth + 1);\n+\tif (err)\n+\t\tgoto failed_set_attr;\n+\n+\terr = hfsplus_delete_attr_nolock(inode, cnid, name, \u0026fd);\n+\tif (err \u0026\u0026 err != -ENOENT \u0026\u0026 err != -ENODATA)\n+\t\tgoto failed_set_attr;\n+\n+\terr = hfsplus_create_attr_nolock(inode, cnid, name,\n+\t\t\t\t\t value, size, \u0026fd, entry_ptr);\n+\n+failed_set_attr:\n+\thfs_find_exit(\u0026fd);\n+\n+failed_init_set_attr:\n+\thfsplus_destroy_attr_entry(entry_ptr);\n+\treturn err;\n+}\ndiff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c\nindex fe11c4b6dd997..d710419db3591 100644\n--- a/fs/hfsplus/catalog.c\n+++ b/fs/hfsplus/catalog.c\n@@ -12,6 +12,7 @@\n \n #include \"hfsplus_fs.h\"\n #include \"hfsplus_raw.h\"\n+#include \"xattr.h\"\n \n int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1,\n \t\t\t const hfsplus_btree_key *k2)\n@@ -102,10 +103,63 @@ void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms)\n \t\tperms-\u003edev = 0;\n }\n \n+static void hfsplus_copy_timestamps2folder(struct hfsplus_timestamps *timestamps,\n+\t\t\t\t\t struct hfsplus_cat_folder *folder)\n+{\n+\tfolder-\u003ecreate_date = timestamps-\u003ecreate_date;\n+\tfolder-\u003econtent_mod_date = timestamps-\u003econtent_mod_date;\n+\tfolder-\u003eattribute_mod_date = timestamps-\u003eattribute_mod_date;\n+\tfolder-\u003eaccess_date = timestamps-\u003eaccess_date;\n+}\n+\n+static void hfsplus_copy_timestamps2file(struct hfsplus_timestamps *timestamps,\n+\t\t\t\t\t struct hfsplus_cat_file *file)\n+{\n+\tfile-\u003ecreate_date = timestamps-\u003ecreate_date;\n+\tfile-\u003econtent_mod_date = timestamps-\u003econtent_mod_date;\n+\tfile-\u003eattribute_mod_date = timestamps-\u003eattribute_mod_date;\n+\tfile-\u003eaccess_date = timestamps-\u003eaccess_date;\n+}\n+\n+/*\n+ * Set creation date of new inode. The creation date after February 2040\n+ * is stored as HFSPLUS_EXT_TIMESTAMP_MARK in the catalog record. The real\n+ * value is saved into internal xattr by hfsplus_create_cat().\n+ */\n+static void hfsplus_set_create_date(struct inode *inode,\n+\t\t\t\t struct hfsplus_timestamps *timestamps)\n+{\n+\ttime64_t ut = ktime_get_real_seconds();\n+\t__be32 create_date = __hfsp_ut2mt(ut);\n+\n+\tHFSPLUS_I(inode)-\u003ebirthdate = ut;\n+\tHFSPLUS_I(inode)-\u003ecreate_date = create_date;\n+\n+\ttimestamps-\u003ecreate_date = create_date;\n+\ttimestamps-\u003econtent_mod_date = create_date;\n+\ttimestamps-\u003eattribute_mod_date = create_date;\n+\ttimestamps-\u003eaccess_date = create_date;\n+}\n+\n+/*\n+ * Real creation date of new catalog record. The hard link record\n+ * inherits the creation date of the hidden directory.\n+ */\n+static time64_t hfsplus_cat_record_birthdate(u32 cnid, struct inode *inode)\n+{\n+\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\n+\n+\tif (!S_ISDIR(inode-\u003ei_mode) \u0026\u0026 cnid != inode-\u003ei_ino)\n+\t\treturn HFSPLUS_I(sbi-\u003ehidden_dir)-\u003ebirthdate;\n+\n+\treturn HFSPLUS_I(inode)-\u003ebirthdate;\n+}\n+\n static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,\n-\t\tu32 cnid, struct inode *inode)\n+\t\t\t\t u32 cnid, struct inode *inode)\n {\n \tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\n+\tstruct hfsplus_timestamps timestamps = {0};\n \n \tif (S_ISDIR(inode-\u003ei_mode)) {\n \t\tstruct hfsplus_cat_folder *folder;\n@@ -116,11 +170,12 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,\n \t\tif (test_bit(HFSPLUS_SB_HFSX, \u0026sbi-\u003eflags))\n \t\t\tfolder-\u003eflags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);\n \t\tfolder-\u003eid = cpu_to_be32(inode-\u003ei_ino);\n-\t\tHFSPLUS_I(inode)-\u003ecreate_date =\n-\t\t\tfolder-\u003ecreate_date =\n-\t\t\tfolder-\u003econtent_mod_date =\n-\t\t\tfolder-\u003eattribute_mod_date =\n-\t\t\tfolder-\u003eaccess_date = hfsp_now2mt();\n+\n+\t\thfsplus_set_create_date(inode, \u0026timestamps);\n+\t\thfsplus_copy_timestamps2folder(\u0026timestamps, folder);\n+\t\tif (hfsp_ut_needs_xattr(HFSPLUS_I(inode)-\u003ebirthdate))\n+\t\t\tfolder-\u003eflags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);\n+\n \t\thfsplus_cat_set_perms(inode, \u0026folder-\u003epermissions);\n \t\tif (inode == sbi-\u003ehidden_dir)\n \t\t\t/* invisible and namelocked */\n@@ -134,11 +189,23 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,\n \t\tfile-\u003etype = cpu_to_be16(HFSPLUS_FILE);\n \t\tfile-\u003eflags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS);\n \t\tfile-\u003eid = cpu_to_be32(cnid);\n-\t\tHFSPLUS_I(inode)-\u003ecreate_date =\n-\t\t\tfile-\u003ecreate_date =\n-\t\t\tfile-\u003econtent_mod_date =\n-\t\t\tfile-\u003eattribute_mod_date =\n-\t\t\tfile-\u003eaccess_date = hfsp_now2mt();\n+\n+\t\tif (cnid == inode-\u003ei_ino) {\n+\t\t\thfsplus_set_create_date(inode, \u0026timestamps);\n+\t\t} else {\n+\t\t\t/*\n+\t\t\t * Hard link record: don't change creation date\n+\t\t\t * of the linked inode.\n+\t\t\t */\n+\t\t\t__be32 now = __hfsp_ut2mt(ktime_get_real_seconds());\n+\n+\t\t\ttimestamps.create_date = now;\n+\t\t\ttimestamps.content_mod_date = now;\n+\t\t\ttimestamps.attribute_mod_date = now;\n+\t\t\ttimestamps.access_date = now;\n+\t\t}\n+\t\thfsplus_copy_timestamps2file(\u0026timestamps, file);\n+\n \t\tif (cnid == inode-\u003ei_ino) {\n \t\t\thfsplus_cat_set_perms(inode, \u0026file-\u003epermissions);\n \t\t\tif (S_ISLNK(inode-\u003ei_mode)) {\n@@ -169,6 +236,10 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,\n \t\t\tfile-\u003epermissions.dev =\n \t\t\t\tcpu_to_be32(HFSPLUS_I(inode)-\u003elinkid);\n \t\t}\n+\n+\t\tif (hfsp_ut_needs_xattr(hfsplus_cat_record_birthdate(cnid, inode)))\n+\t\t\tfile-\u003eflags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);\n+\n \t\treturn sizeof(*file);\n \t}\n }\n@@ -256,6 +327,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,\n \tstruct super_block *sb = dir-\u003ei_sb;\n \tstruct hfs_find_data fd;\n \thfsplus_cat_entry entry;\n+\ttime64_t birthdate;\n \tint entry_size;\n \tint err;\n \n@@ -309,6 +381,22 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,\n \tif (err)\n \t\tgoto err1;\n \n+\tbirthdate = hfsplus_cat_record_birthdate(cnid, inode);\n+\tif (hfsp_ut_needs_xattr(birthdate)) {\n+\t\t/*\n+\t\t * Failure is not critical: the creation date\n+\t\t * will be read as HFS_MAX_TIMESTAMP_SECS.\n+\t\t */\n+\t\terr = hfsplus_set_timestamp_xattr(inode, cnid,\n+\t\t\t\t\t\t XATTR_LINUX_CREATE_DATE_NAME,\n+\t\t\t\t\t\t birthdate);\n+\t\tif (err) {\n+\t\t\tpr_warn(\"fail to save creation date: cnid %u, err %d\\n\",\n+\t\t\t\tcnid, err);\n+\t\t\terr = 0;\n+\t\t}\n+\t}\n+\n \tdir-\u003ei_size++;\n \tif (S_ISDIR(inode-\u003ei_mode))\n \t\thfsplus_subfolders_inc(dir);\ndiff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c\nindex 51fcba2e6d403..af0520ebced70 100644\n--- a/fs/hfsplus/dir.c\n+++ b/fs/hfsplus/dir.c\n@@ -26,6 +26,43 @@ static inline void hfsplus_instantiate(struct dentry *dentry,\n \td_instantiate(dentry, inode);\n }\n \n+/*\n+ * Check that creation date of catalog record @cnid is identical to\n+ * creation date of @inode. If the creation date is after February 2040,\n+ * then the real value is compared by means of internal xattr.\n+ */\n+static inline bool is_create_date_identical(struct inode *inode,\n+\t\t\t\t\t u32 cnid, __be32 create_date)\n+{\n+\ttime64_t timestamp;\n+\tbool has_xattr;\n+\tint err;\n+\n+\tif (create_date != HFSPLUS_I(inode)-\u003ecreate_date)\n+\t\treturn false;\n+\n+\tif (!hfsp_mt_is_ext_timestamp(create_date))\n+\t\treturn true;\n+\n+\terr = hfsplus_read_timestamp(inode-\u003ei_sb, cnid,\n+\t\t\t\t XATTR_LINUX_CREATE_DATE_NAME,\n+\t\t\t\t create_date, \u0026timestamp, \u0026has_xattr);\n+\tif (err) {\n+\t\tpr_err(\"timestamp extraction failure: cnid %u, err %d\\n\",\n+\t\t\tcnid, err);\n+\t\treturn false;\n+\t}\n+\n+\t/*\n+\t * The record without xattr (for example, created by Mac OS X)\n+\t * cannot be distinguished by means of 64-bit timestamp.\n+\t */\n+\tif (!has_xattr)\n+\t\treturn true;\n+\n+\treturn timestamp == HFSPLUS_I(inode)-\u003ebirthdate;\n+}\n+\n /* Find the entry inside dir named dentry-\u003ed_name */\n static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,\n \t\t\t\t unsigned int flags)\n@@ -78,12 +115,12 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,\n \t\t\t\tentry.file.user_info.fdCreator ==\n \t\t\t\tcpu_to_be32(HFSP_HFSPLUS_CREATOR) \u0026\u0026\n \t\t\t\tHFSPLUS_SB(sb)-\u003ehidden_dir \u0026\u0026\n-\t\t\t\t(entry.file.create_date ==\n-\t\t\t\t\tHFSPLUS_I(HFSPLUS_SB(sb)-\u003ehidden_dir)-\u003e\n-\t\t\t\t\t\tcreate_date ||\n-\t\t\t\tentry.file.create_date ==\n-\t\t\t\t\tHFSPLUS_I(d_inode(sb-\u003es_root))-\u003e\n-\t\t\t\t\t\tcreate_date)) {\n+\t\t\t\t(is_create_date_identical(\n+\t\t\t\t\tHFSPLUS_SB(sb)-\u003ehidden_dir,\n+\t\t\t\t\tcnid, entry.file.create_date) ||\n+\t\t\t\tis_create_date_identical(\n+\t\t\t\t\td_inode(sb-\u003es_root),\n+\t\t\t\t\tcnid, entry.file.create_date))) {\n \t\t\tstruct qstr str;\n \t\t\tchar name[32];\n \ndiff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h\nindex 1e5b58e6a13fc..637bba65568ec 100644\n--- a/fs/hfsplus/hfsplus_fs.h\n+++ b/fs/hfsplus/hfsplus_fs.h\n@@ -175,6 +175,13 @@ static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)\n \treturn sb-\u003es_fs_info;\n }\n \n+struct hfsplus_timestamps {\n+\t__be32 create_date;\n+\t__be32 content_mod_date;\n+\t__be32 attribute_mod_date;\n+\t__be32 access_date;\n+\t__be32 backup_date;\n+};\n \n struct hfsplus_inode_info {\n \tatomic_t opencnt;\n@@ -196,7 +203,8 @@ struct hfsplus_inode_info {\n \t * Immutable data.\n \t */\n \tstruct inode *rsrc_inode;\n-\t__be32 create_date;\n+\t__be32 create_date;\t/* on-disk (maybe clamped) creation date */\n+\ttime64_t birthdate;\t/* real creation date (seconds since 1970) */\n \n \t/*\n \t * Protected by sbi-\u003evh_mutex.\n@@ -227,6 +235,9 @@ struct hfsplus_inode_info {\n #define HFSPLUS_I_EXT_DIRTY\t2\t/* has changes in the extent tree */\n #define HFSPLUS_I_ALLOC_DIRTY\t3\t/* has changes in the allocation file */\n #define HFSPLUS_I_ATTR_DIRTY\t4\t/* has changes in the attributes tree */\n+#define HFSPLUS_I_ATIME_XATTR\t5\t/* access date is stored in xattr */\n+#define HFSPLUS_I_MTIME_XATTR\t6\t/* content mod date is stored in xattr */\n+#define HFSPLUS_I_CTIME_XATTR\t7\t/* attribute mod date is stored in xattr */\n \n #define HFSPLUS_IS_RSRC(inode) \\\n \ttest_bit(HFSPLUS_I_RSRC, \u0026HFSPLUS_I(inode)-\u003eflags)\n@@ -351,6 +362,9 @@ int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);\n int hfsplus_replace_attr(struct inode *inode,\n \t\t\t const char *name,\n \t\t\t const void *value, size_t size);\n+int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,\n+\t\t\t const char *name,\n+\t\t\t const void *value, size_t size);\n \n /* bitmap.c */\n int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset,\n@@ -467,6 +481,9 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,\n int hfsplus_fileattr_get(struct dentry *dentry, struct file_kattr *fa);\n int hfsplus_fileattr_set(struct mnt_idmap *idmap,\n \t\t\t struct dentry *dentry, struct file_kattr *fa);\n+int hfsplus_read_timestamp(struct super_block *sb, u32 cnid,\n+\t\t\t const char *name, __be32 mt,\n+\t\t\t time64_t *ut, bool *has_xattr);\n \n /* ioctl.c */\n long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);\n@@ -532,23 +549,42 @@ int hfsplus_brec_read_cat(struct hfs_find_data *fd, hfsplus_cat_entry *entry);\n /*\n * time helpers: convert between 1904-base and 1970-base timestamps\n *\n- * HFS+ implementations are highly inconsistent, this one matches the\n- * traditional behavior of 64-bit Linux, giving the most useful\n- * time range between 1970 and 2106, by treating any on-disk timestamp\n- * under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.\n+ * The on-disk 32-bit timestamps cover the range from\n+ * HFS_MIN_TIMESTAMP_SECS (Jan. 1, 1904) till HFS_MAX_TIMESTAMP_SECS\n+ * (Feb. 6, 2040). The timestamps out of this range are clamped.\n+ * The on-disk value HFSPLUS_EXT_TIMESTAMP_MARK (maximal value) means\n+ * that real timestamp could be stored in the internal xattr of\n+ * the catalog record. It is Linux specific extension of\n+ * HFS+ on-disk layout. It makes possible to support timestamps\n+ * till HFSPLUS_MAX_TIMESTAMP_SECS.\n */\n-#define HFSPLUS_UTC_OFFSET 2082844800U\n+#define HFSPLUS_EXT_TIMESTAMP_MARK\tcpu_to_be32(U32_MAX)\n+#define HFSPLUS_MAX_TIMESTAMP_SECS\tTIME64_MAX\n \n static inline time64_t __hfsp_mt2ut(__be32 mt)\n {\n-\ttime64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET);\n+\ttime64_t ut = (time64_t)be32_to_cpu(mt) - HFS_UTC_OFFSET;\n \n \treturn ut;\n }\n \n static inline __be32 __hfsp_ut2mt(time64_t ut)\n {\n-\treturn cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET);\n+\tut = clamp_t(time64_t, ut,\n+\t\t HFS_MIN_TIMESTAMP_SECS, HFS_MAX_TIMESTAMP_SECS);\n+\tut += HFS_UTC_OFFSET;\n+\n+\treturn cpu_to_be32(lower_32_bits(ut));\n+}\n+\n+static inline bool hfsp_ut_needs_xattr(time64_t ut)\n+{\n+\treturn ut \u003e= HFS_MAX_TIMESTAMP_SECS;\n+}\n+\n+static inline bool hfsp_mt_is_ext_timestamp(__be32 mt)\n+{\n+\treturn mt == HFSPLUS_EXT_TIMESTAMP_MARK;\n }\n \n static inline enum hfsplus_btree_mutex_classes\ndiff --git a/fs/hfsplus/hfsplus_time_test.c b/fs/hfsplus/hfsplus_time_test.c\nnew file mode 100644\nindex 0000000000000..4b3312dc0048b\n--- /dev/null\n+++ b/fs/hfsplus/hfsplus_time_test.c\n@@ -0,0 +1,354 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * KUnit tests for HFS+ date/time conversion\n+ *\n+ * Copyright (C) 2026 Viacheslav Dubeyko \u003cslava@dubeyko.com\u003e\n+ */\n+\n+#include \u003ckunit/test.h\u003e\n+#include \"hfsplus_fs.h\"\n+#include \"xattr.h\"\n+\n+/* January 1, 1970, 00:00:00 UTC */\n+#define TEST_UNIX_EPOCH_SECS\t\t0LL\n+/* December 31, 1969, 23:59:59 UTC */\n+#define TEST_BEFORE_UNIX_EPOCH_SECS\t-1LL\n+/* January 1, 2000, 00:00:00 UTC */\n+#define TEST_Y2000_SECS\t\t\t946684800LL\n+/* January 19, 2038, 03:14:08 UTC (signed 32-bit overflow) */\n+#define TEST_Y2038_SECS\t\t\t2147483648LL\n+/* January 1, 2026, 00:00:00 UTC */\n+#define TEST_Y2026_SECS\t\t\t1767225600LL\n+/* January 1, 2100, 00:00:00 UTC */\n+#define TEST_Y2100_SECS\t\t\t4102444800LL\n+/* January 1, 1900, 00:00:00 UTC */\n+#define TEST_Y1900_SECS\t\t\t-2208988800LL\n+\n+static u32 mt_raw(__be32 mt)\n+{\n+\treturn be32_to_cpu(mt);\n+}\n+\n+/* Test the time range constants */\n+static void hfsplus_time_constants_test(struct kunit *test)\n+{\n+\t/* 32-bit unsigned on-disk field covers exactly U32_MAX seconds */\n+\tKUNIT_EXPECT_EQ(test, (s64)U32_MAX,\n+\t\t\tHFS_MAX_TIMESTAMP_SECS - HFS_MIN_TIMESTAMP_SECS);\n+\tKUNIT_EXPECT_EQ(test, -(s64)HFS_UTC_OFFSET, HFS_MIN_TIMESTAMP_SECS);\n+\n+\t/* xattrs extend the supported range beyond February 2040 */\n+\tKUNIT_EXPECT_GT(test, (s64)HFSPLUS_MAX_TIMESTAMP_SECS,\n+\t\t\t(s64)HFS_MAX_TIMESTAMP_SECS);\n+\n+\t/* the extended timestamp mark is the maximal on-disk value */\n+\tKUNIT_EXPECT_EQ(test, U32_MAX, mt_raw(HFSPLUS_EXT_TIMESTAMP_MARK));\n+}\n+\n+/* Test conversion of on-disk (1904-based) timestamp into 1970-based one */\n+static void hfsplus_mt2ut_test(struct kunit *test)\n+{\n+\tKUNIT_EXPECT_EQ(test, HFS_MIN_TIMESTAMP_SECS,\n+\t\t\t__hfsp_mt2ut(cpu_to_be32(0)));\n+\tKUNIT_EXPECT_EQ(test, TEST_UNIX_EPOCH_SECS,\n+\t\t\t__hfsp_mt2ut(cpu_to_be32(HFS_UTC_OFFSET)));\n+\tKUNIT_EXPECT_EQ(test, TEST_BEFORE_UNIX_EPOCH_SECS,\n+\t\t\t__hfsp_mt2ut(cpu_to_be32(HFS_UTC_OFFSET - 1)));\n+\tKUNIT_EXPECT_EQ(test, TEST_Y2000_SECS,\n+\t\t\t__hfsp_mt2ut(cpu_to_be32(3029529600U)));\n+\tKUNIT_EXPECT_EQ(test, TEST_Y2026_SECS,\n+\t\t\t__hfsp_mt2ut(cpu_to_be32(3850070400U)));\n+\tKUNIT_EXPECT_EQ(test, TEST_Y2038_SECS,\n+\t\t\t__hfsp_mt2ut(cpu_to_be32(4230328448U)));\n+\tKUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS,\n+\t\t\t__hfsp_mt2ut(cpu_to_be32(U32_MAX)));\n+\tKUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS,\n+\t\t\t__hfsp_mt2ut(HFSPLUS_EXT_TIMESTAMP_MARK));\n+}\n+\n+/* Test conversion of 1970-based timestamp into on-disk (1904-based) one */\n+static void hfsplus_ut2mt_test(struct kunit *test)\n+{\n+\tKUNIT_EXPECT_EQ(test, 0U,\n+\t\t\tmt_raw(__hfsp_ut2mt(HFS_MIN_TIMESTAMP_SECS)));\n+\tKUNIT_EXPECT_EQ(test, HFS_UTC_OFFSET,\n+\t\t\tmt_raw(__hfsp_ut2mt(TEST_UNIX_EPOCH_SECS)));\n+\tKUNIT_EXPECT_EQ(test, 3029529600U,\n+\t\t\tmt_raw(__hfsp_ut2mt(TEST_Y2000_SECS)));\n+\tKUNIT_EXPECT_EQ(test, 3850070400U,\n+\t\t\tmt_raw(__hfsp_ut2mt(TEST_Y2026_SECS)));\n+\tKUNIT_EXPECT_EQ(test, 4230328448U,\n+\t\t\tmt_raw(__hfsp_ut2mt(TEST_Y2038_SECS)));\n+\tKUNIT_EXPECT_EQ(test, U32_MAX - 1,\n+\t\t\tmt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS - 1)));\n+\tKUNIT_EXPECT_EQ(test, U32_MAX,\n+\t\t\tmt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS)));\n+}\n+\n+/*\n+ * Test timestamps before January 1, 1970 (xfstests generic/258).\n+ * The old logic added HFS_UTC_OFFSET to lower 32 bits of negative\n+ * value and produced completely wrong result.\n+ */\n+static void hfsplus_ut2mt_before_1970_test(struct kunit *test)\n+{\n+\ttime64_t ut;\n+\n+\tKUNIT_EXPECT_EQ(test, HFS_UTC_OFFSET - 1,\n+\t\t\tmt_raw(__hfsp_ut2mt(TEST_BEFORE_UNIX_EPOCH_SECS)));\n+\n+\t/* January 1, 1960, 00:00:00 UTC */\n+\tut = -315619200LL;\n+\tKUNIT_EXPECT_EQ(test, ut, __hfsp_mt2ut(__hfsp_ut2mt(ut)));\n+\n+\t/* January 1, 1904, 00:00:01 UTC */\n+\tut = HFS_MIN_TIMESTAMP_SECS + 1;\n+\tKUNIT_EXPECT_EQ(test, 1U, mt_raw(__hfsp_ut2mt(ut)));\n+\tKUNIT_EXPECT_EQ(test, ut, __hfsp_mt2ut(__hfsp_ut2mt(ut)));\n+}\n+\n+/* Test that out-of-range timestamps are clamped instead of wrapped */\n+static void hfsplus_ut2mt_clamp_test(struct kunit *test)\n+{\n+\t/* below January 1, 1904 */\n+\tKUNIT_EXPECT_EQ(test, 0U,\n+\t\t\tmt_raw(__hfsp_ut2mt(HFS_MIN_TIMESTAMP_SECS - 1)));\n+\tKUNIT_EXPECT_EQ(test, 0U,\n+\t\t\tmt_raw(__hfsp_ut2mt(TEST_Y1900_SECS)));\n+\tKUNIT_EXPECT_EQ(test, 0U,\n+\t\t\tmt_raw(__hfsp_ut2mt(TIME64_MIN)));\n+\n+\t/* after February 6, 2040 */\n+\tKUNIT_EXPECT_EQ(test, U32_MAX,\n+\t\t\tmt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS + 1)));\n+\tKUNIT_EXPECT_EQ(test, U32_MAX,\n+\t\t\tmt_raw(__hfsp_ut2mt(TEST_Y2100_SECS)));\n+\tKUNIT_EXPECT_EQ(test, U32_MAX,\n+\t\t\tmt_raw(__hfsp_ut2mt(HFSPLUS_MAX_TIMESTAMP_SECS)));\n+\n+\t/* lower 32 bits of these values would wrap into small dates */\n+\tKUNIT_EXPECT_EQ(test, U32_MAX,\n+\t\t\tmt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS +\n+\t\t\t\t\t (s64)U32_MAX + 1)));\n+\tKUNIT_EXPECT_EQ(test, U32_MAX,\n+\t\t\tmt_raw(__hfsp_ut2mt(1LL \u003c\u003c 32)));\n+}\n+\n+/* Test that representable timestamps survive the round trip */\n+static void hfsplus_time_roundtrip_test(struct kunit *test)\n+{\n+\tstatic const time64_t values[] = {\n+\t\tHFS_MIN_TIMESTAMP_SECS,\n+\t\tHFS_MIN_TIMESTAMP_SECS + 1,\n+\t\tTEST_BEFORE_UNIX_EPOCH_SECS,\n+\t\tTEST_UNIX_EPOCH_SECS,\n+\t\t1,\n+\t\tTEST_Y2000_SECS,\n+\t\tTEST_Y2026_SECS,\n+\t\t(s64)S32_MAX,\n+\t\tTEST_Y2038_SECS,\n+\t\tHFS_MAX_TIMESTAMP_SECS - 1,\n+\t\tHFS_MAX_TIMESTAMP_SECS,\n+\t};\n+\ttime64_t ut;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(values); i++) {\n+\t\tKUNIT_EXPECT_EQ_MSG(test, values[i],\n+\t\t\t\t __hfsp_mt2ut(__hfsp_ut2mt(values[i])),\n+\t\t\t\t \"round trip failed: index %d\", i);\n+\t}\n+\n+\t/* sweep the whole range with a large prime step */\n+\tfor (ut = HFS_MIN_TIMESTAMP_SECS; ut \u003c= HFS_MAX_TIMESTAMP_SECS;\n+\t ut += 999983) {\n+\t\tif (__hfsp_mt2ut(__hfsp_ut2mt(ut)) != ut) {\n+\t\t\tKUNIT_FAIL(test, \"round trip failed: ut %lld\", ut);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/* every on-disk value maps back to itself */\n+\tfor (i = 0; i \u003c 32; i++) {\n+\t\tu32 raw = (u32)BIT_ULL(i);\n+\n+\t\tKUNIT_EXPECT_EQ(test, raw,\n+\t\t\t\tmt_raw(__hfsp_ut2mt(__hfsp_mt2ut(cpu_to_be32(raw)))));\n+\t}\n+}\n+\n+/* Test the decision to keep timestamp in xattr */\n+static void hfsplus_ut_needs_xattr_test(struct kunit *test)\n+{\n+\tKUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(HFS_MIN_TIMESTAMP_SECS));\n+\tKUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_BEFORE_UNIX_EPOCH_SECS));\n+\tKUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_UNIX_EPOCH_SECS));\n+\tKUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_Y2026_SECS));\n+\tKUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_Y2038_SECS));\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS - 1));\n+\n+\tKUNIT_EXPECT_TRUE(test, hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS + 1));\n+\tKUNIT_EXPECT_TRUE(test, hfsp_ut_needs_xattr(TEST_Y2100_SECS));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t hfsp_ut_needs_xattr(HFSPLUS_MAX_TIMESTAMP_SECS));\n+}\n+\n+/* Test detection of the extended timestamp mark */\n+static void hfsplus_mt_is_ext_timestamp_test(struct kunit *test)\n+{\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\thfsp_mt_is_ext_timestamp(HFSPLUS_EXT_TIMESTAMP_MARK));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\thfsp_mt_is_ext_timestamp(cpu_to_be32(U32_MAX)));\n+\n+\tKUNIT_EXPECT_FALSE(test, hfsp_mt_is_ext_timestamp(cpu_to_be32(0)));\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\thfsp_mt_is_ext_timestamp(cpu_to_be32(U32_MAX - 1)));\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\thfsp_mt_is_ext_timestamp(cpu_to_be32(HFS_UTC_OFFSET)));\n+\n+\t/* every timestamp that needs xattr is stored as the mark */\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\thfsp_mt_is_ext_timestamp(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS)));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\thfsp_mt_is_ext_timestamp(__hfsp_ut2mt(TEST_Y2100_SECS)));\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\thfsp_mt_is_ext_timestamp(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS - 1)));\n+}\n+\n+static struct super_block *alloc_mock_sb(struct kunit *test)\n+{\n+\tstruct super_block *sb;\n+\tstruct hfsplus_sb_info *sbi;\n+\n+\tsb = kunit_kzalloc(test, sizeof(*sb), GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, sb);\n+\n+\tsbi = kunit_kzalloc(test, sizeof(*sbi), GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, sbi);\n+\n+\t/* no attributes tree: xattr lookup returns -EOPNOTSUPP */\n+\tsbi-\u003eattr_tree = NULL;\n+\tsb-\u003es_fs_info = sbi;\n+\n+\treturn sb;\n+}\n+\n+/*\n+ * Test reading of the on-disk timestamp that doesn't need xattr.\n+ * The superblock must not be touched in such case.\n+ */\n+static void hfsplus_read_timestamp_regular_test(struct kunit *test)\n+{\n+\tstatic const time64_t values[] = {\n+\t\tHFS_MIN_TIMESTAMP_SECS,\n+\t\tTEST_BEFORE_UNIX_EPOCH_SECS,\n+\t\tTEST_UNIX_EPOCH_SECS,\n+\t\tTEST_Y2026_SECS,\n+\t\tHFS_MAX_TIMESTAMP_SECS - 1,\n+\t};\n+\ttime64_t ut;\n+\tbool has_xattr;\n+\tint err;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(values); i++) {\n+\t\tut = 0;\n+\t\thas_xattr = true;\n+\n+\t\terr = hfsplus_read_timestamp(NULL, HFSPLUS_FIRSTUSER_CNID,\n+\t\t\t\t\t XATTR_LINUX_ACCESS_DATE_NAME,\n+\t\t\t\t\t __hfsp_ut2mt(values[i]),\n+\t\t\t\t\t \u0026ut, \u0026has_xattr);\n+\t\tKUNIT_EXPECT_EQ(test, 0, err);\n+\t\tKUNIT_EXPECT_EQ(test, values[i], ut);\n+\t\tKUNIT_EXPECT_FALSE(test, has_xattr);\n+\t}\n+}\n+\n+/*\n+ * Test reading of the extended timestamp mark without xattr\n+ * (for example, the record has been created by Mac OS X or\n+ * the volume has no attributes tree). The timestamp must be\n+ * HFS_MAX_TIMESTAMP_SECS without any error.\n+ */\n+static void hfsplus_read_timestamp_mark_no_xattr_test(struct kunit *test)\n+{\n+\tstruct super_block *sb = alloc_mock_sb(test);\n+\tstatic const char * const names[] = {\n+\t\tXATTR_LINUX_CREATE_DATE_NAME,\n+\t\tXATTR_LINUX_CONTENT_MOD_DATE_NAME,\n+\t\tXATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,\n+\t\tXATTR_LINUX_ACCESS_DATE_NAME,\n+\t};\n+\ttime64_t ut;\n+\tbool has_xattr;\n+\tint err;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(names); i++) {\n+\t\tut = 0;\n+\t\thas_xattr = true;\n+\n+\t\terr = hfsplus_read_timestamp(sb, HFSPLUS_FIRSTUSER_CNID,\n+\t\t\t\t\t names[i],\n+\t\t\t\t\t HFSPLUS_EXT_TIMESTAMP_MARK,\n+\t\t\t\t\t \u0026ut, \u0026has_xattr);\n+\t\tKUNIT_EXPECT_EQ(test, 0, err);\n+\t\tKUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS, ut);\n+\t\tKUNIT_EXPECT_FALSE(test, has_xattr);\n+\t}\n+}\n+\n+/* Test that names of internal xattrs fit the name buffer */\n+static void hfsplus_timestamp_xattr_names_test(struct kunit *test)\n+{\n+\tstatic const char * const names[] = {\n+\t\tXATTR_LINUX_CREATE_DATE_NAME,\n+\t\tXATTR_LINUX_CONTENT_MOD_DATE_NAME,\n+\t\tXATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,\n+\t\tXATTR_LINUX_ACCESS_DATE_NAME,\n+\t\tXATTR_LINUX_BACKUP_DATE_NAME,\n+\t};\n+\tint i;\n+\n+\tKUNIT_EXPECT_EQ(test, strlen(XATTR_LINUX_HFS_PREFIX),\n+\t\t\t(size_t)XATTR_LINUX_HFS_PREFIX_LEN);\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(names); i++) {\n+\t\tsize_t len = XATTR_LINUX_HFS_PREFIX_LEN + strlen(names[i]);\n+\n+\t\tKUNIT_EXPECT_LT_MSG(test, len, (size_t)XATTR_LINUX_HFS_NAME_MAX,\n+\t\t\t\t \"name %s is too long\", names[i]);\n+\t\tKUNIT_EXPECT_LE(test, len, (size_t)HFSPLUS_ATTR_MAX_STRLEN);\n+\t}\n+}\n+\n+static struct kunit_case hfsplus_time_test_cases[] = {\n+\tKUNIT_CASE(hfsplus_time_constants_test),\n+\tKUNIT_CASE(hfsplus_mt2ut_test),\n+\tKUNIT_CASE(hfsplus_ut2mt_test),\n+\tKUNIT_CASE(hfsplus_ut2mt_before_1970_test),\n+\tKUNIT_CASE(hfsplus_ut2mt_clamp_test),\n+\tKUNIT_CASE(hfsplus_time_roundtrip_test),\n+\tKUNIT_CASE(hfsplus_ut_needs_xattr_test),\n+\tKUNIT_CASE(hfsplus_mt_is_ext_timestamp_test),\n+\tKUNIT_CASE(hfsplus_read_timestamp_regular_test),\n+\tKUNIT_CASE(hfsplus_read_timestamp_mark_no_xattr_test),\n+\tKUNIT_CASE(hfsplus_timestamp_xattr_names_test),\n+\t{}\n+};\n+\n+static struct kunit_suite hfsplus_time_test_suite = {\n+\t.name = \"hfsplus_time\",\n+\t.test_cases = hfsplus_time_test_cases,\n+};\n+\n+kunit_test_suite(hfsplus_time_test_suite);\n+\n+MODULE_DESCRIPTION(\"KUnit tests for HFS+ date/time conversion\");\n+MODULE_LICENSE(\"GPL\");\n+MODULE_IMPORT_NS(\"EXPORTED_FOR_KUNIT_TESTING\");\ndiff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/hfsplus_unicode_test.c\nsimilarity index 100%\nrename from fs/hfsplus/unicode_test.c\nrename to fs/hfsplus/hfsplus_unicode_test.c\ndiff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c\nindex 2ce6de574fa6e..0df58dfda5a3e 100644\n--- a/fs/hfsplus/inode.c\n+++ b/fs/hfsplus/inode.c\n@@ -18,6 +18,7 @@\n #include \u003clinux/cred.h\u003e\n #include \u003clinux/uio.h\u003e\n #include \u003clinux/fileattr.h\u003e\n+#include \u003ckunit/visibility.h\u003e\n \n #include \"hfsplus_fs.h\"\n #include \"hfsplus_raw.h\"\n@@ -344,7 +345,8 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,\n \n \tif (request_mask \u0026 STATX_BTIME) {\n \t\tstat-\u003eresult_mask |= STATX_BTIME;\n-\t\tstat-\u003ebtime = hfsp_mt2ut(hip-\u003ecreate_date);\n+\t\tstat-\u003ebtime.tv_sec = hip-\u003ebirthdate;\n+\t\tstat-\u003ebtime.tv_nsec = 0;\n \t}\n \n \tif (inode-\u003ei_flags \u0026 S_APPEND)\n@@ -598,9 +600,139 @@ void hfsplus_inode_write_fork(struct inode *inode,\n \tfork-\u003etotal_blocks = cpu_to_be32(HFSPLUS_I(inode)-\u003ealloc_blocks);\n }\n \n+/*\n+ * hfsplus_read_timestamp - convert on-disk timestamp into 1970-base one\n+ * @sb: superblock\n+ * @cnid: catalog record ID\n+ * @name: name of internal xattr that can keep the real timestamp\n+ * @mt: on-disk timestamp\n+ * @ut: pointer on converted timestamp [out]\n+ * @has_xattr: pointer on flag that xattr exists [out]\n+ *\n+ * If on-disk timestamp is equal to HFSPLUS_EXT_TIMESTAMP_MARK, then\n+ * the real timestamp (after February 2040) could be stored in\n+ * the internal xattr. If the xattr is absent (for example, the record\n+ * has been created by Mac OS X), then HFS_MAX_TIMESTAMP_SECS is used.\n+ */\n+int hfsplus_read_timestamp(struct super_block *sb, u32 cnid,\n+\t\t\t const char *name, __be32 mt,\n+\t\t\t time64_t *ut, bool *has_xattr)\n+{\n+\ttime64_t timestamp;\n+\tint err;\n+\n+\t*ut = __hfsp_mt2ut(mt);\n+\t*has_xattr = false;\n+\n+\tif (!hfsp_mt_is_ext_timestamp(mt))\n+\t\treturn 0;\n+\n+\terr = hfsplus_get_timestamp_xattr(sb, cnid, name, \u0026timestamp);\n+\tif (err == -ENODATA || err == -EOPNOTSUPP) {\n+\t\t/* timestamp is really equal to HFS_MAX_TIMESTAMP_SECS */\n+\t\treturn 0;\n+\t} else if (unlikely(err)) {\n+\t\tpr_warn(\"fail to extract timestamp: cnid %u, name %s, err %d\\n\",\n+\t\t\tcnid, name, err);\n+\t\treturn err;\n+\t}\n+\n+\tif (timestamp \u003c HFS_MAX_TIMESTAMP_SECS) {\n+\t\tpr_warn(\"invalid timestamp in xattr: cnid %u, name %s, timestamp %lld\\n\",\n+\t\t\tcnid, name, timestamp);\n+\t\t/* keep xattr to be deleted or overwritten */\n+\t\t*has_xattr = true;\n+\t} else {\n+\t\t*ut = timestamp;\n+\t\t*has_xattr = true;\n+\t}\n+\n+\treturn 0;\n+}\n+EXPORT_SYMBOL_IF_KUNIT(hfsplus_read_timestamp);\n+\n+static int hfsplus_inode_read_timestamps(struct inode *inode,\n+\t\t\t\t\t struct hfsplus_timestamps *timestamps)\n+{\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n+\tu32 cnid = inode-\u003ei_ino;\n+\tstruct timespec64 ts = {0};\n+\tbool has_xattr;\n+\tint res = 0;\n+\n+\tres = hfsplus_read_timestamp(sb, cnid,\n+\t\t\t\t XATTR_LINUX_ACCESS_DATE_NAME,\n+\t\t\t\t timestamps-\u003eaccess_date,\n+\t\t\t\t \u0026ts.tv_sec, \u0026has_xattr);\n+\tif (res)\n+\t\tgoto finish_read_timestamps;\n+\n+\tinode_set_atime_to_ts(inode, ts);\n+\tif (has_xattr)\n+\t\tset_bit(HFSPLUS_I_ATIME_XATTR, \u0026hip-\u003eflags);\n+\n+\tres = hfsplus_read_timestamp(sb, cnid,\n+\t\t\t\t XATTR_LINUX_CONTENT_MOD_DATE_NAME,\n+\t\t\t\t timestamps-\u003econtent_mod_date,\n+\t\t\t\t \u0026ts.tv_sec, \u0026has_xattr);\n+\tif (res)\n+\t\tgoto finish_read_timestamps;\n+\n+\tinode_set_mtime_to_ts(inode, ts);\n+\tif (has_xattr)\n+\t\tset_bit(HFSPLUS_I_MTIME_XATTR, \u0026hip-\u003eflags);\n+\n+\tres = hfsplus_read_timestamp(sb, cnid,\n+\t\t\t\t XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,\n+\t\t\t\t timestamps-\u003eattribute_mod_date,\n+\t\t\t\t \u0026ts.tv_sec, \u0026has_xattr);\n+\tif (res)\n+\t\tgoto finish_read_timestamps;\n+\n+\tinode_set_ctime_to_ts(inode, ts);\n+\tif (has_xattr)\n+\t\tset_bit(HFSPLUS_I_CTIME_XATTR, \u0026hip-\u003eflags);\n+\n+\tres = hfsplus_read_timestamp(sb, cnid,\n+\t\t\t\t XATTR_LINUX_CREATE_DATE_NAME,\n+\t\t\t\t timestamps-\u003ecreate_date,\n+\t\t\t\t \u0026hip-\u003ebirthdate, \u0026has_xattr);\n+\tif (res)\n+\t\tgoto finish_read_timestamps;\n+\n+\thip-\u003ecreate_date = timestamps-\u003ecreate_date;\n+\n+finish_read_timestamps:\n+\treturn res;\n+}\n+\n+static inline void\n+hfsplus_copy_folder2timestamps(struct hfsplus_cat_folder *folder,\n+\t\t\t\tstruct hfsplus_timestamps *timestamps)\n+{\n+\ttimestamps-\u003ecreate_date = folder-\u003ecreate_date;\n+\ttimestamps-\u003econtent_mod_date = folder-\u003econtent_mod_date;\n+\ttimestamps-\u003eattribute_mod_date = folder-\u003eattribute_mod_date;\n+\ttimestamps-\u003eaccess_date = folder-\u003eaccess_date;\n+\ttimestamps-\u003ebackup_date = folder-\u003ebackup_date;\n+}\n+\n+static inline void\n+hfsplus_copy_file2timestamps(struct hfsplus_cat_file *file,\n+\t\t\t struct hfsplus_timestamps *timestamps)\n+{\n+\ttimestamps-\u003ecreate_date = file-\u003ecreate_date;\n+\ttimestamps-\u003econtent_mod_date = file-\u003econtent_mod_date;\n+\ttimestamps-\u003eattribute_mod_date = file-\u003eattribute_mod_date;\n+\ttimestamps-\u003eaccess_date = file-\u003eaccess_date;\n+\ttimestamps-\u003ebackup_date = file-\u003ebackup_date;\n+}\n+\n int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)\n {\n \thfsplus_cat_entry entry;\n+\tstruct hfsplus_timestamps timestamps = {0};\n \tint res = 0;\n \tu16 type;\n \n@@ -622,12 +754,14 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)\n \t\t\tgoto out;\n \t\tset_nlink(inode, 1);\n \t\tinode-\u003ei_size = 2 + be32_to_cpu(folder-\u003evalence);\n-\t\tinode_set_atime_to_ts(inode, hfsp_mt2ut(folder-\u003eaccess_date));\n-\t\tinode_set_mtime_to_ts(inode,\n-\t\t\t\t hfsp_mt2ut(folder-\u003econtent_mod_date));\n-\t\tinode_set_ctime_to_ts(inode,\n-\t\t\t\t hfsp_mt2ut(folder-\u003eattribute_mod_date));\n-\t\tHFSPLUS_I(inode)-\u003ecreate_date = folder-\u003ecreate_date;\n+\n+\t\thfsplus_copy_folder2timestamps(folder, \u0026timestamps);\n+\t\tres = hfsplus_inode_read_timestamps(inode, \u0026timestamps);\n+\t\tif (res) {\n+\t\t\tres = -EIO;\n+\t\t\tgoto out;\n+\t\t}\n+\n \t\tHFSPLUS_I(inode)-\u003efs_blocks = 0;\n \t\tif (folder-\u003eflags \u0026 cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {\n \t\t\tHFSPLUS_I(inode)-\u003esubfolders =\n@@ -668,12 +802,13 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)\n \t\t\tinit_special_inode(inode, inode-\u003ei_mode,\n \t\t\t\t\t be32_to_cpu(file-\u003epermissions.dev));\n \t\t}\n-\t\tinode_set_atime_to_ts(inode, hfsp_mt2ut(file-\u003eaccess_date));\n-\t\tinode_set_mtime_to_ts(inode,\n-\t\t\t\t hfsp_mt2ut(file-\u003econtent_mod_date));\n-\t\tinode_set_ctime_to_ts(inode,\n-\t\t\t\t hfsp_mt2ut(file-\u003eattribute_mod_date));\n-\t\tHFSPLUS_I(inode)-\u003ecreate_date = file-\u003ecreate_date;\n+\n+\t\thfsplus_copy_file2timestamps(file, \u0026timestamps);\n+\t\tres = hfsplus_inode_read_timestamps(inode, \u0026timestamps);\n+\t\tif (res) {\n+\t\t\tres = -EIO;\n+\t\t\tgoto out;\n+\t\t}\n \t} else {\n \t\tpr_err(\"bad catalog entry used to create inode\\n\");\n \t\tres = -EIO;\n@@ -682,12 +817,126 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)\n \treturn res;\n }\n \n+struct hfsplus_xattr_changes {\n+\tbool added;\n+\tbool removed;\n+};\n+\n+/*\n+ * Convert @ts into on-disk timestamp. The timestamp after February 2040\n+ * is stored as HFSPLUS_EXT_TIMESTAMP_MARK with the real value in\n+ * the internal xattr @name. The stale xattr is removed if timestamp\n+ * becomes representable by on-disk field.\n+ */\n+static int hfsplus_inode_save_timestamp(struct inode *inode,\n+\t\t\t\t\tconst char *name, int xattr_bit,\n+\t\t\t\t\tstruct timespec64 ts, __be32 *date,\n+\t\t\t\t\tstruct hfsplus_xattr_changes *xattr)\n+{\n+\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n+\ttime64_t stored;\n+\tint err;\n+\n+\t*date = __hfsp_ut2mt(ts.tv_sec);\n+\n+\tif (hfsp_ut_needs_xattr(ts.tv_sec)) {\n+\t\t/* don't rewrite xattr if nothing has been changed */\n+\t\tif (test_bit(xattr_bit, \u0026hip-\u003eflags)) {\n+\t\t\terr = hfsplus_get_timestamp_xattr(inode-\u003ei_sb,\n+\t\t\t\t\t\t\t inode-\u003ei_ino,\n+\t\t\t\t\t\t\t name,\n+\t\t\t\t\t\t\t \u0026stored);\n+\t\t\tif (!err \u0026\u0026 stored == ts.tv_sec)\n+\t\t\t\treturn 0;\n+\t\t}\n+\n+\t\terr = hfsplus_set_timestamp_xattr(inode, inode-\u003ei_ino,\n+\t\t\t\t\t\t name, ts.tv_sec);\n+\t\tif (err) {\n+\t\t\tclear_bit(xattr_bit, \u0026hip-\u003eflags);\n+\t\t\treturn err;\n+\t\t}\n+\n+\t\tset_bit(xattr_bit, \u0026hip-\u003eflags);\n+\t\txattr-\u003eadded = true;\n+\t} else if (test_bit(xattr_bit, \u0026hip-\u003eflags)) {\n+\t\terr = hfsplus_remove_timestamp_xattr(inode, name);\n+\t\tif (err)\n+\t\t\treturn err;\n+\n+\t\tclear_bit(xattr_bit, \u0026hip-\u003eflags);\n+\t\txattr-\u003eremoved = true;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void hfsplus_inode_save_timestamps(struct inode *inode,\n+\t\t\t\t\t struct hfsplus_timestamps *timestamps,\n+\t\t\t\t\t struct hfsplus_xattr_changes *changes)\n+{\n+\tint res;\n+\n+\t/*\n+\t * Failure of xattr operation is not critical. The timestamp\n+\t * is clamped by HFS_MAX_TIMESTAMP_SECS in such case.\n+\t * But the rest of the catalog record must be saved anyway.\n+\t */\n+\n+\tres = hfsplus_inode_save_timestamp(inode,\n+\t\t\t\t\t XATTR_LINUX_ACCESS_DATE_NAME,\n+\t\t\t\t\t HFSPLUS_I_ATIME_XATTR,\n+\t\t\t\t\t inode_get_atime(inode),\n+\t\t\t\t\t \u0026timestamps-\u003eaccess_date,\n+\t\t\t\t\t changes);\n+\tif (res) {\n+\t\tpr_warn_ratelimited(\"fail to save access date: ino %llu, err %d\\n\",\n+\t\t\t\t inode-\u003ei_ino, res);\n+\t}\n+\n+\tres = hfsplus_inode_save_timestamp(inode,\n+\t\t\t\t\t XATTR_LINUX_CONTENT_MOD_DATE_NAME,\n+\t\t\t\t\t HFSPLUS_I_MTIME_XATTR,\n+\t\t\t\t\t inode_get_mtime(inode),\n+\t\t\t\t\t \u0026timestamps-\u003econtent_mod_date,\n+\t\t\t\t\t changes);\n+\tif (res) {\n+\t\tpr_warn_ratelimited(\"fail to save content mod date: ino %llu, err %d\\n\",\n+\t\t\t\t inode-\u003ei_ino, res);\n+\t}\n+\n+\tres = hfsplus_inode_save_timestamp(inode,\n+\t\t\t\t\t XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,\n+\t\t\t\t\t HFSPLUS_I_CTIME_XATTR,\n+\t\t\t\t\t inode_get_ctime(inode),\n+\t\t\t\t\t \u0026timestamps-\u003eattribute_mod_date,\n+\t\t\t\t\t changes);\n+\tif (res) {\n+\t\tpr_warn_ratelimited(\"fail to save attribute mod date: ino %llu, err %d\\n\",\n+\t\t\t\t inode-\u003ei_ino, res);\n+\t}\n+}\n+\n+static inline __be16\n+hfsplus_update_xattr_exists_flag(struct inode *inode, __be16 flags,\n+\t\t\t\t struct hfsplus_xattr_changes *xattr)\n+{\n+\tif (xattr-\u003eadded)\n+\t\tflags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);\n+\telse if (xattr-\u003eremoved \u0026\u0026 !hfsplus_attr_exists(inode, NULL))\n+\t\tflags \u0026= cpu_to_be16(~HFSPLUS_XATTR_EXISTS);\n+\n+\treturn flags;\n+}\n+\n int hfsplus_cat_write_inode(struct inode *inode)\n {\n \tstruct inode *main_inode = inode;\n \tstruct hfs_btree *tree = HFSPLUS_SB(inode-\u003ei_sb)-\u003ecat_tree;\n \tstruct hfs_find_data fd;\n \thfsplus_cat_entry entry;\n+\tstruct hfsplus_timestamps timestamps = {0};\n+\tstruct hfsplus_xattr_changes changes = {0};\n \tint res = 0;\n \n \thfs_dbg(\"inode-\u003ei_ino %llu\\n\", inode-\u003ei_ino);\n@@ -718,9 +967,15 @@ int hfsplus_cat_write_inode(struct inode *inode)\n \t\t\t\t\tsizeof(struct hfsplus_cat_folder));\n \t\t/* simple node checks? */\n \t\thfsplus_cat_set_perms(inode, \u0026folder-\u003epermissions);\n-\t\tfolder-\u003eaccess_date = hfsp_ut2mt(inode_get_atime(inode));\n-\t\tfolder-\u003econtent_mod_date = hfsp_ut2mt(inode_get_mtime(inode));\n-\t\tfolder-\u003eattribute_mod_date = hfsp_ut2mt(inode_get_ctime(inode));\n+\n+\t\thfsplus_inode_save_timestamps(inode, \u0026timestamps, \u0026changes);\n+\t\tfolder-\u003eaccess_date = timestamps.access_date;\n+\t\tfolder-\u003econtent_mod_date = timestamps.content_mod_date;\n+\t\tfolder-\u003eattribute_mod_date = timestamps.attribute_mod_date;\n+\t\tfolder-\u003eflags = hfsplus_update_xattr_exists_flag(inode,\n+\t\t\t\t\t\t\t\t folder-\u003eflags,\n+\t\t\t\t\t\t\t\t \u0026changes);\n+\n \t\tfolder-\u003evalence = cpu_to_be32(inode-\u003ei_size - 2);\n \t\tif (folder-\u003eflags \u0026 cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {\n \t\t\tfolder-\u003esubfolders =\n@@ -753,9 +1008,15 @@ int hfsplus_cat_write_inode(struct inode *inode)\n \t\t\tfile-\u003eflags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);\n \t\telse\n \t\t\tfile-\u003eflags \u0026= cpu_to_be16(~HFSPLUS_FILE_LOCKED);\n-\t\tfile-\u003eaccess_date = hfsp_ut2mt(inode_get_atime(inode));\n-\t\tfile-\u003econtent_mod_date = hfsp_ut2mt(inode_get_mtime(inode));\n-\t\tfile-\u003eattribute_mod_date = hfsp_ut2mt(inode_get_ctime(inode));\n+\n+\t\thfsplus_inode_save_timestamps(inode, \u0026timestamps, \u0026changes);\n+\t\tfile-\u003eaccess_date = timestamps.access_date;\n+\t\tfile-\u003econtent_mod_date = timestamps.content_mod_date;\n+\t\tfile-\u003eattribute_mod_date = timestamps.attribute_mod_date;\n+\t\tfile-\u003eflags = hfsplus_update_xattr_exists_flag(inode,\n+\t\t\t\t\t\t\t file-\u003eflags,\n+\t\t\t\t\t\t\t \u0026changes);\n+\n \t\thfs_bnode_write(fd.bnode, \u0026entry, fd.entryoffset,\n \t\t\t\t\t sizeof(struct hfsplus_cat_file));\n \t}\ndiff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c\nindex ff7d6b3336a66..b10b53f6f8f9e 100644\n--- a/fs/hfsplus/super.c\n+++ b/fs/hfsplus/super.c\n@@ -86,6 +86,7 @@ struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)\n \tmutex_init(\u0026HFSPLUS_I(inode)-\u003eextents_lock);\n \tHFSPLUS_I(inode)-\u003ersrc_inode = NULL;\n \tHFSPLUS_I(inode)-\u003ecreate_date = 0;\n+\tHFSPLUS_I(inode)-\u003ebirthdate = 0;\n \tHFSPLUS_I(inode)-\u003elinkid = 0;\n \tHFSPLUS_I(inode)-\u003eflags = 0;\n \tHFSPLUS_I(inode)-\u003efs_blocks = 0;\n@@ -511,6 +512,13 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)\n \tif (!sbi-\u003ersrc_clump_blocks)\n \t\tsbi-\u003ersrc_clump_blocks = 1;\n \n+\tsb-\u003es_time_gran = NSEC_PER_SEC;\n+\tsb-\u003es_time_min = HFS_MIN_TIMESTAMP_SECS;\n+\t/*\n+\t * Timestamps after HFS_MAX_TIMESTAMP_SECS are stored in xattrs.\n+\t */\n+\tsb-\u003es_time_max = HFS_MAX_TIMESTAMP_SECS;\n+\n \terr = -EFBIG;\n \tlast_fs_block = sbi-\u003etotal_blocks - 1;\n \tlast_fs_page = (last_fs_block \u003c\u003c sbi-\u003ealloc_blksz_shift) \u003e\u003e\ndiff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c\nindex 21a1c196c71f2..d3b1734496168 100644\n--- a/fs/hfsplus/xattr.c\n+++ b/fs/hfsplus/xattr.c\n@@ -50,6 +50,12 @@ static bool is_known_namespace(const char *name)\n \treturn true;\n }\n \n+static bool is_linux_hfs_internal_xattr(const char *name)\n+{\n+\treturn !strncmp(name, XATTR_LINUX_HFS_PREFIX,\n+\t\t\tXATTR_LINUX_HFS_PREFIX_LEN);\n+}\n+\n static u32 hfsplus_init_header_node(struct inode *attr_file,\n \t\t\t\t\tu32 clump_size,\n \t\t\t\t\tchar *buf, u16 node_size)\n@@ -319,6 +325,19 @@ static int hfsplus_create_attributes_file(struct super_block *sb)\n \n \thfsplus_mark_inode_dirty(attr_file, HFSPLUS_I_ATTR_DIRTY);\n \n+\t/*\n+\t * Store the fork of AttributesFile into the volume header right now.\n+\t * The AttributesFile can be created by hfsplus_cat_write_inode()\n+\t * (timestamps after 2040 are stored in xattrs) in the middle of\n+\t * sync operation. Then, the dirty AttributesFile's inode can be\n+\t * skipped by writeback and the volume header will be committed\n+\t * without AttributesFile. As a result, the AttributesFile will be\n+\t * not opened during the next mount.\n+\t */\n+\thfsplus_inode_write_fork(attr_file, \u0026sbi-\u003es_vhdr-\u003eattr_file);\n+\tset_bit(HFSPLUS_SB_WRITEBACKUP, \u0026sbi-\u003eflags);\n+\thfsplus_mark_mdb_dirty(sb);\n+\n \tsbi-\u003eattr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);\n \tif (!sbi-\u003eattr_tree)\n \t\tpr_err(\"failed to load attributes file\\n\");\n@@ -339,8 +358,7 @@ static int hfsplus_create_attributes_file(struct super_block *sb)\n \treturn err;\n }\n \n-static inline\n-bool is_xattr_operation_supported(struct inode *inode)\n+static inline bool is_xattr_operation_supported(struct inode *inode)\n {\n \tif (HFSPLUS_IS_RSRC(inode))\n \t\treturn false;\n@@ -609,8 +627,9 @@ static ssize_t hfsplus_getxattr_finder_info(struct inode *inode,\n \treturn res;\n }\n \n-ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,\n-\t\t\t void *value, size_t size)\n+static ssize_t __hfsplus_getxattr_nocheck(struct super_block *sb,\n+\t\t\t\t\t u32 cnid, const char *name,\n+\t\t\t\t\t void *value, size_t size)\n {\n \tstruct hfs_find_data fd;\n \thfsplus_attr_entry *entry;\n@@ -619,13 +638,7 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,\n \tu16 record_length = 0;\n \tssize_t res;\n \n-\tif (!is_xattr_operation_supported(inode))\n-\t\treturn -EOPNOTSUPP;\n-\n-\tif (!strcmp_xattr_finder_info(name))\n-\t\treturn hfsplus_getxattr_finder_info(inode, value, size);\n-\n-\tif (!HFSPLUS_SB(inode-\u003ei_sb)-\u003eattr_tree)\n+\tif (!HFSPLUS_SB(sb)-\u003eattr_tree)\n \t\treturn -EOPNOTSUPP;\n \n \tentry = hfsplus_alloc_attr_entry();\n@@ -634,18 +647,18 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,\n \t\treturn -ENOMEM;\n \t}\n \n-\tres = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003eattr_tree, \u0026fd);\n+\tres = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\n \tif (res) {\n \t\tpr_err(\"can't init xattr find struct\\n\");\n \t\tgoto failed_getxattr_init;\n \t}\n \n-\tres = hfsplus_find_attr(inode-\u003ei_sb, inode-\u003ei_ino, name, \u0026fd);\n+\tres = hfsplus_find_attr(sb, cnid, name, \u0026fd);\n \tif (res) {\n \t\tif (res == -ENOENT || res == -ENODATA)\n \t\t\tres = -ENODATA;\n \t\telse\n-\t\t\tpr_err(\"xattr search failed\\n\");\n+\t\t\tpr_err(\"xattr searching failed\\n\");\n \t\tgoto out;\n \t}\n \n@@ -693,6 +706,38 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,\n \treturn res;\n }\n \n+static inline ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,\n+\t\t\t\t\t void *value, size_t size)\n+{\n+\tif (!is_xattr_operation_supported(inode))\n+\t\treturn -EOPNOTSUPP;\n+\n+\tif (!strcmp_xattr_finder_info(name))\n+\t\treturn hfsplus_getxattr_finder_info(inode, value, size);\n+\n+\treturn __hfsplus_getxattr_nocheck(inode-\u003ei_sb, (u32)inode-\u003ei_ino,\n+\t\t\t\t\t name, value, size);\n+}\n+\n+static inline char *hfsplus_build_xattr_name(const char *name,\n+\t\t\t\t\t const char *prefix,\n+\t\t\t\t\t size_t prefixlen)\n+{\n+\tchar *xattr_name;\n+\tsize_t len = NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1;\n+\n+\txattr_name = kzalloc(len, GFP_KERNEL);\n+\tif (!xattr_name)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tif (snprintf(xattr_name, len, \"%s%s\", prefix, name) \u003e= len) {\n+\t\tkfree(xattr_name);\n+\t\treturn ERR_PTR(-ENAMETOOLONG);\n+\t}\n+\n+\treturn xattr_name;\n+}\n+\n ssize_t hfsplus_getxattr(struct inode *inode, const char *name,\n \t\t\t void *value, size_t size,\n \t\t\t const char *prefix, size_t prefixlen)\n@@ -704,13 +749,9 @@ ssize_t hfsplus_getxattr(struct inode *inode, const char *name,\n \t\tinode-\u003ei_ino, name ? name : NULL,\n \t\tprefix ? prefix : NULL);\n \n-\txattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,\n-\t\t\t GFP_KERNEL);\n-\tif (!xattr_name)\n-\t\treturn -ENOMEM;\n-\n-\tstrcpy(xattr_name, prefix);\n-\tstrcpy(xattr_name + prefixlen, name);\n+\txattr_name = hfsplus_build_xattr_name(name, prefix, prefixlen);\n+\tif (IS_ERR(xattr_name))\n+\t\treturn PTR_ERR(xattr_name);\n \n \tres = __hfsplus_getxattr(inode, xattr_name, value, size);\n \tkfree(xattr_name);\n@@ -718,7 +759,114 @@ ssize_t hfsplus_getxattr(struct inode *inode, const char *name,\n \thfs_dbg(\"finished: res %d\\n\", res);\n \n \treturn res;\n+}\n+\n+static ssize_t hfsplus_getxattr_nocheck(struct super_block *sb, u32 cnid,\n+\t\t\t\t\tconst char *name,\n+\t\t\t\t\tvoid *value, size_t size,\n+\t\t\t\t\tconst char *prefix, size_t prefixlen)\n+{\n+\tint res;\n+\tchar *xattr_name;\n \n+\thfs_dbg(\"cnid %u, name %s, prefix %s\\n\",\n+\t\tcnid, name ? name : NULL,\n+\t\tprefix ? prefix : NULL);\n+\n+\txattr_name = hfsplus_build_xattr_name(name, prefix, prefixlen);\n+\tif (IS_ERR(xattr_name))\n+\t\treturn PTR_ERR(xattr_name);\n+\n+\tres = __hfsplus_getxattr_nocheck(sb, cnid, xattr_name, value, size);\n+\tkfree(xattr_name);\n+\n+\thfs_dbg(\"finished: res %d\\n\", res);\n+\n+\treturn res;\n+}\n+\n+/*\n+ * Get the timestamp stored in the internal xattr @name\n+ * of catalog record @cnid. The caller can hold the catalog tree lock.\n+ */\n+int hfsplus_get_timestamp_xattr(struct super_block *sb, u32 cnid,\n+\t\t\t\tconst char *name, time64_t *ts)\n+{\n+\t__be64 value;\n+\tssize_t res;\n+\n+\tres = hfsplus_getxattr_nocheck(sb, cnid, name,\n+\t\t\t\t\t\u0026value, sizeof(value),\n+\t\t\t\t\tXATTR_LINUX_HFS_PREFIX,\n+\t\t\t\t\tXATTR_LINUX_HFS_PREFIX_LEN);\n+\tif (res \u003c 0)\n+\t\treturn res;\n+\n+\tif (res != sizeof(value))\n+\t\treturn -EIO;\n+\n+\t*ts = (time64_t)be64_to_cpu(value);\n+\treturn 0;\n+}\n+\n+/*\n+ * Store the timestamp @ts into the internal xattr @name of catalog\n+ * record @cnid. The caller must hold the catalog tree lock and it is\n+ * caller's responsibility to set HFSPLUS_XATTR_EXISTS flag in\n+ * the catalog record.\n+ */\n+int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,\n+\t\t\t\tconst char *name, time64_t ts)\n+{\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\tchar xattr_name[XATTR_LINUX_HFS_NAME_MAX];\n+\t__be64 value = cpu_to_be64(ts);\n+\tint err;\n+\n+\thfs_dbg(\"ino %llu, cnid %u, name %s, ts %lld\\n\",\n+\t\tinode-\u003ei_ino, cnid, name, ts);\n+\n+\tif (!HFSPLUS_SB(sb)-\u003eattr_tree) {\n+\t\terr = hfsplus_create_attributes_file(sb);\n+\t\tif (unlikely(err))\n+\t\t\treturn err;\n+\n+\t\tif (!HFSPLUS_SB(sb)-\u003eattr_tree)\n+\t\t\treturn -EIO;\n+\t}\n+\n+\tif (snprintf(xattr_name, sizeof(xattr_name), \"%s%s\",\n+\t\t XATTR_LINUX_HFS_PREFIX, name) \u003e= sizeof(xattr_name))\n+\t\treturn -ENAMETOOLONG;\n+\n+\treturn hfsplus_set_attr_cnid(inode, cnid, xattr_name,\n+\t\t\t\t \u0026value, sizeof(value));\n+}\n+\n+/*\n+ * Remove the internal xattr @name of @inode. The caller must hold\n+ * the catalog tree lock and it is caller's responsibility to update\n+ * HFSPLUS_XATTR_EXISTS flag in the catalog record.\n+ */\n+int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name)\n+{\n+\tchar xattr_name[XATTR_LINUX_HFS_NAME_MAX];\n+\tint err;\n+\n+\thfs_dbg(\"ino %llu, name %s\\n\", inode-\u003ei_ino, name);\n+\n+\tif (!HFSPLUS_SB(inode-\u003ei_sb)-\u003eattr_tree)\n+\t\treturn 0;\n+\n+\tif (snprintf(xattr_name, sizeof(xattr_name), \"%s%s\",\n+\t\t XATTR_LINUX_HFS_PREFIX, name) \u003e= sizeof(xattr_name))\n+\t\treturn -ENAMETOOLONG;\n+\n+\terr = hfsplus_delete_attr(inode, xattr_name);\n+\tif (err == -ENOENT || err == -ENODATA)\n+\t\terr = 0;\n+\n+\treturn err;\n }\n \n static inline int can_list(const char *xattr_name)\n@@ -726,6 +874,10 @@ static inline int can_list(const char *xattr_name)\n \tif (!xattr_name)\n \t\treturn 0;\n \n+\t/* Internal xattrs of the driver are hidden */\n+\tif (is_linux_hfs_internal_xattr(xattr_name))\n+\t\treturn 0;\n+\n \treturn strncmp(xattr_name, XATTR_TRUSTED_PREFIX,\n \t\t\tXATTR_TRUSTED_PREFIX_LEN) ||\n \t\t\t\tcapable(CAP_SYS_ADMIN);\n@@ -998,6 +1150,10 @@ static int hfsplus_osx_getxattr(const struct xattr_handler *handler,\n \tif (is_known_namespace(name))\n \t\treturn -EOPNOTSUPP;\n \n+\t/* Internal xattrs of the driver are hidden */\n+\tif (is_linux_hfs_internal_xattr(name))\n+\t\treturn -EOPNOTSUPP;\n+\n \t/*\n \t * osx is the namespace we use to indicate an unprefixed\n \t * attribute on the filesystem (like the ones that OS X\n@@ -1020,6 +1176,10 @@ static int hfsplus_osx_setxattr(const struct xattr_handler *handler,\n \tif (is_known_namespace(name))\n \t\treturn -EOPNOTSUPP;\n \n+\t/* Internal xattrs of the driver cannot be changed by user */\n+\tif (is_linux_hfs_internal_xattr(name))\n+\t\treturn -EOPNOTSUPP;\n+\n \t/*\n \t * osx is the namespace we use to indicate an unprefixed\n \t * attribute on the filesystem (like the ones that OS X\ndiff --git a/fs/hfsplus/xattr.h b/fs/hfsplus/xattr.h\nindex 15cc55e414100..8f6283f85f133 100644\n--- a/fs/hfsplus/xattr.h\n+++ b/fs/hfsplus/xattr.h\n@@ -12,6 +12,24 @@\n \n #include \u003clinux/xattr.h\u003e\n \n+/*\n+ * Internal xattrs of Linux HFS+ driver. Timestamps beyond\n+ * HFS_MAX_TIMESTAMP_SECS (February 2040) cannot be represented by\n+ * 32-bit on-disk fields. Such timestamp is stored as the maximal value\n+ * (HFSPLUS_EXT_TIMESTAMP_MARK) in the catalog record and the real value\n+ * is kept in the xattr as big-endian 64-bit seconds since\n+ * 00:00 GMT, Jan. 1, 1970.\n+ */\n+#define XATTR_LINUX_HFS_PREFIX \"linux_hfs.\"\n+#define XATTR_LINUX_HFS_PREFIX_LEN \\\n+\t(sizeof(XATTR_LINUX_HFS_PREFIX) - 1)\n+#define XATTR_LINUX_HFS_NAME_MAX\t64\n+#define XATTR_LINUX_CREATE_DATE_NAME \"create_date_u64\"\n+#define XATTR_LINUX_CONTENT_MOD_DATE_NAME \"content_mod_date_u64\"\n+#define XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME \"attribute_mod_date_u64\"\n+#define XATTR_LINUX_ACCESS_DATE_NAME \"access_date_u64\"\n+#define XATTR_LINUX_BACKUP_DATE_NAME \"backup_date_u64\"\n+\n extern const struct xattr_handler hfsplus_xattr_osx_handler;\n extern const struct xattr_handler hfsplus_xattr_user_handler;\n extern const struct xattr_handler hfsplus_xattr_trusted_handler;\n@@ -23,16 +41,18 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,\n \t\t\tconst void *value, size_t size, int flags);\n \n int hfsplus_setxattr(struct inode *inode, const char *name,\n-\t\t\t\t const void *value, size_t size, int flags,\n-\t\t\t\t const char *prefix, size_t prefixlen);\n-\n-ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,\n-\t\t\t void *value, size_t size);\n-\n+\t\t const void *value, size_t size, int flags,\n+\t\t const char *prefix, size_t prefixlen);\n ssize_t hfsplus_getxattr(struct inode *inode, const char *name,\n \t\t\t void *value, size_t size,\n \t\t\t const char *prefix, size_t prefixlen);\n \n+int hfsplus_get_timestamp_xattr(struct super_block *sb, u32 cnid,\n+\t\t\t\tconst char *name, time64_t *ts);\n+int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,\n+\t\t\t\tconst char *name, time64_t ts);\n+int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name);\n+\n ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);\n \n int hfsplus_init_security(struct inode *inode, struct inode *dir,\ndiff --git a/include/linux/hfs_common.h b/include/linux/hfs_common.h\nindex d6a615e74b26e..d4e91dea23628 100644\n--- a/include/linux/hfs_common.h\n+++ b/include/linux/hfs_common.h\n@@ -667,4 +667,17 @@ typedef union {\n \tstruct hfsplus_attr_key attr;\n } __packed hfsplus_btree_key;\n \n+/*\n+ * There are two time systems. Both are based on seconds since\n+ * a particular time/date.\n+ *\tUnix:\tsigned little-endian since 00:00 GMT, Jan. 1, 1970\n+ *\tmac:\tunsigned big-endian since 00:00 GMT, Jan. 1, 1904\n+ */\n+#define HFS_UTC_OFFSET 2082844800U\n+\n+/* January 1, 1904, 00:00:00 UTC */\n+#define HFS_MIN_TIMESTAMP_SECS\t\t-2082844800LL\n+/* February 6, 2040, 06:28:15 UTC */\n+#define HFS_MAX_TIMESTAMP_SECS\t\t2212122495LL\n+\n #endif /* _HFS_COMMON_H_ */\n"
} |
| 2/1 | 2026/10/14 04:39 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"HFSPLUS_FS",
"BLOCK"
],
"FocusSymbols": [
"hfsplus_read_timestamp",
"hfsplus_get_timestamp_xattr",
"hfsplus_set_timestamp_xattr",
"hfsplus_remove_timestamp_xattr",
"hfsplus_set_attr_cnid",
"hfsplus_cat_write_inode",
"hfsplus_cat_read_inode",
"hfsplus_create_cat"
],
"Reasoning": "The patch modifies the HFS+ filesystem driver to extend timestamp support past February 2040 using hidden internal xattrs. This touches core filesystem operations including catalog creation, inode reading/writing, on-demand attributes file creation, and btree manipulation during inode writeback. The code is fully reachable in standard QEMU/virtualized environments by mounting or manipulating crafted HFS+ filesystem images and warrants fuzzing.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit b4c9108390579ca1cf61016eb15d8e4bd23c1cac
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Oct 14 04:39:58 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h
index e250f87a5e336..659b0ba733d49 100644
--- a/fs/hfs/hfs_fs.h
+++ b/fs/hfs/hfs_fs.h
@@ -255,19 +255,6 @@ extern int hfs_mac2asc(struct super_block *sb,
/* super.c */
extern void hfs_mark_mdb_dirty(struct super_block *sb);
-/*
- * There are two time systems. Both are based on seconds since
- * a particular time/date.
- * Unix: signed little-endian since 00:00 GMT, Jan. 1, 1970
- * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
- *
- * HFS implementations are highly inconsistent, this one matches the
- * traditional behavior of 64-bit Linux, giving the most useful
- * time range between 1970 and 2106, by treating any on-disk timestamp
- * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
- */
-#define HFS_UTC_OFFSET 2082844800U
-
static inline time64_t __hfs_m_to_utime(__be32 mt)
{
time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
diff --git a/fs/hfsplus/Makefile b/fs/hfsplus/Makefile
index f2a9ae697e811..7cb0a5ef9831c 100644
--- a/fs/hfsplus/Makefile
+++ b/fs/hfsplus/Makefile
@@ -10,4 +10,4 @@ hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btre
attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
# KUnit tests
-obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += unicode_test.o
+obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += hfsplus_unicode_test.o hfsplus_time_test.o
diff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c
index 7c2e589d45538..51b18d780f2c0 100644
--- a/fs/hfsplus/attributes.c
+++ b/fs/hfsplus/attributes.c
@@ -206,7 +206,8 @@ int hfsplus_attr_exists(struct inode *inode, const char *name)
}
static
-int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
+int hfsplus_create_attr_nolock(struct inode *inode, u32 cnid,
+ const char *name,
const void *value, size_t size,
struct hfs_find_data *fd,
hfsplus_attr_entry *entry_ptr)
@@ -215,12 +216,12 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
int entry_size;
int err;
- hfs_dbg("name %s, ino %llu\n",
- name ? name : NULL, inode->i_ino);
+ hfs_dbg("name %s, ino %llu, cnid %u\n",
+ name ? name : NULL, inode->i_ino, cnid);
if (name) {
err = hfsplus_attr_build_key(sb, fd->search_key,
- inode->i_ino, name);
+ cnid, name);
if (err)
return err;
} else
@@ -229,7 +230,7 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
/* Mac OS X supports only inline data attributes. */
entry_size = hfsplus_attr_build_record(entry_ptr,
HFSPLUS_ATTR_INLINE_DATA,
- inode->i_ino,
+ cnid,
value, size);
if (entry_size == HFSPLUS_INVALID_ATTR_RECORD) {
if (size > HFSPLUS_MAX_INLINE_DATA_SIZE)
@@ -289,8 +290,8 @@ int hfsplus_create_attr(struct inode *inode,
if (err)
goto failed_create_attr;
- err = hfsplus_create_attr_nolock(inode, name, value, size,
- &fd, entry_ptr);
+ err = hfsplus_create_attr_nolock(inode, (u32)inode->i_ino, name,
+ value, size, &fd, entry_ptr);
if (err)
goto failed_create_attr;
@@ -347,18 +348,19 @@ static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,
}
static
-int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,
+int hfsplus_delete_attr_nolock(struct inode *inode, u32 cnid,
+ const char *name,
struct hfs_find_data *fd)
{
struct super_block *sb = inode->i_sb;
int err;
- hfs_dbg("name %s, ino %llu\n",
- name ? name : NULL, inode->i_ino);
+ hfs_dbg("name %s, ino %llu, cnid %u\n",
+ name ? name : NULL, inode->i_ino, cnid);
if (name) {
err = hfsplus_attr_build_key(sb, fd->search_key,
- inode->i_ino, name);
+ cnid, name);
if (err)
return err;
} else {
@@ -373,7 +375,7 @@ int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,
} else if (err)
return err;
- err = __hfsplus_delete_attr(inode, inode->i_ino, fd);
+ err = __hfsplus_delete_attr(inode, cnid, fd);
if (err)
return err;
@@ -403,7 +405,7 @@ int hfsplus_delete_attr(struct inode *inode, const char *name)
if (err)
goto out;
- err = hfsplus_delete_attr_nolock(inode, name, &fd);
+ err = hfsplus_delete_attr_nolock(inode, (u32)inode->i_ino, name, &fd);
if (err)
goto out;
@@ -481,12 +483,12 @@ int hfsplus_replace_attr(struct inode *inode,
if (err)
goto failed_replace_attr;
- err = hfsplus_delete_attr_nolock(inode, name, &fd);
+ err = hfsplus_delete_attr_nolock(inode, (u32)inode->i_ino, name, &fd);
if (err)
goto failed_replace_attr;
- err = hfsplus_create_attr_nolock(inode, name, value, size,
- &fd, entry_ptr);
+ err = hfsplus_create_attr_nolock(inode, (u32)inode->i_ino, name,
+ value, size, &fd, entry_ptr);
if (err)
goto failed_replace_attr;
@@ -497,3 +499,54 @@ int hfsplus_replace_attr(struct inode *inode,
hfsplus_destroy_attr_entry(entry_ptr);
return err;
}
+
+/*
+ * Create or replace the xattr @name of catalog record @cnid.
+ * The @inode is used only for access to the superblock and for
+ * marking the attributes tree as dirty. It is the caller's
+ * responsibility to set HFSPLUS_XATTR_EXISTS in the catalog record.
+ */
+int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,
+ const char *name,
+ const void *value, size_t size)
+{
+ struct super_block *sb = inode->i_sb;
+ struct hfs_find_data fd;
+ hfsplus_attr_entry *entry_ptr;
+ int err = 0;
+
+ hfs_dbg("name %s, ino %llu, cnid %u\n",
+ name ? name : NULL, inode->i_ino, cnid);
+
+ if (!HFSPLUS_SB(sb)->attr_tree) {
+ pr_err("attributes file doesn't exist\n");
+ return -EINVAL;
+ }
+
+ entry_ptr = hfsplus_alloc_attr_entry();
+ if (!entry_ptr)
+ return -ENOMEM;
+
+ err = hfs_find_init(HFSPLUS_SB(sb)->attr_tree, &fd);
+ if (err)
+ goto failed_init_set_attr;
+
+ /* Fail early and avoid ENOSPC during the btree operation */
+ err = hfs_bmap_reserve(fd.tree, fd.tree->depth + 1);
+ if (err)
+ goto failed_set_attr;
+
+ err = hfsplus_delete_attr_nolock(inode, cnid, name, &fd);
+ if (err && err != -ENOENT && err != -ENODATA)
+ goto failed_set_attr;
+
+ err = hfsplus_create_attr_nolock(inode, cnid, name,
+ value, size, &fd, entry_ptr);
+
+failed_set_attr:
+ hfs_find_exit(&fd);
+
+failed_init_set_attr:
+ hfsplus_destroy_attr_entry(entry_ptr);
+ return err;
+}
diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
index fe11c4b6dd997..d710419db3591 100644
--- a/fs/hfsplus/catalog.c
+++ b/fs/hfsplus/catalog.c
@@ -12,6 +12,7 @@
#include "hfsplus_fs.h"
#include "hfsplus_raw.h"
+#include "xattr.h"
int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1,
const hfsplus_btree_key *k2)
@@ -102,10 +103,63 @@ void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms)
perms->dev = 0;
}
+static void hfsplus_copy_timestamps2folder(struct hfsplus_timestamps *timestamps,
+ struct hfsplus_cat_folder *folder)
+{
+ folder->create_date = timestamps->create_date;
+ folder->content_mod_date = timestamps->content_mod_date;
+ folder->attribute_mod_date = timestamps->attribute_mod_date;
+ folder->access_date = timestamps->access_date;
+}
+
+static void hfsplus_copy_timestamps2file(struct hfsplus_timestamps *timestamps,
+ struct hfsplus_cat_file *file)
+{
+ file->create_date = timestamps->create_date;
+ file->content_mod_date = timestamps->content_mod_date;
+ file->attribute_mod_date = timestamps->attribute_mod_date;
+ file->access_date = timestamps->access_date;
+}
+
+/*
+ * Set creation date of new inode. The creation date after February 2040
+ * is stored as HFSPLUS_EXT_TIMESTAMP_MARK in the catalog record. The real
+ * value is saved into internal xattr by hfsplus_create_cat().
+ */
+static void hfsplus_set_create_date(struct inode *inode,
+ struct hfsplus_timestamps *timestamps)
+{
+ time64_t ut = ktime_get_real_seconds();
+ __be32 create_date = __hfsp_ut2mt(ut);
+
+ HFSPLUS_I(inode)->birthdate = ut;
+ HFSPLUS_I(inode)->create_date = create_date;
+
+ timestamps->create_date = create_date;
+ timestamps->content_mod_date = create_date;
+ timestamps->attribute_mod_date = create_date;
+ timestamps->access_date = create_date;
+}
+
+/*
+ * Real creation date of new catalog record. The hard link record
+ * inherits the creation date of the hidden directory.
+ */
+static time64_t hfsplus_cat_record_birthdate(u32 cnid, struct inode *inode)
+{
+ struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+
+ if (!S_ISDIR(inode->i_mode) && cnid != inode->i_ino)
+ return HFSPLUS_I(sbi->hidden_dir)->birthdate;
+
+ return HFSPLUS_I(inode)->birthdate;
+}
+
static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
- u32 cnid, struct inode *inode)
+ u32 cnid, struct inode *inode)
{
struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+ struct hfsplus_timestamps timestamps = {0};
if (S_ISDIR(inode->i_mode)) {
struct hfsplus_cat_folder *folder;
@@ -116,11 +170,12 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags))
folder->flags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);
folder->id = cpu_to_be32(inode->i_ino);
- HFSPLUS_I(inode)->create_date =
- folder->create_date =
- folder->content_mod_date =
- folder->attribute_mod_date =
- folder->access_date = hfsp_now2mt();
+
+ hfsplus_set_create_date(inode, ×tamps);
+ hfsplus_copy_timestamps2folder(×tamps, folder);
+ if (hfsp_ut_needs_xattr(HFSPLUS_I(inode)->birthdate))
+ folder->flags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);
+
hfsplus_cat_set_perms(inode, &folder->permissions);
if (inode == sbi->hidden_dir)
/* invisible and namelocked */
@@ -134,11 +189,23 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
file->type = cpu_to_be16(HFSPLUS_FILE);
file->flags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS);
file->id = cpu_to_be32(cnid);
- HFSPLUS_I(inode)->create_date =
- file->create_date =
- file->content_mod_date =
- file->attribute_mod_date =
- file->access_date = hfsp_now2mt();
+
+ if (cnid == inode->i_ino) {
+ hfsplus_set_create_date(inode, ×tamps);
+ } else {
+ /*
+ * Hard link record: don't change creation date
+ * of the linked inode.
+ */
+ __be32 now = __hfsp_ut2mt(ktime_get_real_seconds());
+
+ timestamps.create_date = now;
+ timestamps.content_mod_date = now;
+ timestamps.attribute_mod_date = now;
+ timestamps.access_date = now;
+ }
+ hfsplus_copy_timestamps2file(×tamps, file);
+
if (cnid == inode->i_ino) {
hfsplus_cat_set_perms(inode, &file->permissions);
if (S_ISLNK(inode->i_mode)) {
@@ -169,6 +236,10 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
file->permissions.dev =
cpu_to_be32(HFSPLUS_I(inode)->linkid);
}
+
+ if (hfsp_ut_needs_xattr(hfsplus_cat_record_birthdate(cnid, inode)))
+ file->flags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);
+
return sizeof(*file);
}
}
@@ -256,6 +327,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
struct super_block *sb = dir->i_sb;
struct hfs_find_data fd;
hfsplus_cat_entry entry;
+ time64_t birthdate;
int entry_size;
int err;
@@ -309,6 +381,22 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
if (err)
goto err1;
+ birthdate = hfsplus_cat_record_birthdate(cnid, inode);
+ if (hfsp_ut_needs_xattr(birthdate)) {
+ /*
+ * Failure is not critical: the creation date
+ * will be read as HFS_MAX_TIMESTAMP_SECS.
+ */
+ err = hfsplus_set_timestamp_xattr(inode, cnid,
+ XATTR_LINUX_CREATE_DATE_NAME,
+ birthdate);
+ if (err) {
+ pr_warn("fail to save creation date: cnid %u, err %d\n",
+ cnid, err);
+ err = 0;
+ }
+ }
+
dir->i_size++;
if (S_ISDIR(inode->i_mode))
hfsplus_subfolders_inc(dir);
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 51fcba2e6d403..af0520ebced70 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -26,6 +26,43 @@ static inline void hfsplus_instantiate(struct dentry *dentry,
d_instantiate(dentry, inode);
}
+/*
+ * Check that creation date of catalog record @cnid is identical to
+ * creation date of @inode. If the creation date is after February 2040,
+ * then the real value is compared by means of internal xattr.
+ */
+static inline bool is_create_date_identical(struct inode *inode,
+ u32 cnid, __be32 create_date)
+{
+ time64_t timestamp;
+ bool has_xattr;
+ int err;
+
+ if (create_date != HFSPLUS_I(inode)->create_date)
+ return false;
+
+ if (!hfsp_mt_is_ext_timestamp(create_date))
+ return true;
+
+ err = hfsplus_read_timestamp(inode->i_sb, cnid,
+ XATTR_LINUX_CREATE_DATE_NAME,
+ create_date, ×tamp, &has_xattr);
+ if (err) {
+ pr_err("timestamp extraction failure: cnid %u, err %d\n",
+ cnid, err);
+ return false;
+ }
+
+ /*
+ * The record without xattr (for example, created by Mac OS X)
+ * cannot be distinguished by means of 64-bit timestamp.
+ */
+ if (!has_xattr)
+ return true;
+
+ return timestamp == HFSPLUS_I(inode)->birthdate;
+}
+
/* Find the entry inside dir named dentry->d_name */
static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags)
@@ -78,12 +115,12 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
entry.file.user_info.fdCreator ==
cpu_to_be32(HFSP_HFSPLUS_CREATOR) &&
HFSPLUS_SB(sb)->hidden_dir &&
- (entry.file.create_date ==
- HFSPLUS_I(HFSPLUS_SB(sb)->hidden_dir)->
- create_date ||
- entry.file.create_date ==
- HFSPLUS_I(d_inode(sb->s_root))->
- create_date)) {
+ (is_create_date_identical(
+ HFSPLUS_SB(sb)->hidden_dir,
+ cnid, entry.file.create_date) ||
+ is_create_date_identical(
+ d_inode(sb->s_root),
+ cnid, entry.file.create_date))) {
struct qstr str;
char name[32];
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 1e5b58e6a13fc..637bba65568ec 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -175,6 +175,13 @@ static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
return sb->s_fs_info;
}
+struct hfsplus_timestamps {
+ __be32 create_date;
+ __be32 content_mod_date;
+ __be32 attribute_mod_date;
+ __be32 access_date;
+ __be32 backup_date;
+};
struct hfsplus_inode_info {
atomic_t opencnt;
@@ -196,7 +203,8 @@ struct hfsplus_inode_info {
* Immutable data.
*/
struct inode *rsrc_inode;
- __be32 create_date;
+ __be32 create_date; /* on-disk (maybe clamped) creation date */
+ time64_t birthdate; /* real creation date (seconds since 1970) */
/*
* Protected by sbi->vh_mutex.
@@ -227,6 +235,9 @@ struct hfsplus_inode_info {
#define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
#define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
#define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
+#define HFSPLUS_I_ATIME_XATTR 5 /* access date is stored in xattr */
+#define HFSPLUS_I_MTIME_XATTR 6 /* content mod date is stored in xattr */
+#define HFSPLUS_I_CTIME_XATTR 7 /* attribute mod date is stored in xattr */
#define HFSPLUS_IS_RSRC(inode) \
test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
@@ -351,6 +362,9 @@ int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
int hfsplus_replace_attr(struct inode *inode,
const char *name,
const void *value, size_t size);
+int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,
+ const char *name,
+ const void *value, size_t size);
/* bitmap.c */
int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset,
@@ -467,6 +481,9 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
int hfsplus_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
int hfsplus_fileattr_set(struct mnt_idmap *idmap,
struct dentry *dentry, struct file_kattr *fa);
+int hfsplus_read_timestamp(struct super_block *sb, u32 cnid,
+ const char *name, __be32 mt,
+ time64_t *ut, bool *has_xattr);
/* ioctl.c */
long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
@@ -532,23 +549,42 @@ int hfsplus_brec_read_cat(struct hfs_find_data *fd, hfsplus_cat_entry *entry);
/*
* time helpers: convert between 1904-base and 1970-base timestamps
*
- * HFS+ implementations are highly inconsistent, this one matches the
- * traditional behavior of 64-bit Linux, giving the most useful
- * time range between 1970 and 2106, by treating any on-disk timestamp
- * under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
+ * The on-disk 32-bit timestamps cover the range from
+ * HFS_MIN_TIMESTAMP_SECS (Jan. 1, 1904) till HFS_MAX_TIMESTAMP_SECS
+ * (Feb. 6, 2040). The timestamps out of this range are clamped.
+ * The on-disk value HFSPLUS_EXT_TIMESTAMP_MARK (maximal value) means
+ * that real timestamp could be stored in the internal xattr of
+ * the catalog record. It is Linux specific extension of
+ * HFS+ on-disk layout. It makes possible to support timestamps
+ * till HFSPLUS_MAX_TIMESTAMP_SECS.
*/
-#define HFSPLUS_UTC_OFFSET 2082844800U
+#define HFSPLUS_EXT_TIMESTAMP_MARK cpu_to_be32(U32_MAX)
+#define HFSPLUS_MAX_TIMESTAMP_SECS TIME64_MAX
static inline time64_t __hfsp_mt2ut(__be32 mt)
{
- time64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET);
+ time64_t ut = (time64_t)be32_to_cpu(mt) - HFS_UTC_OFFSET;
return ut;
}
static inline __be32 __hfsp_ut2mt(time64_t ut)
{
- return cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET);
+ ut = clamp_t(time64_t, ut,
+ HFS_MIN_TIMESTAMP_SECS, HFS_MAX_TIMESTAMP_SECS);
+ ut += HFS_UTC_OFFSET;
+
+ return cpu_to_be32(lower_32_bits(ut));
+}
+
+static inline bool hfsp_ut_needs_xattr(time64_t ut)
+{
+ return ut >= HFS_MAX_TIMESTAMP_SECS;
+}
+
+static inline bool hfsp_mt_is_ext_timestamp(__be32 mt)
+{
+ return mt == HFSPLUS_EXT_TIMESTAMP_MARK;
}
static inline enum hfsplus_btree_mutex_classes
diff --git a/fs/hfsplus/hfsplus_time_test.c b/fs/hfsplus/hfsplus_time_test.c
new file mode 100644
index 0000000000000..4b3312dc0048b
--- /dev/null
+++ b/fs/hfsplus/hfsplus_time_test.c
@@ -0,0 +1,354 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit tests for HFS+ date/time conversion
+ *
+ * Copyright (C) 2026 Viacheslav Dubeyko <slava@dubeyko.com>
+ */
+
+#include <kunit/test.h>
+#include "hfsplus_fs.h"
+#include "xattr.h"
+
+/* January 1, 1970, 00:00:00 UTC */
+#define TEST_UNIX_EPOCH_SECS 0LL
+/* December 31, 1969, 23:59:59 UTC */
+#define TEST_BEFORE_UNIX_EPOCH_SECS -1LL
+/* January 1, 2000, 00:00:00 UTC */
+#define TEST_Y2000_SECS 946684800LL
+/* January 19, 2038, 03:14:08 UTC (signed 32-bit overflow) */
+#define TEST_Y2038_SECS 2147483648LL
+/* January 1, 2026, 00:00:00 UTC */
+#define TEST_Y2026_SECS 1767225600LL
+/* January 1, 2100, 00:00:00 UTC */
+#define TEST_Y2100_SECS 4102444800LL
+/* January 1, 1900, 00:00:00 UTC */
+#define TEST_Y1900_SECS -2208988800LL
+
+static u32 mt_raw(__be32 mt)
+{
+ return be32_to_cpu(mt);
+}
+
+/* Test the time range constants */
+static void hfsplus_time_constants_test(struct kunit *test)
+{
+ /* 32-bit unsigned on-disk field covers exactly U32_MAX seconds */
+ KUNIT_EXPECT_EQ(test, (s64)U32_MAX,
+ HFS_MAX_TIMESTAMP_SECS - HFS_MIN_TIMESTAMP_SECS);
+ KUNIT_EXPECT_EQ(test, -(s64)HFS_UTC_OFFSET, HFS_MIN_TIMESTAMP_SECS);
+
+ /* xattrs extend the supported range beyond February 2040 */
+ KUNIT_EXPECT_GT(test, (s64)HFSPLUS_MAX_TIMESTAMP_SECS,
+ (s64)HFS_MAX_TIMESTAMP_SECS);
+
+ /* the extended timestamp mark is the maximal on-disk value */
+ KUNIT_EXPECT_EQ(test, U32_MAX, mt_raw(HFSPLUS_EXT_TIMESTAMP_MARK));
+}
+
+/* Test conversion of on-disk (1904-based) timestamp into 1970-based one */
+static void hfsplus_mt2ut_test(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, HFS_MIN_TIMESTAMP_SECS,
+ __hfsp_mt2ut(cpu_to_be32(0)));
+ KUNIT_EXPECT_EQ(test, TEST_UNIX_EPOCH_SECS,
+ __hfsp_mt2ut(cpu_to_be32(HFS_UTC_OFFSET)));
+ KUNIT_EXPECT_EQ(test, TEST_BEFORE_UNIX_EPOCH_SECS,
+ __hfsp_mt2ut(cpu_to_be32(HFS_UTC_OFFSET - 1)));
+ KUNIT_EXPECT_EQ(test, TEST_Y2000_SECS,
+ __hfsp_mt2ut(cpu_to_be32(3029529600U)));
+ KUNIT_EXPECT_EQ(test, TEST_Y2026_SECS,
+ __hfsp_mt2ut(cpu_to_be32(3850070400U)));
+ KUNIT_EXPECT_EQ(test, TEST_Y2038_SECS,
+ __hfsp_mt2ut(cpu_to_be32(4230328448U)));
+ KUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS,
+ __hfsp_mt2ut(cpu_to_be32(U32_MAX)));
+ KUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS,
+ __hfsp_mt2ut(HFSPLUS_EXT_TIMESTAMP_MARK));
+}
+
+/* Test conversion of 1970-based timestamp into on-disk (1904-based) one */
+static void hfsplus_ut2mt_test(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(HFS_MIN_TIMESTAMP_SECS)));
+ KUNIT_EXPECT_EQ(test, HFS_UTC_OFFSET,
+ mt_raw(__hfsp_ut2mt(TEST_UNIX_EPOCH_SECS)));
+ KUNIT_EXPECT_EQ(test, 3029529600U,
+ mt_raw(__hfsp_ut2mt(TEST_Y2000_SECS)));
+ KUNIT_EXPECT_EQ(test, 3850070400U,
+ mt_raw(__hfsp_ut2mt(TEST_Y2026_SECS)));
+ KUNIT_EXPECT_EQ(test, 4230328448U,
+ mt_raw(__hfsp_ut2mt(TEST_Y2038_SECS)));
+ KUNIT_EXPECT_EQ(test, U32_MAX - 1,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS - 1)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS)));
+}
+
+/*
+ * Test timestamps before January 1, 1970 (xfstests generic/258).
+ * The old logic added HFS_UTC_OFFSET to lower 32 bits of negative
+ * value and produced completely wrong result.
+ */
+static void hfsplus_ut2mt_before_1970_test(struct kunit *test)
+{
+ time64_t ut;
+
+ KUNIT_EXPECT_EQ(test, HFS_UTC_OFFSET - 1,
+ mt_raw(__hfsp_ut2mt(TEST_BEFORE_UNIX_EPOCH_SECS)));
+
+ /* January 1, 1960, 00:00:00 UTC */
+ ut = -315619200LL;
+ KUNIT_EXPECT_EQ(test, ut, __hfsp_mt2ut(__hfsp_ut2mt(ut)));
+
+ /* January 1, 1904, 00:00:01 UTC */
+ ut = HFS_MIN_TIMESTAMP_SECS + 1;
+ KUNIT_EXPECT_EQ(test, 1U, mt_raw(__hfsp_ut2mt(ut)));
+ KUNIT_EXPECT_EQ(test, ut, __hfsp_mt2ut(__hfsp_ut2mt(ut)));
+}
+
+/* Test that out-of-range timestamps are clamped instead of wrapped */
+static void hfsplus_ut2mt_clamp_test(struct kunit *test)
+{
+ /* below January 1, 1904 */
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(HFS_MIN_TIMESTAMP_SECS - 1)));
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(TEST_Y1900_SECS)));
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(TIME64_MIN)));
+
+ /* after February 6, 2040 */
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS + 1)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(TEST_Y2100_SECS)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFSPLUS_MAX_TIMESTAMP_SECS)));
+
+ /* lower 32 bits of these values would wrap into small dates */
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS +
+ (s64)U32_MAX + 1)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(1LL << 32)));
+}
+
+/* Test that representable timestamps survive the round trip */
+static void hfsplus_time_roundtrip_test(struct kunit *test)
+{
+ static const time64_t values[] = {
+ HFS_MIN_TIMESTAMP_SECS,
+ HFS_MIN_TIMESTAMP_SECS + 1,
+ TEST_BEFORE_UNIX_EPOCH_SECS,
+ TEST_UNIX_EPOCH_SECS,
+ 1,
+ TEST_Y2000_SECS,
+ TEST_Y2026_SECS,
+ (s64)S32_MAX,
+ TEST_Y2038_SECS,
+ HFS_MAX_TIMESTAMP_SECS - 1,
+ HFS_MAX_TIMESTAMP_SECS,
+ };
+ time64_t ut;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(values); i++) {
+ KUNIT_EXPECT_EQ_MSG(test, values[i],
+ __hfsp_mt2ut(__hfsp_ut2mt(values[i])),
+ "round trip failed: index %d", i);
+ }
+
+ /* sweep the whole range with a large prime step */
+ for (ut = HFS_MIN_TIMESTAMP_SECS; ut <= HFS_MAX_TIMESTAMP_SECS;
+ ut += 999983) {
+ if (__hfsp_mt2ut(__hfsp_ut2mt(ut)) != ut) {
+ KUNIT_FAIL(test, "round trip failed: ut %lld", ut);
+ break;
+ }
+ }
+
+ /* every on-disk value maps back to itself */
+ for (i = 0; i < 32; i++) {
+ u32 raw = (u32)BIT_ULL(i);
+
+ KUNIT_EXPECT_EQ(test, raw,
+ mt_raw(__hfsp_ut2mt(__hfsp_mt2ut(cpu_to_be32(raw)))));
+ }
+}
+
+/* Test the decision to keep timestamp in xattr */
+static void hfsplus_ut_needs_xattr_test(struct kunit *test)
+{
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(HFS_MIN_TIMESTAMP_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_BEFORE_UNIX_EPOCH_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_UNIX_EPOCH_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_Y2026_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_Y2038_SECS));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS - 1));
+
+ KUNIT_EXPECT_TRUE(test, hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS + 1));
+ KUNIT_EXPECT_TRUE(test, hfsp_ut_needs_xattr(TEST_Y2100_SECS));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_ut_needs_xattr(HFSPLUS_MAX_TIMESTAMP_SECS));
+}
+
+/* Test detection of the extended timestamp mark */
+static void hfsplus_mt_is_ext_timestamp_test(struct kunit *test)
+{
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(HFSPLUS_EXT_TIMESTAMP_MARK));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(cpu_to_be32(U32_MAX)));
+
+ KUNIT_EXPECT_FALSE(test, hfsp_mt_is_ext_timestamp(cpu_to_be32(0)));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_mt_is_ext_timestamp(cpu_to_be32(U32_MAX - 1)));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_mt_is_ext_timestamp(cpu_to_be32(HFS_UTC_OFFSET)));
+
+ /* every timestamp that needs xattr is stored as the mark */
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS)));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(__hfsp_ut2mt(TEST_Y2100_SECS)));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_mt_is_ext_timestamp(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS - 1)));
+}
+
+static struct super_block *alloc_mock_sb(struct kunit *test)
+{
+ struct super_block *sb;
+ struct hfsplus_sb_info *sbi;
+
+ sb = kunit_kzalloc(test, sizeof(*sb), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sb);
+
+ sbi = kunit_kzalloc(test, sizeof(*sbi), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sbi);
+
+ /* no attributes tree: xattr lookup returns -EOPNOTSUPP */
+ sbi->attr_tree = NULL;
+ sb->s_fs_info = sbi;
+
+ return sb;
+}
+
+/*
+ * Test reading of the on-disk timestamp that doesn't need xattr.
+ * The superblock must not be touched in such case.
+ */
+static void hfsplus_read_timestamp_regular_test(struct kunit *test)
+{
+ static const time64_t values[] = {
+ HFS_MIN_TIMESTAMP_SECS,
+ TEST_BEFORE_UNIX_EPOCH_SECS,
+ TEST_UNIX_EPOCH_SECS,
+ TEST_Y2026_SECS,
+ HFS_MAX_TIMESTAMP_SECS - 1,
+ };
+ time64_t ut;
+ bool has_xattr;
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(values); i++) {
+ ut = 0;
+ has_xattr = true;
+
+ err = hfsplus_read_timestamp(NULL, HFSPLUS_FIRSTUSER_CNID,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ __hfsp_ut2mt(values[i]),
+ &ut, &has_xattr);
+ KUNIT_EXPECT_EQ(test, 0, err);
+ KUNIT_EXPECT_EQ(test, values[i], ut);
+ KUNIT_EXPECT_FALSE(test, has_xattr);
+ }
+}
+
+/*
+ * Test reading of the extended timestamp mark without xattr
+ * (for example, the record has been created by Mac OS X or
+ * the volume has no attributes tree). The timestamp must be
+ * HFS_MAX_TIMESTAMP_SECS without any error.
+ */
+static void hfsplus_read_timestamp_mark_no_xattr_test(struct kunit *test)
+{
+ struct super_block *sb = alloc_mock_sb(test);
+ static const char * const names[] = {
+ XATTR_LINUX_CREATE_DATE_NAME,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ };
+ time64_t ut;
+ bool has_xattr;
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(names); i++) {
+ ut = 0;
+ has_xattr = true;
+
+ err = hfsplus_read_timestamp(sb, HFSPLUS_FIRSTUSER_CNID,
+ names[i],
+ HFSPLUS_EXT_TIMESTAMP_MARK,
+ &ut, &has_xattr);
+ KUNIT_EXPECT_EQ(test, 0, err);
+ KUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS, ut);
+ KUNIT_EXPECT_FALSE(test, has_xattr);
+ }
+}
+
+/* Test that names of internal xattrs fit the name buffer */
+static void hfsplus_timestamp_xattr_names_test(struct kunit *test)
+{
+ static const char * const names[] = {
+ XATTR_LINUX_CREATE_DATE_NAME,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ XATTR_LINUX_BACKUP_DATE_NAME,
+ };
+ int i;
+
+ KUNIT_EXPECT_EQ(test, strlen(XATTR_LINUX_HFS_PREFIX),
+ (size_t)XATTR_LINUX_HFS_PREFIX_LEN);
+
+ for (i = 0; i < ARRAY_SIZE(names); i++) {
+ size_t len = XATTR_LINUX_HFS_PREFIX_LEN + strlen(names[i]);
+
+ KUNIT_EXPECT_LT_MSG(test, len, (size_t)XATTR_LINUX_HFS_NAME_MAX,
+ "name %s is too long", names[i]);
+ KUNIT_EXPECT_LE(test, len, (size_t)HFSPLUS_ATTR_MAX_STRLEN);
+ }
+}
+
+static struct kunit_case hfsplus_time_test_cases[] = {
+ KUNIT_CASE(hfsplus_time_constants_test),
+ KUNIT_CASE(hfsplus_mt2ut_test),
+ KUNIT_CASE(hfsplus_ut2mt_test),
+ KUNIT_CASE(hfsplus_ut2mt_before_1970_test),
+ KUNIT_CASE(hfsplus_ut2mt_clamp_test),
+ KUNIT_CASE(hfsplus_time_roundtrip_test),
+ KUNIT_CASE(hfsplus_ut_needs_xattr_test),
+ KUNIT_CASE(hfsplus_mt_is_ext_timestamp_test),
+ KUNIT_CASE(hfsplus_read_timestamp_regular_test),
+ KUNIT_CASE(hfsplus_read_timestamp_mark_no_xattr_test),
+ KUNIT_CASE(hfsplus_timestamp_xattr_names_test),
+ {}
+};
+
+static struct kunit_suite hfsplus_time_test_suite = {
+ .name = "hfsplus_time",
+ .test_cases = hfsplus_time_test_cases,
+};
+
+kunit_test_suite(hfsplus_time_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for HFS+ date/time conversion");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
diff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/hfsplus_unicode_test.c
similarity index 100%
rename from fs/hfsplus/unicode_test.c
rename to fs/hfsplus/hfsplus_unicode_test.c
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 2ce6de574fa6e..0df58dfda5a3e 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -18,6 +18,7 @@
#include <linux/cred.h>
#include <linux/uio.h>
#include <linux/fileattr.h>
+#include <kunit/visibility.h>
#include "hfsplus_fs.h"
#include "hfsplus_raw.h"
@@ -344,7 +345,8 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,
if (request_mask & STATX_BTIME) {
stat->result_mask |= STATX_BTIME;
- stat->btime = hfsp_mt2ut(hip->create_date);
+ stat->btime.tv_sec = hip->birthdate;
+ stat->btime.tv_nsec = 0;
}
if (inode->i_flags & S_APPEND)
@@ -598,9 +600,139 @@ void hfsplus_inode_write_fork(struct inode *inode,
fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode)->alloc_blocks);
}
+/*
+ * hfsplus_read_timestamp - convert on-disk timestamp into 1970-base one
+ * @sb: superblock
+ * @cnid: catalog record ID
+ * @name: name of internal xattr that can keep the real timestamp
+ * @mt: on-disk timestamp
+ * @ut: pointer on converted timestamp [out]
+ * @has_xattr: pointer on flag that xattr exists [out]
+ *
+ * If on-disk timestamp is equal to HFSPLUS_EXT_TIMESTAMP_MARK, then
+ * the real timestamp (after February 2040) could be stored in
+ * the internal xattr. If the xattr is absent (for example, the record
+ * has been created by Mac OS X), then HFS_MAX_TIMESTAMP_SECS is used.
+ */
+int hfsplus_read_timestamp(struct super_block *sb, u32 cnid,
+ const char *name, __be32 mt,
+ time64_t *ut, bool *has_xattr)
+{
+ time64_t timestamp;
+ int err;
+
+ *ut = __hfsp_mt2ut(mt);
+ *has_xattr = false;
+
+ if (!hfsp_mt_is_ext_timestamp(mt))
+ return 0;
+
+ err = hfsplus_get_timestamp_xattr(sb, cnid, name, ×tamp);
+ if (err == -ENODATA || err == -EOPNOTSUPP) {
+ /* timestamp is really equal to HFS_MAX_TIMESTAMP_SECS */
+ return 0;
+ } else if (unlikely(err)) {
+ pr_warn("fail to extract timestamp: cnid %u, name %s, err %d\n",
+ cnid, name, err);
+ return err;
+ }
+
+ if (timestamp < HFS_MAX_TIMESTAMP_SECS) {
+ pr_warn("invalid timestamp in xattr: cnid %u, name %s, timestamp %lld\n",
+ cnid, name, timestamp);
+ /* keep xattr to be deleted or overwritten */
+ *has_xattr = true;
+ } else {
+ *ut = timestamp;
+ *has_xattr = true;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_IF_KUNIT(hfsplus_read_timestamp);
+
+static int hfsplus_inode_read_timestamps(struct inode *inode,
+ struct hfsplus_timestamps *timestamps)
+{
+ struct super_block *sb = inode->i_sb;
+ struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+ u32 cnid = inode->i_ino;
+ struct timespec64 ts = {0};
+ bool has_xattr;
+ int res = 0;
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ timestamps->access_date,
+ &ts.tv_sec, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ inode_set_atime_to_ts(inode, ts);
+ if (has_xattr)
+ set_bit(HFSPLUS_I_ATIME_XATTR, &hip->flags);
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ timestamps->content_mod_date,
+ &ts.tv_sec, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ inode_set_mtime_to_ts(inode, ts);
+ if (has_xattr)
+ set_bit(HFSPLUS_I_MTIME_XATTR, &hip->flags);
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ timestamps->attribute_mod_date,
+ &ts.tv_sec, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ inode_set_ctime_to_ts(inode, ts);
+ if (has_xattr)
+ set_bit(HFSPLUS_I_CTIME_XATTR, &hip->flags);
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_CREATE_DATE_NAME,
+ timestamps->create_date,
+ &hip->birthdate, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ hip->create_date = timestamps->create_date;
+
+finish_read_timestamps:
+ return res;
+}
+
+static inline void
+hfsplus_copy_folder2timestamps(struct hfsplus_cat_folder *folder,
+ struct hfsplus_timestamps *timestamps)
+{
+ timestamps->create_date = folder->create_date;
+ timestamps->content_mod_date = folder->content_mod_date;
+ timestamps->attribute_mod_date = folder->attribute_mod_date;
+ timestamps->access_date = folder->access_date;
+ timestamps->backup_date = folder->backup_date;
+}
+
+static inline void
+hfsplus_copy_file2timestamps(struct hfsplus_cat_file *file,
+ struct hfsplus_timestamps *timestamps)
+{
+ timestamps->create_date = file->create_date;
+ timestamps->content_mod_date = file->content_mod_date;
+ timestamps->attribute_mod_date = file->attribute_mod_date;
+ timestamps->access_date = file->access_date;
+ timestamps->backup_date = file->backup_date;
+}
+
int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
{
hfsplus_cat_entry entry;
+ struct hfsplus_timestamps timestamps = {0};
int res = 0;
u16 type;
@@ -622,12 +754,14 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
goto out;
set_nlink(inode, 1);
inode->i_size = 2 + be32_to_cpu(folder->valence);
- inode_set_atime_to_ts(inode, hfsp_mt2ut(folder->access_date));
- inode_set_mtime_to_ts(inode,
- hfsp_mt2ut(folder->content_mod_date));
- inode_set_ctime_to_ts(inode,
- hfsp_mt2ut(folder->attribute_mod_date));
- HFSPLUS_I(inode)->create_date = folder->create_date;
+
+ hfsplus_copy_folder2timestamps(folder, ×tamps);
+ res = hfsplus_inode_read_timestamps(inode, ×tamps);
+ if (res) {
+ res = -EIO;
+ goto out;
+ }
+
HFSPLUS_I(inode)->fs_blocks = 0;
if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
HFSPLUS_I(inode)->subfolders =
@@ -668,12 +802,13 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
init_special_inode(inode, inode->i_mode,
be32_to_cpu(file->permissions.dev));
}
- inode_set_atime_to_ts(inode, hfsp_mt2ut(file->access_date));
- inode_set_mtime_to_ts(inode,
- hfsp_mt2ut(file->content_mod_date));
- inode_set_ctime_to_ts(inode,
- hfsp_mt2ut(file->attribute_mod_date));
- HFSPLUS_I(inode)->create_date = file->create_date;
+
+ hfsplus_copy_file2timestamps(file, ×tamps);
+ res = hfsplus_inode_read_timestamps(inode, ×tamps);
+ if (res) {
+ res = -EIO;
+ goto out;
+ }
} else {
pr_err("bad catalog entry used to create inode\n");
res = -EIO;
@@ -682,12 +817,126 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
return res;
}
+struct hfsplus_xattr_changes {
+ bool added;
+ bool removed;
+};
+
+/*
+ * Convert @ts into on-disk timestamp. The timestamp after February 2040
+ * is stored as HFSPLUS_EXT_TIMESTAMP_MARK with the real value in
+ * the internal xattr @name. The stale xattr is removed if timestamp
+ * becomes representable by on-disk field.
+ */
+static int hfsplus_inode_save_timestamp(struct inode *inode,
+ const char *name, int xattr_bit,
+ struct timespec64 ts, __be32 *date,
+ struct hfsplus_xattr_changes *xattr)
+{
+ struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+ time64_t stored;
+ int err;
+
+ *date = __hfsp_ut2mt(ts.tv_sec);
+
+ if (hfsp_ut_needs_xattr(ts.tv_sec)) {
+ /* don't rewrite xattr if nothing has been changed */
+ if (test_bit(xattr_bit, &hip->flags)) {
+ err = hfsplus_get_timestamp_xattr(inode->i_sb,
+ inode->i_ino,
+ name,
+ &stored);
+ if (!err && stored == ts.tv_sec)
+ return 0;
+ }
+
+ err = hfsplus_set_timestamp_xattr(inode, inode->i_ino,
+ name, ts.tv_sec);
+ if (err) {
+ clear_bit(xattr_bit, &hip->flags);
+ return err;
+ }
+
+ set_bit(xattr_bit, &hip->flags);
+ xattr->added = true;
+ } else if (test_bit(xattr_bit, &hip->flags)) {
+ err = hfsplus_remove_timestamp_xattr(inode, name);
+ if (err)
+ return err;
+
+ clear_bit(xattr_bit, &hip->flags);
+ xattr->removed = true;
+ }
+
+ return 0;
+}
+
+static void hfsplus_inode_save_timestamps(struct inode *inode,
+ struct hfsplus_timestamps *timestamps,
+ struct hfsplus_xattr_changes *changes)
+{
+ int res;
+
+ /*
+ * Failure of xattr operation is not critical. The timestamp
+ * is clamped by HFS_MAX_TIMESTAMP_SECS in such case.
+ * But the rest of the catalog record must be saved anyway.
+ */
+
+ res = hfsplus_inode_save_timestamp(inode,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ HFSPLUS_I_ATIME_XATTR,
+ inode_get_atime(inode),
+ ×tamps->access_date,
+ changes);
+ if (res) {
+ pr_warn_ratelimited("fail to save access date: ino %llu, err %d\n",
+ inode->i_ino, res);
+ }
+
+ res = hfsplus_inode_save_timestamp(inode,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ HFSPLUS_I_MTIME_XATTR,
+ inode_get_mtime(inode),
+ ×tamps->content_mod_date,
+ changes);
+ if (res) {
+ pr_warn_ratelimited("fail to save content mod date: ino %llu, err %d\n",
+ inode->i_ino, res);
+ }
+
+ res = hfsplus_inode_save_timestamp(inode,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ HFSPLUS_I_CTIME_XATTR,
+ inode_get_ctime(inode),
+ ×tamps->attribute_mod_date,
+ changes);
+ if (res) {
+ pr_warn_ratelimited("fail to save attribute mod date: ino %llu, err %d\n",
+ inode->i_ino, res);
+ }
+}
+
+static inline __be16
+hfsplus_update_xattr_exists_flag(struct inode *inode, __be16 flags,
+ struct hfsplus_xattr_changes *xattr)
+{
+ if (xattr->added)
+ flags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);
+ else if (xattr->removed && !hfsplus_attr_exists(inode, NULL))
+ flags &= cpu_to_be16(~HFSPLUS_XATTR_EXISTS);
+
+ return flags;
+}
+
int hfsplus_cat_write_inode(struct inode *inode)
{
struct inode *main_inode = inode;
struct hfs_btree *tree = HFSPLUS_SB(inode->i_sb)->cat_tree;
struct hfs_find_data fd;
hfsplus_cat_entry entry;
+ struct hfsplus_timestamps timestamps = {0};
+ struct hfsplus_xattr_changes changes = {0};
int res = 0;
hfs_dbg("inode->i_ino %llu\n", inode->i_ino);
@@ -718,9 +967,15 @@ int hfsplus_cat_write_inode(struct inode *inode)
sizeof(struct hfsplus_cat_folder));
/* simple node checks? */
hfsplus_cat_set_perms(inode, &folder->permissions);
- folder->access_date = hfsp_ut2mt(inode_get_atime(inode));
- folder->content_mod_date = hfsp_ut2mt(inode_get_mtime(inode));
- folder->attribute_mod_date = hfsp_ut2mt(inode_get_ctime(inode));
+
+ hfsplus_inode_save_timestamps(inode, ×tamps, &changes);
+ folder->access_date = timestamps.access_date;
+ folder->content_mod_date = timestamps.content_mod_date;
+ folder->attribute_mod_date = timestamps.attribute_mod_date;
+ folder->flags = hfsplus_update_xattr_exists_flag(inode,
+ folder->flags,
+ &changes);
+
folder->valence = cpu_to_be32(inode->i_size - 2);
if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
folder->subfolders =
@@ -753,9 +1008,15 @@ int hfsplus_cat_write_inode(struct inode *inode)
file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
else
file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
- file->access_date = hfsp_ut2mt(inode_get_atime(inode));
- file->content_mod_date = hfsp_ut2mt(inode_get_mtime(inode));
- file->attribute_mod_date = hfsp_ut2mt(inode_get_ctime(inode));
+
+ hfsplus_inode_save_timestamps(inode, ×tamps, &changes);
+ file->access_date = timestamps.access_date;
+ file->content_mod_date = timestamps.content_mod_date;
+ file->attribute_mod_date = timestamps.attribute_mod_date;
+ file->flags = hfsplus_update_xattr_exists_flag(inode,
+ file->flags,
+ &changes);
+
hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
sizeof(struct hfsplus_cat_file));
}
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index ff7d6b3336a66..b10b53f6f8f9e 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -86,6 +86,7 @@ struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
mutex_init(&HFSPLUS_I(inode)->extents_lock);
HFSPLUS_I(inode)->rsrc_inode = NULL;
HFSPLUS_I(inode)->create_date = 0;
+ HFSPLUS_I(inode)->birthdate = 0;
HFSPLUS_I(inode)->linkid = 0;
HFSPLUS_I(inode)->flags = 0;
HFSPLUS_I(inode)->fs_blocks = 0;
@@ -511,6 +512,13 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
if (!sbi->rsrc_clump_blocks)
sbi->rsrc_clump_blocks = 1;
+ sb->s_time_gran = NSEC_PER_SEC;
+ sb->s_time_min = HFS_MIN_TIMESTAMP_SECS;
+ /*
+ * Timestamps after HFS_MAX_TIMESTAMP_SECS are stored in xattrs.
+ */
+ sb->s_time_max = HFS_MAX_TIMESTAMP_SECS;
+
err = -EFBIG;
last_fs_block = sbi->total_blocks - 1;
last_fs_page = (last_fs_block << sbi->alloc_blksz_shift) >>
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index 21a1c196c71f2..d3b1734496168 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -50,6 +50,12 @@ static bool is_known_namespace(const char *name)
return true;
}
+static bool is_linux_hfs_internal_xattr(const char *name)
+{
+ return !strncmp(name, XATTR_LINUX_HFS_PREFIX,
+ XATTR_LINUX_HFS_PREFIX_LEN);
+}
+
static u32 hfsplus_init_header_node(struct inode *attr_file,
u32 clump_size,
char *buf, u16 node_size)
@@ -319,6 +325,19 @@ static int hfsplus_create_attributes_file(struct super_block *sb)
hfsplus_mark_inode_dirty(attr_file, HFSPLUS_I_ATTR_DIRTY);
+ /*
+ * Store the fork of AttributesFile into the volume header right now.
+ * The AttributesFile can be created by hfsplus_cat_write_inode()
+ * (timestamps after 2040 are stored in xattrs) in the middle of
+ * sync operation. Then, the dirty AttributesFile's inode can be
+ * skipped by writeback and the volume header will be committed
+ * without AttributesFile. As a result, the AttributesFile will be
+ * not opened during the next mount.
+ */
+ hfsplus_inode_write_fork(attr_file, &sbi->s_vhdr->attr_file);
+ set_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags);
+ hfsplus_mark_mdb_dirty(sb);
+
sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
if (!sbi->attr_tree)
pr_err("failed to load attributes file\n");
@@ -339,8 +358,7 @@ static int hfsplus_create_attributes_file(struct super_block *sb)
return err;
}
-static inline
-bool is_xattr_operation_supported(struct inode *inode)
+static inline bool is_xattr_operation_supported(struct inode *inode)
{
if (HFSPLUS_IS_RSRC(inode))
return false;
@@ -609,8 +627,9 @@ static ssize_t hfsplus_getxattr_finder_info(struct inode *inode,
return res;
}
-ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
- void *value, size_t size)
+static ssize_t __hfsplus_getxattr_nocheck(struct super_block *sb,
+ u32 cnid, const char *name,
+ void *value, size_t size)
{
struct hfs_find_data fd;
hfsplus_attr_entry *entry;
@@ -619,13 +638,7 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
u16 record_length = 0;
ssize_t res;
- if (!is_xattr_operation_supported(inode))
- return -EOPNOTSUPP;
-
- if (!strcmp_xattr_finder_info(name))
- return hfsplus_getxattr_finder_info(inode, value, size);
-
- if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
+ if (!HFSPLUS_SB(sb)->attr_tree)
return -EOPNOTSUPP;
entry = hfsplus_alloc_attr_entry();
@@ -634,18 +647,18 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
return -ENOMEM;
}
- res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->attr_tree, &fd);
+ res = hfs_find_init(HFSPLUS_SB(sb)->attr_tree, &fd);
if (res) {
pr_err("can't init xattr find struct\n");
goto failed_getxattr_init;
}
- res = hfsplus_find_attr(inode->i_sb, inode->i_ino, name, &fd);
+ res = hfsplus_find_attr(sb, cnid, name, &fd);
if (res) {
if (res == -ENOENT || res == -ENODATA)
res = -ENODATA;
else
- pr_err("xattr search failed\n");
+ pr_err("xattr searching failed\n");
goto out;
}
@@ -693,6 +706,38 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
return res;
}
+static inline ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
+ void *value, size_t size)
+{
+ if (!is_xattr_operation_supported(inode))
+ return -EOPNOTSUPP;
+
+ if (!strcmp_xattr_finder_info(name))
+ return hfsplus_getxattr_finder_info(inode, value, size);
+
+ return __hfsplus_getxattr_nocheck(inode->i_sb, (u32)inode->i_ino,
+ name, value, size);
+}
+
+static inline char *hfsplus_build_xattr_name(const char *name,
+ const char *prefix,
+ size_t prefixlen)
+{
+ char *xattr_name;
+ size_t len = NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1;
+
+ xattr_name = kzalloc(len, GFP_KERNEL);
+ if (!xattr_name)
+ return ERR_PTR(-ENOMEM);
+
+ if (snprintf(xattr_name, len, "%s%s", prefix, name) >= len) {
+ kfree(xattr_name);
+ return ERR_PTR(-ENAMETOOLONG);
+ }
+
+ return xattr_name;
+}
+
ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
void *value, size_t size,
const char *prefix, size_t prefixlen)
@@ -704,13 +749,9 @@ ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
inode->i_ino, name ? name : NULL,
prefix ? prefix : NULL);
- xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
- GFP_KERNEL);
- if (!xattr_name)
- return -ENOMEM;
-
- strcpy(xattr_name, prefix);
- strcpy(xattr_name + prefixlen, name);
+ xattr_name = hfsplus_build_xattr_name(name, prefix, prefixlen);
+ if (IS_ERR(xattr_name))
+ return PTR_ERR(xattr_name);
res = __hfsplus_getxattr(inode, xattr_name, value, size);
kfree(xattr_name);
@@ -718,7 +759,114 @@ ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
hfs_dbg("finished: res %d\n", res);
return res;
+}
+
+static ssize_t hfsplus_getxattr_nocheck(struct super_block *sb, u32 cnid,
+ const char *name,
+ void *value, size_t size,
+ const char *prefix, size_t prefixlen)
+{
+ int res;
+ char *xattr_name;
+ hfs_dbg("cnid %u, name %s, prefix %s\n",
+ cnid, name ? name : NULL,
+ prefix ? prefix : NULL);
+
+ xattr_name = hfsplus_build_xattr_name(name, prefix, prefixlen);
+ if (IS_ERR(xattr_name))
+ return PTR_ERR(xattr_name);
+
+ res = __hfsplus_getxattr_nocheck(sb, cnid, xattr_name, value, size);
+ kfree(xattr_name);
+
+ hfs_dbg("finished: res %d\n", res);
+
+ return res;
+}
+
+/*
+ * Get the timestamp stored in the internal xattr @name
+ * of catalog record @cnid. The caller can hold the catalog tree lock.
+ */
+int hfsplus_get_timestamp_xattr(struct super_block *sb, u32 cnid,
+ const char *name, time64_t *ts)
+{
+ __be64 value;
+ ssize_t res;
+
+ res = hfsplus_getxattr_nocheck(sb, cnid, name,
+ &value, sizeof(value),
+ XATTR_LINUX_HFS_PREFIX,
+ XATTR_LINUX_HFS_PREFIX_LEN);
+ if (res < 0)
+ return res;
+
+ if (res != sizeof(value))
+ return -EIO;
+
+ *ts = (time64_t)be64_to_cpu(value);
+ return 0;
+}
+
+/*
+ * Store the timestamp @ts into the internal xattr @name of catalog
+ * record @cnid. The caller must hold the catalog tree lock and it is
+ * caller's responsibility to set HFSPLUS_XATTR_EXISTS flag in
+ * the catalog record.
+ */
+int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,
+ const char *name, time64_t ts)
+{
+ struct super_block *sb = inode->i_sb;
+ char xattr_name[XATTR_LINUX_HFS_NAME_MAX];
+ __be64 value = cpu_to_be64(ts);
+ int err;
+
+ hfs_dbg("ino %llu, cnid %u, name %s, ts %lld\n",
+ inode->i_ino, cnid, name, ts);
+
+ if (!HFSPLUS_SB(sb)->attr_tree) {
+ err = hfsplus_create_attributes_file(sb);
+ if (unlikely(err))
+ return err;
+
+ if (!HFSPLUS_SB(sb)->attr_tree)
+ return -EIO;
+ }
+
+ if (snprintf(xattr_name, sizeof(xattr_name), "%s%s",
+ XATTR_LINUX_HFS_PREFIX, name) >= sizeof(xattr_name))
+ return -ENAMETOOLONG;
+
+ return hfsplus_set_attr_cnid(inode, cnid, xattr_name,
+ &value, sizeof(value));
+}
+
+/*
+ * Remove the internal xattr @name of @inode. The caller must hold
+ * the catalog tree lock and it is caller's responsibility to update
+ * HFSPLUS_XATTR_EXISTS flag in the catalog record.
+ */
+int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name)
+{
+ char xattr_name[XATTR_LINUX_HFS_NAME_MAX];
+ int err;
+
+ hfs_dbg("ino %llu, name %s\n", inode->i_ino, name);
+
+ if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
+ return 0;
+
+ if (snprintf(xattr_name, sizeof(xattr_name), "%s%s",
+ XATTR_LINUX_HFS_PREFIX, name) >= sizeof(xattr_name))
+ return -ENAMETOOLONG;
+
+ err = hfsplus_delete_attr(inode, xattr_name);
+ if (err == -ENOENT || err == -ENODATA)
+ err = 0;
+
+ return err;
}
static inline int can_list(const char *xattr_name)
@@ -726,6 +874,10 @@ static inline int can_list(const char *xattr_name)
if (!xattr_name)
return 0;
+ /* Internal xattrs of the driver are hidden */
+ if (is_linux_hfs_internal_xattr(xattr_name))
+ return 0;
+
return strncmp(xattr_name, XATTR_TRUSTED_PREFIX,
XATTR_TRUSTED_PREFIX_LEN) ||
capable(CAP_SYS_ADMIN);
@@ -998,6 +1150,10 @@ static int hfsplus_osx_getxattr(const struct xattr_handler *handler,
if (is_known_namespace(name))
return -EOPNOTSUPP;
+ /* Internal xattrs of the driver are hidden */
+ if (is_linux_hfs_internal_xattr(name))
+ return -EOPNOTSUPP;
+
/*
* osx is the namespace we use to indicate an unprefixed
* attribute on the filesystem (like the ones that OS X
@@ -1020,6 +1176,10 @@ static int hfsplus_osx_setxattr(const struct xattr_handler *handler,
if (is_known_namespace(name))
return -EOPNOTSUPP;
+ /* Internal xattrs of the driver cannot be changed by user */
+ if (is_linux_hfs_internal_xattr(name))
+ return -EOPNOTSUPP;
+
/*
* osx is the namespace we use to indicate an unprefixed
* attribute on the filesystem (like the ones that OS X
diff --git a/fs/hfsplus/xattr.h b/fs/hfsplus/xattr.h
index 15cc55e414100..8f6283f85f133 100644
--- a/fs/hfsplus/xattr.h
+++ b/fs/hfsplus/xattr.h
@@ -12,6 +12,24 @@
#include <linux/xattr.h>
+/*
+ * Internal xattrs of Linux HFS+ driver. Timestamps beyond
+ * HFS_MAX_TIMESTAMP_SECS (February 2040) cannot be represented by
+ * 32-bit on-disk fields. Such timestamp is stored as the maximal value
+ * (HFSPLUS_EXT_TIMESTAMP_MARK) in the catalog record and the real value
+ * is kept in the xattr as big-endian 64-bit seconds since
+ * 00:00 GMT, Jan. 1, 1970.
+ */
+#define XATTR_LINUX_HFS_PREFIX "linux_hfs."
+#define XATTR_LINUX_HFS_PREFIX_LEN \
+ (sizeof(XATTR_LINUX_HFS_PREFIX) - 1)
+#define XATTR_LINUX_HFS_NAME_MAX 64
+#define XATTR_LINUX_CREATE_DATE_NAME "create_date_u64"
+#define XATTR_LINUX_CONTENT_MOD_DATE_NAME "content_mod_date_u64"
+#define XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME "attribute_mod_date_u64"
+#define XATTR_LINUX_ACCESS_DATE_NAME "access_date_u64"
+#define XATTR_LINUX_BACKUP_DATE_NAME "backup_date_u64"
+
extern const struct xattr_handler hfsplus_xattr_osx_handler;
extern const struct xattr_handler hfsplus_xattr_user_handler;
extern const struct xattr_handler hfsplus_xattr_trusted_handler;
@@ -23,16 +41,18 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
const void *value, size_t size, int flags);
int hfsplus_setxattr(struct inode *inode, const char *name,
- const void *value, size_t size, int flags,
- const char *prefix, size_t prefixlen);
-
-ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
- void *value, size_t size);
-
+ const void *value, size_t size, int flags,
+ const char *prefix, size_t prefixlen);
ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
void *value, size_t size,
const char *prefix, size_t prefixlen);
+int hfsplus_get_timestamp_xattr(struct super_block *sb, u32 cnid,
+ const char *name, time64_t *ts);
+int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,
+ const char *name, time64_t ts);
+int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name);
+
ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
int hfsplus_init_security(struct inode *inode, struct inode *dir,
diff --git a/include/linux/hfs_common.h b/include/linux/hfs_common.h
index d6a615e74b26e..d4e91dea23628 100644
--- a/include/linux/hfs_common.h
+++ b/include/linux/hfs_common.h
@@ -667,4 +667,17 @@ typedef union {
struct hfsplus_attr_key attr;
} __packed hfsplus_btree_key;
+/*
+ * There are two time systems. Both are based on seconds since
+ * a particular time/date.
+ * Unix: signed little-endian since 00:00 GMT, Jan. 1, 1970
+ * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
+ */
+#define HFS_UTC_OFFSET 2082844800U
+
+/* January 1, 1904, 00:00:00 UTC */
+#define HFS_MIN_TIMESTAMP_SECS -2082844800LL
+/* February 6, 2040, 06:28:15 UTC */
+#define HFS_MAX_TIMESTAMP_SECS 2212122495LL
+
#endif /* _HFS_COMMON_H_ */
|
| 3/2 | 2026/10/14 04:39 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25898 output: 33 thoughts: 316 Thoughts: **Reviewing a Post-Application Patch to HFS+ Filesystem Support** Okay, so I need to get a handle on this patch that's already landed. My immediate goal is to understand the scope of changes. Let's start by looking at the modified files revealed by the diff. Ah, it appears this patch is touching `fs/hfs/hfs_fs.h`, `fs/hfsplus/Makefile`, a few key files in `fs/hfsplus` like `attributes.c`, `catalog.c`, `dir.c`, `hfsplus_fs.h`, `hfsplus_time_test.c`, `hfsplus_unicode_test.c` (looks like a rename from `unicode_test.c`), `inode.c`, `super.c`, `xattr.c`, and `xattr.h`, and finally `include/linux/hfs_common.h`. Interesting spread... so it's reaching across the headers, build system, and the core implementation. Based on the file list, my initial intuition is that this patch is most likely related to extending the HFS+ filesystem, perhaps to handle something related to timestamps – it looks like a common theme for filesystem improvements. The mention of internal xattrs with the `linux_hfs.<attr_name>` format strongly suggests the implementation of 64-bit timestamp support, which would be essential to avoid the year-2038 problem (or the year 2040 problem for HFS+). This makes sense, given HFS+'s age and the need for future compatibility. The context here is a bit intriguing: it seems we're dealing with filesystem code that's part of the kernel, so this is likely something that could be leveraged by loop/block devices or even the syzkaller tool to mount various hfsplus filesystem images. The reference to manipulating files, xattrs, utimes, and statx confirms that this is about fundamental filesystem operations. HFS+ is a standard, reachable Linux filesystem, which implies this patch is important to the kernel and could have implications beyond the immediate HFS+ users. Now, let's drill down and check the relevant Kconfig options for HFSPLUS. I'll quickly use `grepper` to search through `fs/hfsplus/Kconfig` and see what configurations are available and if this patch might change how we can configure the filesystem support. That should give me a more granular picture. |
| 4/2 | 2026/10/14 04:40 | tool | grepper |
0mArgs:{
"Expression": "config HFSPLUS",
"PathPrefixes": [
"fs/hfsplus/Kconfig"
]
}Results: {
"Output": "fs/hfsplus/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/hfsplus/Kconfig:2:config HFSPLUS_FS\nfs/hfsplus/Kconfig-3-\ttristate \"Apple Extended HFS file system support\"\n--\nfs/hfsplus/Kconfig-17-\nfs/hfsplus/Kconfig:18:config HFSPLUS_KUNIT_TEST\nfs/hfsplus/Kconfig-19-\ttristate \"KUnit tests for HFS+ filesystem\" if !KUNIT_ALL_TESTS\n"
} |
| 5/2 | 2026/10/14 04:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26927 output: 34 thoughts: 14 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing the Kconfig for HFS+ Support** Alright, let's dive into the `fs/hfsplus/Kconfig` file. I need to understand how the HFS+ filesystem support is configured within the kernel. My initial focus will be on the various configuration options exposed. I want to see: * **Default Behavior:** What's the default state of HFS+ support? Is it compiled in, as a module, or disabled by default? This has a significant impact on its general availability. * **Module Options:** If it's modular, which module name is used? I'll need to know this for proper probing and loading during boot, especially in an embedded environment. * **Dependencies:** What are the dependencies on other kernel subsystems or features? Does it rely on specific block device support, security modules, or other filesystem components? Understanding these relationships is crucial for troubleshooting compatibility issues. * **Performance Tuning:** Are there any options that allow for tuning performance, such as buffer size configurations, journaling settings, or read-ahead parameters? These would be important in assessing performance bottlenecks. * **Debug Options:** I'll also look for debugging options. These are often invaluable for in-depth analysis of any HFS+ related issues encountered. * **Security Configuration:** What security options are configurable? This is especially critical since HFS+ has unique features. Ultimately, I need a comprehensive overview of how this module can be tweaked and adapted to suit different use cases and system configurations. This includes understanding the impact of any changes on both system performance and general stability. |
| 6/2 | 2026/10/14 04:40 | tool | read-file |
0mArgs:{
"File": "fs/hfsplus/Kconfig",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig HFSPLUS_FS\n 3:\t\ttristate \"Apple Extended HFS file system support\"\n 4:\t\tdepends on BLOCK\n 5:\t\tselect BUFFER_HEAD\n 6:\t\tselect NLS\n 7:\t\tselect NLS_UTF8\n 8:\t\tselect LEGACY_DIRECT_IO\n 9:\t\thelp\n 10:\t\t If you say Y here, you will be able to mount extended format\n 11:\t\t Macintosh-formatted hard drive partitions with full read-write access.\n 12:\t\n 13:\t\t This file system is often called HFS+ and was introduced with\n 14:\t\t MacOS 8. It includes all Mac specific filesystem data such as\n 15:\t\t data forks and creator codes, but it also has several UNIX\n 16:\t\t style features such as file ownership and permissions.\n 17:\t\n 18:\tconfig HFSPLUS_KUNIT_TEST\n 19:\t\ttristate \"KUnit tests for HFS+ filesystem\" if !KUNIT_ALL_TESTS\n 20:\t\tdepends on HFSPLUS_FS \u0026\u0026 KUNIT\n 21:\t\tdefault KUNIT_ALL_TESTS\n 22:\t\thelp\n 23:\t\t This builds KUnit tests for the HFS+ filesystem.\n 24:\t\n 25:\t\t KUnit tests run during boot and output the results to the debug\n 26:\t\t log in TAP format (https://testanything.org/). Only useful for\n 27:\t\t kernel devs running KUnit test harness and are not for inclusion\n 28:\t\t into a production build.\n 29:\t\n 30:\t\t For more information on KUnit and unit tests in general please\n 31:\t\t refer to the KUnit documentation in Documentation/dev-tools/kunit/.\n"
} |
| 7/2 | 2026/10/14 04:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27798 output: 55 thoughts: 1956 Thoughts: **Fuzzing Focus: HFS+ Timestamp Handling** Okay, let's break this down for fuzzing. We've got changes in `fs/hfs/` related to timestamp handling, specifically around the `HFSPLUS_FS` Apple Extended HFS filesystem. This is great, because syzkaller *definitely* fuzzes filesystems, and HFS+ is one of the targets, usually through `syz_mount_image` or the standard `mount` syscall. Plus, filesystem code lives right in the core kernel. The patch touches a bunch of functions across `attributes.c`, `catalog.c`, `dir.c`, `inode.c`, `super.c`, and `xattr.c`. That's a wide swath of the filesystem! Reachable in standard environments? Yep. QEMU, GCE, loop devices, ramdisks, virtio-blk – HFS+ is mountable everywhere, and syzkaller hits it hard. Now, the potential for bugs...this is where it gets interesting. We're looking at what happens when an inode's timestamp goes past `HFS_MAX_TIMESTAMP_SECS`. That triggers the creation or update of internal "linux_hfs.*" xattrs on the attributes tree. The key is `hfsplus_inode_save_timestamp()` calling `hfsplus_set_timestamp_xattr()`, which *might* call `hfsplus_create_attributes_file(sb)` inside `hfsplus_cat_write_inode()`. The comment about the AttributesFile being created "in the middle of sync operation..." is a red flag. Think about the implications: locking, B-tree modifications (especially the `hfs_bmap_reserve` call), potential recursion, all during inode writeback. `hfsplus_set_attr_cnid` also grabs B-tree node reserve. And `hfsplus_cat_write_inode` is called from `write_inode` callbacks. There's also `hfsplus_getattr` now reading timestamps, which increases the attack surface. This is prime fuzzing material! Okay, `WorthFuzzing = true`, no doubt. This involves core filesystem logic, complex attribute and catalog record manipulation, and new code paths in HFS+. Now, let's identify the specific functions to *focus* the fuzzer. We need to avoid generic hot-paths and target the feature logic. We need to get the focus symbols. So, let's look at the modified functions, avoiding the ubiquitous ones: Here's a list. And more importantly, the functions we can use for FocusSymbols: * `hfsplus_set_attr_cnid` * `hfsplus_read_timestamp` * `hfsplus_get_timestamp_xattr` * `hfsplus_set_timestamp_xattr` * `hfsplus_remove_timestamp_xattr` * `hfsplus_cat_write_inode` * `hfsplus_cat_read_inode` * `hfsplus_create_cat` * `hfsplus_getattr` We can be confident that these are real symbols, not inlined, and good targets for focused fuzzing. That's a good list, and should give us excellent coverage. |
| 8/2 | 2026/10/14 04:40 | tool | grepper |
0mArgs:{
"Expression": "hfsplus_cat_write_inode|hfsplus_create_cat|hfsplus_set_attr_cnid",
"PathPrefixes": [
"fs/hfsplus/"
]
}Results: {
"Output": "fs/hfsplus/attributes.c=456=int hfsplus_replace_attr(struct inode *inode,\n--\nfs/hfsplus/attributes.c-508- */\nfs/hfsplus/attributes.c:509:int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,\nfs/hfsplus/attributes.c-510-\t\t\t const char *name,\n--\nfs/hfsplus/catalog.c=115=static void hfsplus_copy_timestamps2file(struct hfsplus_timestamps *timestamps,\n--\nfs/hfsplus/catalog.c-126- * is stored as HFSPLUS_EXT_TIMESTAMP_MARK in the catalog record. The real\nfs/hfsplus/catalog.c:127: * value is saved into internal xattr by hfsplus_create_cat().\nfs/hfsplus/catalog.c-128- */\n--\nfs/hfsplus/catalog.c=307=static void hfsplus_subfolders_dec(struct inode *dir)\n--\nfs/hfsplus/catalog.c-323-\nfs/hfsplus/catalog.c:324:int hfsplus_create_cat(u32 cnid, struct inode *dir,\nfs/hfsplus/catalog.c-325-\t\tconst struct qstr *str, struct inode *inode)\n--\nfs/hfsplus/dir.c=331=static int hfsplus_link(struct dentry *src_dentry, struct inode *dst_dir,\n--\nfs/hfsplus/dir.c-367-\t\tsrc_dentry-\u003ed_fsdata = (void *)(unsigned long)cnid;\nfs/hfsplus/dir.c:368:\t\tres = hfsplus_create_cat(cnid, src_dir,\nfs/hfsplus/dir.c-369-\t\t\t\t\t \u0026src_dentry-\u003ed_name, inode);\n--\nfs/hfsplus/dir.c-375-\tcnid = sbi-\u003enext_cnid++;\nfs/hfsplus/dir.c:376:\tres = hfsplus_create_cat(cnid, dst_dir, \u0026dst_dentry-\u003ed_name, inode);\nfs/hfsplus/dir.c-377-\tif (res)\n--\nfs/hfsplus/dir.c-387-\nfs/hfsplus/dir.c:388:\tres = hfsplus_cat_write_inode(src_dir);\nfs/hfsplus/dir.c-389-\tif (res)\n--\nfs/hfsplus/dir.c-391-\nfs/hfsplus/dir.c:392:\tres = hfsplus_cat_write_inode(dst_dir);\nfs/hfsplus/dir.c-393-\tif (res)\n--\nfs/hfsplus/dir.c-395-\nfs/hfsplus/dir.c:396:\tres = hfsplus_cat_write_inode(sbi-\u003ehidden_dir);\nfs/hfsplus/dir.c-397-\tif (res)\n--\nfs/hfsplus/dir.c-399-\nfs/hfsplus/dir.c:400:\tres = hfsplus_cat_write_inode(inode);\nfs/hfsplus/dir.c-401-\n--\nfs/hfsplus/dir.c=407=static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)\n--\nfs/hfsplus/dir.c-463-\tif (!res) {\nfs/hfsplus/dir.c:464:\t\tres = hfsplus_cat_write_inode(dir);\nfs/hfsplus/dir.c-465-\t\tif (!res) {\nfs/hfsplus/dir.c:466:\t\t\tres = hfsplus_cat_write_inode(sbi-\u003ehidden_dir);\nfs/hfsplus/dir.c-467-\t\t\tif (!res)\nfs/hfsplus/dir.c:468:\t\t\t\tres = hfsplus_cat_write_inode(inode);\nfs/hfsplus/dir.c-469-\t\t}\n--\nfs/hfsplus/dir.c=476=static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry)\n--\nfs/hfsplus/dir.c-493-\nfs/hfsplus/dir.c:494:\tres = hfsplus_cat_write_inode(dir);\nfs/hfsplus/dir.c-495-out:\n--\nfs/hfsplus/dir.c=500=static int hfsplus_symlink(struct mnt_idmap *idmap, struct inode *dir,\n--\nfs/hfsplus/dir.c-518-\nfs/hfsplus/dir.c:519:\tres = hfsplus_create_cat(inode-\u003ei_ino, dir, \u0026dentry-\u003ed_name, inode);\nfs/hfsplus/dir.c-520-\tif (res)\n--\nfs/hfsplus/dir.c-534-\nfs/hfsplus/dir.c:535:\tres = hfsplus_cat_write_inode(dir);\nfs/hfsplus/dir.c-536-\tif (res)\n--\nfs/hfsplus/dir.c-538-\nfs/hfsplus/dir.c:539:\tres = hfsplus_cat_write_inode(inode);\nfs/hfsplus/dir.c-540-\tgoto out;\n--\nfs/hfsplus/dir.c=551=static int hfsplus_mknod(struct mnt_idmap *idmap, struct inode *dir,\n--\nfs/hfsplus/dir.c-568-\nfs/hfsplus/dir.c:569:\tres = hfsplus_create_cat(inode-\u003ei_ino, dir, \u0026dentry-\u003ed_name, inode);\nfs/hfsplus/dir.c-570-\tif (res)\n--\nfs/hfsplus/dir.c-584-\nfs/hfsplus/dir.c:585:\tres = hfsplus_cat_write_inode(dir);\nfs/hfsplus/dir.c-586-\tif (res)\n--\nfs/hfsplus/dir.c-588-\nfs/hfsplus/dir.c:589:\tres = hfsplus_cat_write_inode(inode);\nfs/hfsplus/dir.c-590-\tgoto out;\n--\nfs/hfsplus/dir.c=613=static int hfsplus_rename(struct mnt_idmap *idmap,\n--\nfs/hfsplus/dir.c-643-\nfs/hfsplus/dir.c:644:\t\tres = hfsplus_cat_write_inode(old_dir);\nfs/hfsplus/dir.c-645-\t\tif (res)\n--\nfs/hfsplus/dir.c-647-\nfs/hfsplus/dir.c:648:\t\tres = hfsplus_cat_write_inode(new_dir);\nfs/hfsplus/dir.c-649-\t\tif (res)\n--\nfs/hfsplus/dir.c-651-\nfs/hfsplus/dir.c:652:\t\tres = hfsplus_cat_write_inode(inode);\nfs/hfsplus/dir.c-653-\t}\n--\nfs/hfsplus/hfsplus_fs.h=362=int hfsplus_replace_attr(struct inode *inode,\n--\nfs/hfsplus/hfsplus_fs.h-364-\t\t\t const void *value, size_t size);\nfs/hfsplus/hfsplus_fs.h:365:int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,\nfs/hfsplus/hfsplus_fs.h-366-\t\t\t const char *name,\n--\nfs/hfsplus/hfsplus_fs.h=435=int hfsplus_find_cat(struct super_block *sb, u32 cnid,\nfs/hfsplus/hfsplus_fs.h-436-\t\t struct hfs_find_data *fd);\nfs/hfsplus/hfsplus_fs.h:437:int hfsplus_create_cat(u32 cnid, struct inode *dir, const struct qstr *str,\nfs/hfsplus/hfsplus_fs.h-438-\t\t struct inode *inode);\n--\nfs/hfsplus/hfsplus_fs.h=474=int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd);\nfs/hfsplus/hfsplus_fs.h:475:int hfsplus_cat_write_inode(struct inode *inode);\nfs/hfsplus/hfsplus_fs.h-476-int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,\n--\nfs/hfsplus/inode.c=921=hfsplus_update_xattr_exists_flag(struct inode *inode, __be16 flags,\n--\nfs/hfsplus/inode.c-931-\nfs/hfsplus/inode.c:932:int hfsplus_cat_write_inode(struct inode *inode)\nfs/hfsplus/inode.c-933-{\n--\nfs/hfsplus/super.c=169=static int hfsplus_write_inode(struct inode *inode,\n--\nfs/hfsplus/super.c-181-\t inode-\u003ei_ino == HFSPLUS_ROOT_CNID)\nfs/hfsplus/super.c:182:\t\treturn hfsplus_cat_write_inode(inode);\nfs/hfsplus/super.c-183-\telse\n--\nfs/hfsplus/super.c=453=static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)\n--\nfs/hfsplus/super.c-635-\t\t\t}\nfs/hfsplus/super.c:636:\t\t\terr = hfsplus_create_cat(sbi-\u003ehidden_dir-\u003ei_ino, root,\nfs/hfsplus/super.c-637-\t\t\t\t\t\t \u0026str, sbi-\u003ehidden_dir);\n--\nfs/hfsplus/xattr.c=204=static int hfsplus_create_attributes_file(struct super_block *sb)\n--\nfs/hfsplus/xattr.c-329-\t * Store the fork of AttributesFile into the volume header right now.\nfs/hfsplus/xattr.c:330:\t * The AttributesFile can be created by hfsplus_cat_write_inode()\nfs/hfsplus/xattr.c-331-\t * (timestamps after 2040 are stored in xattrs) in the middle of\n--\nfs/hfsplus/xattr.c=818=int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/xattr.c-841-\nfs/hfsplus/xattr.c:842:\treturn hfsplus_set_attr_cnid(inode, cnid, xattr_name,\nfs/hfsplus/xattr.c-843-\t\t\t\t \u0026value, sizeof(value));\n"
} |
| 9/2 | 2026/10/14 04:40 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33474 output: 33 thoughts: 535 Thoughts: **Analyzing the New Timestamp Feature in HFS+** Okay, let's dive into this new timestamp feature. My immediate focus is on the specific functions that handle it: `hfsplus_get_timestamp_xattr`, `hfsplus_set_timestamp_xattr`, and `hfsplus_remove_timestamp_xattr`. These are the key entry points for the added or modified logic. First, I need to understand the call flow. `hfsplus_get_timestamp_xattr` is called by `hfsplus_read_timestamp` and `hfsplus_inode_save_timestamp`. `hfsplus_set_timestamp_xattr` is called by `hfsplus_create_cat` and `hfsplus_inode_save_timestamp`. And `hfsplus_remove_timestamp_xattr` is only called by `hfsplus_inode_save_timestamp`. Now, looking at the consumers of the more fundamental function `hfsplus_read_timestamp`: it's called in `is_create_date_identical` which is used in directory lookups, and `hfsplus_inode_read_timestamps` which runs during the `hfsplus_cat_read_inode`. `hfsplus_set_attr_cnid` is also called by `hfsplus_set_timestamp_xattr`. `hfsplus_cat_write_inode` calls `hfsplus_inode_save_timestamps` during write/sync. `hfsplus_cat_read_inode` calls `hfsplus_inode_read_timestamps` which is likely when it reads the timestamp. And finally, `hfsplus_create_cat` is responsible for setting the birthdate and creates the xattr if needed, for new files/dirs/symlinks/hardlinks. Then, `hfsplus_getattr` returns the birthdate during `statx` and `getattr`. Now, a critical piece: the configuration dependencies. I'll start with the obvious: `HFSPLUS_FS`. Does it have any specific config dependencies? Let's check `fs/hfsplus/Kconfig`. It depends on `BLOCK`, selects `BUFFER_HEAD`, selects `NLS`, `NLS_UTF8`, and `LEGACY_DIRECT_IO`. Are there other configurations that matter, maybe in `fs/hfs/Kconfig`? I need to make sure I don't miss any relevant flags. Looks like I should also check `fs/hfs/hfs_fs.h`. Let's see what `fs/hfs/Kconfig` says. |
| 10/2 | 2026/10/14 04:41 | tool | read-file |
0mArgs:{
"File": "fs/hfs/Kconfig",
"FirstLine": 1,
"LineCount": 30
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig HFS_FS\n 3:\t\ttristate \"Apple Macintosh file system support\"\n 4:\t\tdepends on BLOCK\n 5:\t\tselect BUFFER_HEAD\n 6:\t\tselect NLS\n 7:\t\tselect LEGACY_DIRECT_IO\n 8:\t\thelp\n 9:\t\t If you say Y here, you will be able to mount Macintosh-formatted\n 10:\t\t floppy disks and hard drive partitions with full read-write access.\n 11:\t\t Please read \u003cfile:Documentation/filesystems/hfs.rst\u003e to learn about\n 12:\t\t the available mount options.\n 13:\t\n 14:\t\t To compile this file system support as a module, choose M here: the\n 15:\t\t module will be called hfs.\n 16:\t\n 17:\tconfig HFS_KUNIT_TEST\n 18:\t\ttristate \"KUnit tests for HFS filesystem\" if !KUNIT_ALL_TESTS\n 19:\t\tdepends on HFS_FS \u0026\u0026 KUNIT\n 20:\t\tdefault KUNIT_ALL_TESTS\n 21:\t\thelp\n 22:\t\t This builds KUnit tests for the HFS filesystem.\n 23:\t\n 24:\t\t KUnit tests run during boot and output the results to the debug\n 25:\t\t log in TAP format (https://testanything.org/). Only useful for\n 26:\t\t kernel devs running KUnit test harness and are not for inclusion\n 27:\t\t into a production build.\n 28:\t\n 29:\t\t For more information on KUnit and unit tests in general please\n 30:\t\t refer to the KUnit documentation in Documentation/dev-tools/kunit/.\n"
} |
| 11/2 | 2026/10/14 04:41 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35059 output: 222 thoughts: 1237 Thoughts: **Analysis of HFS+ Filesystem Patch for Fuzzing** Okay, let's break this down. First, the change to `fs/hfs/hfs_fs.h` is just a cosmetic move of `HFS_UTC_OFFSET`, nothing functionally significant there for our purposes. The meat of the patch is definitely in `fs/hfsplus/`. Looking at the build configuration, we'll need `HFSPLUS_FS` and `BLOCK` enabled. I quickly checked the `Makefile` in `fs/hfsplus` to confirm that all the key modules like `super.o`, `inode.o`, `catalog.o`, and `xattr.o` are indeed built when `CONFIG_HFSPLUS_FS` is set. The `CONFIG_HFSPLUS_KUNIT_TEST` is just for KUnit tests, which are not relevant for fuzzing runtime code; we're good with just `HFSPLUS_FS` and `BLOCK`. Now, the critical part: identifying the focus symbols. We need to be precise here. I've pinpointed a list of functions that have been directly modified or added that are not ubiquitous: `hfsplus_read_timestamp`, `hfsplus_get_timestamp_xattr`, `hfsplus_set_timestamp_xattr`, `hfsplus_remove_timestamp_xattr`, `hfsplus_set_attr_cnid`, `hfsplus_cat_read_inode`, `hfsplus_cat_write_inode`, and `hfsplus_create_cat`. I also briefly considered `hfsplus_getattr`, but that is a bit generic though still specific to hfsplus, and `hfsplus_create_attributes_file` which is touched in xattr.c but I decided the primary function names were still more suitable. Checking how `hfsplus_create_attributes_file` is used, I saw that it is called by `hfsplus_set_timestamp_xattr`, and `hfsplus_create_attr_nolock` and `hfsplus_delete_attr_nolock` had their signatures changed, with `hfsplus_set_attr_cnid` calling them. These all are tied together so I went with the list above. I double-checked to ensure none of the selected functions are *ubiquitous* lifecycle hot-paths, like general memory allocators or VFS primitives, or generic VFS functions. Thankfully, they are all clearly specific to the HFS+ filesystem implementation. So, the fuzzing setup: * **EnableConfigs:** `["HFSPLUS_FS", "BLOCK"]` * **FocusSymbols:** `["hfsplus_read_timestamp", "hfsplus_get_timestamp_xattr", "hfsplus_set_timestamp_xattr", "hfsplus_remove_timestamp_xattr", "hfsplus_set_attr_cnid", "hfsplus_cat_write_inode", "hfsplus_cat_read_inode", "hfsplus_create_cat"]` * **Reasoning:** This patch series introduces 64-bit timestamp support past 2040 using hidden extended attributes on catalog records, creating attributes files during inode sync/writeback, clamping timestamps, and altering inode read/write/creation logic in the HFS+ filesystem. These specific filesystem functions have been changed, making the code relevant to be fuzzed. * **WorthFuzzing:** `true` I've confirmed the core triage philosophy – this HFS+ code is reachable in standard virtual environments and the patch introduces refactorings and logic changes. We definitely want to fuzz this. All checks are complete. Let's provide the final answer to `set-results`. |
| 12/2 | 2026/10/14 04:41 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"HFSPLUS_FS",
"BLOCK"
],
"FocusSymbols": [
"hfsplus_read_timestamp",
"hfsplus_get_timestamp_xattr",
"hfsplus_set_timestamp_xattr",
"hfsplus_remove_timestamp_xattr",
"hfsplus_set_attr_cnid",
"hfsplus_cat_write_inode",
"hfsplus_cat_read_inode",
"hfsplus_create_cat"
],
"Reasoning": "The patch modifies the HFS+ filesystem driver to extend timestamp support past February 2040 using hidden internal xattrs. This touches core filesystem operations including catalog creation, inode reading/writing, on-demand attributes file creation, and btree manipulation during inode writeback. The code is fully reachable in standard QEMU/virtualized environments by mounting or manipulating crafted HFS+ filesystem images and warrants fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"HFSPLUS_FS",
"BLOCK"
],
"FocusSymbols": [
"hfsplus_read_timestamp",
"hfsplus_get_timestamp_xattr",
"hfsplus_set_timestamp_xattr",
"hfsplus_remove_timestamp_xattr",
"hfsplus_set_attr_cnid",
"hfsplus_cat_write_inode",
"hfsplus_cat_read_inode",
"hfsplus_create_cat"
],
"Reasoning": "The patch modifies the HFS+ filesystem driver to extend timestamp support past February 2040 using hidden internal xattrs. This touches core filesystem operations including catalog creation, inode reading/writing, on-demand attributes file creation, and btree manipulation during inode writeback. The code is fully reachable in standard QEMU/virtualized environments by mounting or manipulating crafted HFS+ filesystem images and warrants fuzzing.",
"WorthFuzzing": true
} |
| 13/1 | 2026/10/14 04:41 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 14/2 | 2026/10/14 04:41 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch series adds 64-bit timestamp support to HFS+ by storing timestamps beyond February 2040 in internal extended attributes (\"linux_hfs.*\") and clamping on-disk 32-bit timestamps, along with corresponding KUnit test coverage.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and leaks of uninitialized kernel data to user space. In this patch:\n 1. All newly introduced stack structures (`struct hfsplus_timestamps`, `struct hfsplus_xattr_changes`, `struct timespec64`) are explicitly zero-initialized (`= {0}`).\n 2. In-memory inode timestamp fields (`birthdate`, `create_date`) are initialized to 0 in `hfsplus_iget()` and populated on inode read or creation.\n 3. The `statx` creation timestamp (`stat-\u003ebtime`) has both `tv_sec` and `tv_nsec` fully initialized in `hfsplus_getattr()`.\n 4. Dynamic allocations in `hfsplus_build_xattr_name()` use `kzalloc()`.\n 5. Inode/xattr record builders like `hfsplus_attr_build_record()` and `hfsplus_cat_build_record()` zero-fill record memory before writing.\n 6. Return/output arguments in helper functions (`hfsplus_read_timestamp()`, `hfsplus_get_timestamp_xattr()`) are always initialized before use, and internal xattrs are filtered from `listxattr` and user-facing APIs.\n- KASAN and standard sanitizers already adequately cover any risks related to buffer limits, memory allocations, or B-tree traversal/record bounds.\n\nTherefore, this patch series does not introduce uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit b4c9108390579ca1cf61016eb15d8e4bd23c1cac
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Oct 14 04:39:58 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h
index e250f87a5e336..659b0ba733d49 100644
--- a/fs/hfs/hfs_fs.h
+++ b/fs/hfs/hfs_fs.h
@@ -255,19 +255,6 @@ extern int hfs_mac2asc(struct super_block *sb,
/* super.c */
extern void hfs_mark_mdb_dirty(struct super_block *sb);
-/*
- * There are two time systems. Both are based on seconds since
- * a particular time/date.
- * Unix: signed little-endian since 00:00 GMT, Jan. 1, 1970
- * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
- *
- * HFS implementations are highly inconsistent, this one matches the
- * traditional behavior of 64-bit Linux, giving the most useful
- * time range between 1970 and 2106, by treating any on-disk timestamp
- * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
- */
-#define HFS_UTC_OFFSET 2082844800U
-
static inline time64_t __hfs_m_to_utime(__be32 mt)
{
time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
diff --git a/fs/hfsplus/Makefile b/fs/hfsplus/Makefile
index f2a9ae697e811..7cb0a5ef9831c 100644
--- a/fs/hfsplus/Makefile
+++ b/fs/hfsplus/Makefile
@@ -10,4 +10,4 @@ hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btre
attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
# KUnit tests
-obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += unicode_test.o
+obj-$(CONFIG_HFSPLUS_KUNIT_TEST) += hfsplus_unicode_test.o hfsplus_time_test.o
diff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c
index 7c2e589d45538..51b18d780f2c0 100644
--- a/fs/hfsplus/attributes.c
+++ b/fs/hfsplus/attributes.c
@@ -206,7 +206,8 @@ int hfsplus_attr_exists(struct inode *inode, const char *name)
}
static
-int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
+int hfsplus_create_attr_nolock(struct inode *inode, u32 cnid,
+ const char *name,
const void *value, size_t size,
struct hfs_find_data *fd,
hfsplus_attr_entry *entry_ptr)
@@ -215,12 +216,12 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
int entry_size;
int err;
- hfs_dbg("name %s, ino %llu\n",
- name ? name : NULL, inode->i_ino);
+ hfs_dbg("name %s, ino %llu, cnid %u\n",
+ name ? name : NULL, inode->i_ino, cnid);
if (name) {
err = hfsplus_attr_build_key(sb, fd->search_key,
- inode->i_ino, name);
+ cnid, name);
if (err)
return err;
} else
@@ -229,7 +230,7 @@ int hfsplus_create_attr_nolock(struct inode *inode, const char *name,
/* Mac OS X supports only inline data attributes. */
entry_size = hfsplus_attr_build_record(entry_ptr,
HFSPLUS_ATTR_INLINE_DATA,
- inode->i_ino,
+ cnid,
value, size);
if (entry_size == HFSPLUS_INVALID_ATTR_RECORD) {
if (size > HFSPLUS_MAX_INLINE_DATA_SIZE)
@@ -289,8 +290,8 @@ int hfsplus_create_attr(struct inode *inode,
if (err)
goto failed_create_attr;
- err = hfsplus_create_attr_nolock(inode, name, value, size,
- &fd, entry_ptr);
+ err = hfsplus_create_attr_nolock(inode, (u32)inode->i_ino, name,
+ value, size, &fd, entry_ptr);
if (err)
goto failed_create_attr;
@@ -347,18 +348,19 @@ static int __hfsplus_delete_attr(struct inode *inode, u32 cnid,
}
static
-int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,
+int hfsplus_delete_attr_nolock(struct inode *inode, u32 cnid,
+ const char *name,
struct hfs_find_data *fd)
{
struct super_block *sb = inode->i_sb;
int err;
- hfs_dbg("name %s, ino %llu\n",
- name ? name : NULL, inode->i_ino);
+ hfs_dbg("name %s, ino %llu, cnid %u\n",
+ name ? name : NULL, inode->i_ino, cnid);
if (name) {
err = hfsplus_attr_build_key(sb, fd->search_key,
- inode->i_ino, name);
+ cnid, name);
if (err)
return err;
} else {
@@ -373,7 +375,7 @@ int hfsplus_delete_attr_nolock(struct inode *inode, const char *name,
} else if (err)
return err;
- err = __hfsplus_delete_attr(inode, inode->i_ino, fd);
+ err = __hfsplus_delete_attr(inode, cnid, fd);
if (err)
return err;
@@ -403,7 +405,7 @@ int hfsplus_delete_attr(struct inode *inode, const char *name)
if (err)
goto out;
- err = hfsplus_delete_attr_nolock(inode, name, &fd);
+ err = hfsplus_delete_attr_nolock(inode, (u32)inode->i_ino, name, &fd);
if (err)
goto out;
@@ -481,12 +483,12 @@ int hfsplus_replace_attr(struct inode *inode,
if (err)
goto failed_replace_attr;
- err = hfsplus_delete_attr_nolock(inode, name, &fd);
+ err = hfsplus_delete_attr_nolock(inode, (u32)inode->i_ino, name, &fd);
if (err)
goto failed_replace_attr;
- err = hfsplus_create_attr_nolock(inode, name, value, size,
- &fd, entry_ptr);
+ err = hfsplus_create_attr_nolock(inode, (u32)inode->i_ino, name,
+ value, size, &fd, entry_ptr);
if (err)
goto failed_replace_attr;
@@ -497,3 +499,54 @@ int hfsplus_replace_attr(struct inode *inode,
hfsplus_destroy_attr_entry(entry_ptr);
return err;
}
+
+/*
+ * Create or replace the xattr @name of catalog record @cnid.
+ * The @inode is used only for access to the superblock and for
+ * marking the attributes tree as dirty. It is the caller's
+ * responsibility to set HFSPLUS_XATTR_EXISTS in the catalog record.
+ */
+int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,
+ const char *name,
+ const void *value, size_t size)
+{
+ struct super_block *sb = inode->i_sb;
+ struct hfs_find_data fd;
+ hfsplus_attr_entry *entry_ptr;
+ int err = 0;
+
+ hfs_dbg("name %s, ino %llu, cnid %u\n",
+ name ? name : NULL, inode->i_ino, cnid);
+
+ if (!HFSPLUS_SB(sb)->attr_tree) {
+ pr_err("attributes file doesn't exist\n");
+ return -EINVAL;
+ }
+
+ entry_ptr = hfsplus_alloc_attr_entry();
+ if (!entry_ptr)
+ return -ENOMEM;
+
+ err = hfs_find_init(HFSPLUS_SB(sb)->attr_tree, &fd);
+ if (err)
+ goto failed_init_set_attr;
+
+ /* Fail early and avoid ENOSPC during the btree operation */
+ err = hfs_bmap_reserve(fd.tree, fd.tree->depth + 1);
+ if (err)
+ goto failed_set_attr;
+
+ err = hfsplus_delete_attr_nolock(inode, cnid, name, &fd);
+ if (err && err != -ENOENT && err != -ENODATA)
+ goto failed_set_attr;
+
+ err = hfsplus_create_attr_nolock(inode, cnid, name,
+ value, size, &fd, entry_ptr);
+
+failed_set_attr:
+ hfs_find_exit(&fd);
+
+failed_init_set_attr:
+ hfsplus_destroy_attr_entry(entry_ptr);
+ return err;
+}
diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
index fe11c4b6dd997..d710419db3591 100644
--- a/fs/hfsplus/catalog.c
+++ b/fs/hfsplus/catalog.c
@@ -12,6 +12,7 @@
#include "hfsplus_fs.h"
#include "hfsplus_raw.h"
+#include "xattr.h"
int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1,
const hfsplus_btree_key *k2)
@@ -102,10 +103,63 @@ void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms)
perms->dev = 0;
}
+static void hfsplus_copy_timestamps2folder(struct hfsplus_timestamps *timestamps,
+ struct hfsplus_cat_folder *folder)
+{
+ folder->create_date = timestamps->create_date;
+ folder->content_mod_date = timestamps->content_mod_date;
+ folder->attribute_mod_date = timestamps->attribute_mod_date;
+ folder->access_date = timestamps->access_date;
+}
+
+static void hfsplus_copy_timestamps2file(struct hfsplus_timestamps *timestamps,
+ struct hfsplus_cat_file *file)
+{
+ file->create_date = timestamps->create_date;
+ file->content_mod_date = timestamps->content_mod_date;
+ file->attribute_mod_date = timestamps->attribute_mod_date;
+ file->access_date = timestamps->access_date;
+}
+
+/*
+ * Set creation date of new inode. The creation date after February 2040
+ * is stored as HFSPLUS_EXT_TIMESTAMP_MARK in the catalog record. The real
+ * value is saved into internal xattr by hfsplus_create_cat().
+ */
+static void hfsplus_set_create_date(struct inode *inode,
+ struct hfsplus_timestamps *timestamps)
+{
+ time64_t ut = ktime_get_real_seconds();
+ __be32 create_date = __hfsp_ut2mt(ut);
+
+ HFSPLUS_I(inode)->birthdate = ut;
+ HFSPLUS_I(inode)->create_date = create_date;
+
+ timestamps->create_date = create_date;
+ timestamps->content_mod_date = create_date;
+ timestamps->attribute_mod_date = create_date;
+ timestamps->access_date = create_date;
+}
+
+/*
+ * Real creation date of new catalog record. The hard link record
+ * inherits the creation date of the hidden directory.
+ */
+static time64_t hfsplus_cat_record_birthdate(u32 cnid, struct inode *inode)
+{
+ struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+
+ if (!S_ISDIR(inode->i_mode) && cnid != inode->i_ino)
+ return HFSPLUS_I(sbi->hidden_dir)->birthdate;
+
+ return HFSPLUS_I(inode)->birthdate;
+}
+
static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
- u32 cnid, struct inode *inode)
+ u32 cnid, struct inode *inode)
{
struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+ struct hfsplus_timestamps timestamps = {0};
if (S_ISDIR(inode->i_mode)) {
struct hfsplus_cat_folder *folder;
@@ -116,11 +170,12 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags))
folder->flags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);
folder->id = cpu_to_be32(inode->i_ino);
- HFSPLUS_I(inode)->create_date =
- folder->create_date =
- folder->content_mod_date =
- folder->attribute_mod_date =
- folder->access_date = hfsp_now2mt();
+
+ hfsplus_set_create_date(inode, ×tamps);
+ hfsplus_copy_timestamps2folder(×tamps, folder);
+ if (hfsp_ut_needs_xattr(HFSPLUS_I(inode)->birthdate))
+ folder->flags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);
+
hfsplus_cat_set_perms(inode, &folder->permissions);
if (inode == sbi->hidden_dir)
/* invisible and namelocked */
@@ -134,11 +189,23 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
file->type = cpu_to_be16(HFSPLUS_FILE);
file->flags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS);
file->id = cpu_to_be32(cnid);
- HFSPLUS_I(inode)->create_date =
- file->create_date =
- file->content_mod_date =
- file->attribute_mod_date =
- file->access_date = hfsp_now2mt();
+
+ if (cnid == inode->i_ino) {
+ hfsplus_set_create_date(inode, ×tamps);
+ } else {
+ /*
+ * Hard link record: don't change creation date
+ * of the linked inode.
+ */
+ __be32 now = __hfsp_ut2mt(ktime_get_real_seconds());
+
+ timestamps.create_date = now;
+ timestamps.content_mod_date = now;
+ timestamps.attribute_mod_date = now;
+ timestamps.access_date = now;
+ }
+ hfsplus_copy_timestamps2file(×tamps, file);
+
if (cnid == inode->i_ino) {
hfsplus_cat_set_perms(inode, &file->permissions);
if (S_ISLNK(inode->i_mode)) {
@@ -169,6 +236,10 @@ static int hfsplus_cat_build_record(hfsplus_cat_entry *entry,
file->permissions.dev =
cpu_to_be32(HFSPLUS_I(inode)->linkid);
}
+
+ if (hfsp_ut_needs_xattr(hfsplus_cat_record_birthdate(cnid, inode)))
+ file->flags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);
+
return sizeof(*file);
}
}
@@ -256,6 +327,7 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
struct super_block *sb = dir->i_sb;
struct hfs_find_data fd;
hfsplus_cat_entry entry;
+ time64_t birthdate;
int entry_size;
int err;
@@ -309,6 +381,22 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
if (err)
goto err1;
+ birthdate = hfsplus_cat_record_birthdate(cnid, inode);
+ if (hfsp_ut_needs_xattr(birthdate)) {
+ /*
+ * Failure is not critical: the creation date
+ * will be read as HFS_MAX_TIMESTAMP_SECS.
+ */
+ err = hfsplus_set_timestamp_xattr(inode, cnid,
+ XATTR_LINUX_CREATE_DATE_NAME,
+ birthdate);
+ if (err) {
+ pr_warn("fail to save creation date: cnid %u, err %d\n",
+ cnid, err);
+ err = 0;
+ }
+ }
+
dir->i_size++;
if (S_ISDIR(inode->i_mode))
hfsplus_subfolders_inc(dir);
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 51fcba2e6d403..af0520ebced70 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -26,6 +26,43 @@ static inline void hfsplus_instantiate(struct dentry *dentry,
d_instantiate(dentry, inode);
}
+/*
+ * Check that creation date of catalog record @cnid is identical to
+ * creation date of @inode. If the creation date is after February 2040,
+ * then the real value is compared by means of internal xattr.
+ */
+static inline bool is_create_date_identical(struct inode *inode,
+ u32 cnid, __be32 create_date)
+{
+ time64_t timestamp;
+ bool has_xattr;
+ int err;
+
+ if (create_date != HFSPLUS_I(inode)->create_date)
+ return false;
+
+ if (!hfsp_mt_is_ext_timestamp(create_date))
+ return true;
+
+ err = hfsplus_read_timestamp(inode->i_sb, cnid,
+ XATTR_LINUX_CREATE_DATE_NAME,
+ create_date, ×tamp, &has_xattr);
+ if (err) {
+ pr_err("timestamp extraction failure: cnid %u, err %d\n",
+ cnid, err);
+ return false;
+ }
+
+ /*
+ * The record without xattr (for example, created by Mac OS X)
+ * cannot be distinguished by means of 64-bit timestamp.
+ */
+ if (!has_xattr)
+ return true;
+
+ return timestamp == HFSPLUS_I(inode)->birthdate;
+}
+
/* Find the entry inside dir named dentry->d_name */
static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags)
@@ -78,12 +115,12 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
entry.file.user_info.fdCreator ==
cpu_to_be32(HFSP_HFSPLUS_CREATOR) &&
HFSPLUS_SB(sb)->hidden_dir &&
- (entry.file.create_date ==
- HFSPLUS_I(HFSPLUS_SB(sb)->hidden_dir)->
- create_date ||
- entry.file.create_date ==
- HFSPLUS_I(d_inode(sb->s_root))->
- create_date)) {
+ (is_create_date_identical(
+ HFSPLUS_SB(sb)->hidden_dir,
+ cnid, entry.file.create_date) ||
+ is_create_date_identical(
+ d_inode(sb->s_root),
+ cnid, entry.file.create_date))) {
struct qstr str;
char name[32];
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 1e5b58e6a13fc..637bba65568ec 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -175,6 +175,13 @@ static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
return sb->s_fs_info;
}
+struct hfsplus_timestamps {
+ __be32 create_date;
+ __be32 content_mod_date;
+ __be32 attribute_mod_date;
+ __be32 access_date;
+ __be32 backup_date;
+};
struct hfsplus_inode_info {
atomic_t opencnt;
@@ -196,7 +203,8 @@ struct hfsplus_inode_info {
* Immutable data.
*/
struct inode *rsrc_inode;
- __be32 create_date;
+ __be32 create_date; /* on-disk (maybe clamped) creation date */
+ time64_t birthdate; /* real creation date (seconds since 1970) */
/*
* Protected by sbi->vh_mutex.
@@ -227,6 +235,9 @@ struct hfsplus_inode_info {
#define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
#define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
#define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
+#define HFSPLUS_I_ATIME_XATTR 5 /* access date is stored in xattr */
+#define HFSPLUS_I_MTIME_XATTR 6 /* content mod date is stored in xattr */
+#define HFSPLUS_I_CTIME_XATTR 7 /* attribute mod date is stored in xattr */
#define HFSPLUS_IS_RSRC(inode) \
test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
@@ -351,6 +362,9 @@ int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
int hfsplus_replace_attr(struct inode *inode,
const char *name,
const void *value, size_t size);
+int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,
+ const char *name,
+ const void *value, size_t size);
/* bitmap.c */
int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset,
@@ -467,6 +481,9 @@ int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
int hfsplus_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
int hfsplus_fileattr_set(struct mnt_idmap *idmap,
struct dentry *dentry, struct file_kattr *fa);
+int hfsplus_read_timestamp(struct super_block *sb, u32 cnid,
+ const char *name, __be32 mt,
+ time64_t *ut, bool *has_xattr);
/* ioctl.c */
long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
@@ -532,23 +549,42 @@ int hfsplus_brec_read_cat(struct hfs_find_data *fd, hfsplus_cat_entry *entry);
/*
* time helpers: convert between 1904-base and 1970-base timestamps
*
- * HFS+ implementations are highly inconsistent, this one matches the
- * traditional behavior of 64-bit Linux, giving the most useful
- * time range between 1970 and 2106, by treating any on-disk timestamp
- * under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
+ * The on-disk 32-bit timestamps cover the range from
+ * HFS_MIN_TIMESTAMP_SECS (Jan. 1, 1904) till HFS_MAX_TIMESTAMP_SECS
+ * (Feb. 6, 2040). The timestamps out of this range are clamped.
+ * The on-disk value HFSPLUS_EXT_TIMESTAMP_MARK (maximal value) means
+ * that real timestamp could be stored in the internal xattr of
+ * the catalog record. It is Linux specific extension of
+ * HFS+ on-disk layout. It makes possible to support timestamps
+ * till HFSPLUS_MAX_TIMESTAMP_SECS.
*/
-#define HFSPLUS_UTC_OFFSET 2082844800U
+#define HFSPLUS_EXT_TIMESTAMP_MARK cpu_to_be32(U32_MAX)
+#define HFSPLUS_MAX_TIMESTAMP_SECS TIME64_MAX
static inline time64_t __hfsp_mt2ut(__be32 mt)
{
- time64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET);
+ time64_t ut = (time64_t)be32_to_cpu(mt) - HFS_UTC_OFFSET;
return ut;
}
static inline __be32 __hfsp_ut2mt(time64_t ut)
{
- return cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET);
+ ut = clamp_t(time64_t, ut,
+ HFS_MIN_TIMESTAMP_SECS, HFS_MAX_TIMESTAMP_SECS);
+ ut += HFS_UTC_OFFSET;
+
+ return cpu_to_be32(lower_32_bits(ut));
+}
+
+static inline bool hfsp_ut_needs_xattr(time64_t ut)
+{
+ return ut >= HFS_MAX_TIMESTAMP_SECS;
+}
+
+static inline bool hfsp_mt_is_ext_timestamp(__be32 mt)
+{
+ return mt == HFSPLUS_EXT_TIMESTAMP_MARK;
}
static inline enum hfsplus_btree_mutex_classes
diff --git a/fs/hfsplus/hfsplus_time_test.c b/fs/hfsplus/hfsplus_time_test.c
new file mode 100644
index 0000000000000..4b3312dc0048b
--- /dev/null
+++ b/fs/hfsplus/hfsplus_time_test.c
@@ -0,0 +1,354 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit tests for HFS+ date/time conversion
+ *
+ * Copyright (C) 2026 Viacheslav Dubeyko <slava@dubeyko.com>
+ */
+
+#include <kunit/test.h>
+#include "hfsplus_fs.h"
+#include "xattr.h"
+
+/* January 1, 1970, 00:00:00 UTC */
+#define TEST_UNIX_EPOCH_SECS 0LL
+/* December 31, 1969, 23:59:59 UTC */
+#define TEST_BEFORE_UNIX_EPOCH_SECS -1LL
+/* January 1, 2000, 00:00:00 UTC */
+#define TEST_Y2000_SECS 946684800LL
+/* January 19, 2038, 03:14:08 UTC (signed 32-bit overflow) */
+#define TEST_Y2038_SECS 2147483648LL
+/* January 1, 2026, 00:00:00 UTC */
+#define TEST_Y2026_SECS 1767225600LL
+/* January 1, 2100, 00:00:00 UTC */
+#define TEST_Y2100_SECS 4102444800LL
+/* January 1, 1900, 00:00:00 UTC */
+#define TEST_Y1900_SECS -2208988800LL
+
+static u32 mt_raw(__be32 mt)
+{
+ return be32_to_cpu(mt);
+}
+
+/* Test the time range constants */
+static void hfsplus_time_constants_test(struct kunit *test)
+{
+ /* 32-bit unsigned on-disk field covers exactly U32_MAX seconds */
+ KUNIT_EXPECT_EQ(test, (s64)U32_MAX,
+ HFS_MAX_TIMESTAMP_SECS - HFS_MIN_TIMESTAMP_SECS);
+ KUNIT_EXPECT_EQ(test, -(s64)HFS_UTC_OFFSET, HFS_MIN_TIMESTAMP_SECS);
+
+ /* xattrs extend the supported range beyond February 2040 */
+ KUNIT_EXPECT_GT(test, (s64)HFSPLUS_MAX_TIMESTAMP_SECS,
+ (s64)HFS_MAX_TIMESTAMP_SECS);
+
+ /* the extended timestamp mark is the maximal on-disk value */
+ KUNIT_EXPECT_EQ(test, U32_MAX, mt_raw(HFSPLUS_EXT_TIMESTAMP_MARK));
+}
+
+/* Test conversion of on-disk (1904-based) timestamp into 1970-based one */
+static void hfsplus_mt2ut_test(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, HFS_MIN_TIMESTAMP_SECS,
+ __hfsp_mt2ut(cpu_to_be32(0)));
+ KUNIT_EXPECT_EQ(test, TEST_UNIX_EPOCH_SECS,
+ __hfsp_mt2ut(cpu_to_be32(HFS_UTC_OFFSET)));
+ KUNIT_EXPECT_EQ(test, TEST_BEFORE_UNIX_EPOCH_SECS,
+ __hfsp_mt2ut(cpu_to_be32(HFS_UTC_OFFSET - 1)));
+ KUNIT_EXPECT_EQ(test, TEST_Y2000_SECS,
+ __hfsp_mt2ut(cpu_to_be32(3029529600U)));
+ KUNIT_EXPECT_EQ(test, TEST_Y2026_SECS,
+ __hfsp_mt2ut(cpu_to_be32(3850070400U)));
+ KUNIT_EXPECT_EQ(test, TEST_Y2038_SECS,
+ __hfsp_mt2ut(cpu_to_be32(4230328448U)));
+ KUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS,
+ __hfsp_mt2ut(cpu_to_be32(U32_MAX)));
+ KUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS,
+ __hfsp_mt2ut(HFSPLUS_EXT_TIMESTAMP_MARK));
+}
+
+/* Test conversion of 1970-based timestamp into on-disk (1904-based) one */
+static void hfsplus_ut2mt_test(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(HFS_MIN_TIMESTAMP_SECS)));
+ KUNIT_EXPECT_EQ(test, HFS_UTC_OFFSET,
+ mt_raw(__hfsp_ut2mt(TEST_UNIX_EPOCH_SECS)));
+ KUNIT_EXPECT_EQ(test, 3029529600U,
+ mt_raw(__hfsp_ut2mt(TEST_Y2000_SECS)));
+ KUNIT_EXPECT_EQ(test, 3850070400U,
+ mt_raw(__hfsp_ut2mt(TEST_Y2026_SECS)));
+ KUNIT_EXPECT_EQ(test, 4230328448U,
+ mt_raw(__hfsp_ut2mt(TEST_Y2038_SECS)));
+ KUNIT_EXPECT_EQ(test, U32_MAX - 1,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS - 1)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS)));
+}
+
+/*
+ * Test timestamps before January 1, 1970 (xfstests generic/258).
+ * The old logic added HFS_UTC_OFFSET to lower 32 bits of negative
+ * value and produced completely wrong result.
+ */
+static void hfsplus_ut2mt_before_1970_test(struct kunit *test)
+{
+ time64_t ut;
+
+ KUNIT_EXPECT_EQ(test, HFS_UTC_OFFSET - 1,
+ mt_raw(__hfsp_ut2mt(TEST_BEFORE_UNIX_EPOCH_SECS)));
+
+ /* January 1, 1960, 00:00:00 UTC */
+ ut = -315619200LL;
+ KUNIT_EXPECT_EQ(test, ut, __hfsp_mt2ut(__hfsp_ut2mt(ut)));
+
+ /* January 1, 1904, 00:00:01 UTC */
+ ut = HFS_MIN_TIMESTAMP_SECS + 1;
+ KUNIT_EXPECT_EQ(test, 1U, mt_raw(__hfsp_ut2mt(ut)));
+ KUNIT_EXPECT_EQ(test, ut, __hfsp_mt2ut(__hfsp_ut2mt(ut)));
+}
+
+/* Test that out-of-range timestamps are clamped instead of wrapped */
+static void hfsplus_ut2mt_clamp_test(struct kunit *test)
+{
+ /* below January 1, 1904 */
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(HFS_MIN_TIMESTAMP_SECS - 1)));
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(TEST_Y1900_SECS)));
+ KUNIT_EXPECT_EQ(test, 0U,
+ mt_raw(__hfsp_ut2mt(TIME64_MIN)));
+
+ /* after February 6, 2040 */
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS + 1)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(TEST_Y2100_SECS)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFSPLUS_MAX_TIMESTAMP_SECS)));
+
+ /* lower 32 bits of these values would wrap into small dates */
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS +
+ (s64)U32_MAX + 1)));
+ KUNIT_EXPECT_EQ(test, U32_MAX,
+ mt_raw(__hfsp_ut2mt(1LL << 32)));
+}
+
+/* Test that representable timestamps survive the round trip */
+static void hfsplus_time_roundtrip_test(struct kunit *test)
+{
+ static const time64_t values[] = {
+ HFS_MIN_TIMESTAMP_SECS,
+ HFS_MIN_TIMESTAMP_SECS + 1,
+ TEST_BEFORE_UNIX_EPOCH_SECS,
+ TEST_UNIX_EPOCH_SECS,
+ 1,
+ TEST_Y2000_SECS,
+ TEST_Y2026_SECS,
+ (s64)S32_MAX,
+ TEST_Y2038_SECS,
+ HFS_MAX_TIMESTAMP_SECS - 1,
+ HFS_MAX_TIMESTAMP_SECS,
+ };
+ time64_t ut;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(values); i++) {
+ KUNIT_EXPECT_EQ_MSG(test, values[i],
+ __hfsp_mt2ut(__hfsp_ut2mt(values[i])),
+ "round trip failed: index %d", i);
+ }
+
+ /* sweep the whole range with a large prime step */
+ for (ut = HFS_MIN_TIMESTAMP_SECS; ut <= HFS_MAX_TIMESTAMP_SECS;
+ ut += 999983) {
+ if (__hfsp_mt2ut(__hfsp_ut2mt(ut)) != ut) {
+ KUNIT_FAIL(test, "round trip failed: ut %lld", ut);
+ break;
+ }
+ }
+
+ /* every on-disk value maps back to itself */
+ for (i = 0; i < 32; i++) {
+ u32 raw = (u32)BIT_ULL(i);
+
+ KUNIT_EXPECT_EQ(test, raw,
+ mt_raw(__hfsp_ut2mt(__hfsp_mt2ut(cpu_to_be32(raw)))));
+ }
+}
+
+/* Test the decision to keep timestamp in xattr */
+static void hfsplus_ut_needs_xattr_test(struct kunit *test)
+{
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(HFS_MIN_TIMESTAMP_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_BEFORE_UNIX_EPOCH_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_UNIX_EPOCH_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_Y2026_SECS));
+ KUNIT_EXPECT_FALSE(test, hfsp_ut_needs_xattr(TEST_Y2038_SECS));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS - 1));
+
+ KUNIT_EXPECT_TRUE(test, hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_ut_needs_xattr(HFS_MAX_TIMESTAMP_SECS + 1));
+ KUNIT_EXPECT_TRUE(test, hfsp_ut_needs_xattr(TEST_Y2100_SECS));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_ut_needs_xattr(HFSPLUS_MAX_TIMESTAMP_SECS));
+}
+
+/* Test detection of the extended timestamp mark */
+static void hfsplus_mt_is_ext_timestamp_test(struct kunit *test)
+{
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(HFSPLUS_EXT_TIMESTAMP_MARK));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(cpu_to_be32(U32_MAX)));
+
+ KUNIT_EXPECT_FALSE(test, hfsp_mt_is_ext_timestamp(cpu_to_be32(0)));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_mt_is_ext_timestamp(cpu_to_be32(U32_MAX - 1)));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_mt_is_ext_timestamp(cpu_to_be32(HFS_UTC_OFFSET)));
+
+ /* every timestamp that needs xattr is stored as the mark */
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS)));
+ KUNIT_EXPECT_TRUE(test,
+ hfsp_mt_is_ext_timestamp(__hfsp_ut2mt(TEST_Y2100_SECS)));
+ KUNIT_EXPECT_FALSE(test,
+ hfsp_mt_is_ext_timestamp(__hfsp_ut2mt(HFS_MAX_TIMESTAMP_SECS - 1)));
+}
+
+static struct super_block *alloc_mock_sb(struct kunit *test)
+{
+ struct super_block *sb;
+ struct hfsplus_sb_info *sbi;
+
+ sb = kunit_kzalloc(test, sizeof(*sb), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sb);
+
+ sbi = kunit_kzalloc(test, sizeof(*sbi), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sbi);
+
+ /* no attributes tree: xattr lookup returns -EOPNOTSUPP */
+ sbi->attr_tree = NULL;
+ sb->s_fs_info = sbi;
+
+ return sb;
+}
+
+/*
+ * Test reading of the on-disk timestamp that doesn't need xattr.
+ * The superblock must not be touched in such case.
+ */
+static void hfsplus_read_timestamp_regular_test(struct kunit *test)
+{
+ static const time64_t values[] = {
+ HFS_MIN_TIMESTAMP_SECS,
+ TEST_BEFORE_UNIX_EPOCH_SECS,
+ TEST_UNIX_EPOCH_SECS,
+ TEST_Y2026_SECS,
+ HFS_MAX_TIMESTAMP_SECS - 1,
+ };
+ time64_t ut;
+ bool has_xattr;
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(values); i++) {
+ ut = 0;
+ has_xattr = true;
+
+ err = hfsplus_read_timestamp(NULL, HFSPLUS_FIRSTUSER_CNID,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ __hfsp_ut2mt(values[i]),
+ &ut, &has_xattr);
+ KUNIT_EXPECT_EQ(test, 0, err);
+ KUNIT_EXPECT_EQ(test, values[i], ut);
+ KUNIT_EXPECT_FALSE(test, has_xattr);
+ }
+}
+
+/*
+ * Test reading of the extended timestamp mark without xattr
+ * (for example, the record has been created by Mac OS X or
+ * the volume has no attributes tree). The timestamp must be
+ * HFS_MAX_TIMESTAMP_SECS without any error.
+ */
+static void hfsplus_read_timestamp_mark_no_xattr_test(struct kunit *test)
+{
+ struct super_block *sb = alloc_mock_sb(test);
+ static const char * const names[] = {
+ XATTR_LINUX_CREATE_DATE_NAME,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ };
+ time64_t ut;
+ bool has_xattr;
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(names); i++) {
+ ut = 0;
+ has_xattr = true;
+
+ err = hfsplus_read_timestamp(sb, HFSPLUS_FIRSTUSER_CNID,
+ names[i],
+ HFSPLUS_EXT_TIMESTAMP_MARK,
+ &ut, &has_xattr);
+ KUNIT_EXPECT_EQ(test, 0, err);
+ KUNIT_EXPECT_EQ(test, HFS_MAX_TIMESTAMP_SECS, ut);
+ KUNIT_EXPECT_FALSE(test, has_xattr);
+ }
+}
+
+/* Test that names of internal xattrs fit the name buffer */
+static void hfsplus_timestamp_xattr_names_test(struct kunit *test)
+{
+ static const char * const names[] = {
+ XATTR_LINUX_CREATE_DATE_NAME,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ XATTR_LINUX_BACKUP_DATE_NAME,
+ };
+ int i;
+
+ KUNIT_EXPECT_EQ(test, strlen(XATTR_LINUX_HFS_PREFIX),
+ (size_t)XATTR_LINUX_HFS_PREFIX_LEN);
+
+ for (i = 0; i < ARRAY_SIZE(names); i++) {
+ size_t len = XATTR_LINUX_HFS_PREFIX_LEN + strlen(names[i]);
+
+ KUNIT_EXPECT_LT_MSG(test, len, (size_t)XATTR_LINUX_HFS_NAME_MAX,
+ "name %s is too long", names[i]);
+ KUNIT_EXPECT_LE(test, len, (size_t)HFSPLUS_ATTR_MAX_STRLEN);
+ }
+}
+
+static struct kunit_case hfsplus_time_test_cases[] = {
+ KUNIT_CASE(hfsplus_time_constants_test),
+ KUNIT_CASE(hfsplus_mt2ut_test),
+ KUNIT_CASE(hfsplus_ut2mt_test),
+ KUNIT_CASE(hfsplus_ut2mt_before_1970_test),
+ KUNIT_CASE(hfsplus_ut2mt_clamp_test),
+ KUNIT_CASE(hfsplus_time_roundtrip_test),
+ KUNIT_CASE(hfsplus_ut_needs_xattr_test),
+ KUNIT_CASE(hfsplus_mt_is_ext_timestamp_test),
+ KUNIT_CASE(hfsplus_read_timestamp_regular_test),
+ KUNIT_CASE(hfsplus_read_timestamp_mark_no_xattr_test),
+ KUNIT_CASE(hfsplus_timestamp_xattr_names_test),
+ {}
+};
+
+static struct kunit_suite hfsplus_time_test_suite = {
+ .name = "hfsplus_time",
+ .test_cases = hfsplus_time_test_cases,
+};
+
+kunit_test_suite(hfsplus_time_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for HFS+ date/time conversion");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
diff --git a/fs/hfsplus/unicode_test.c b/fs/hfsplus/hfsplus_unicode_test.c
similarity index 100%
rename from fs/hfsplus/unicode_test.c
rename to fs/hfsplus/hfsplus_unicode_test.c
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 2ce6de574fa6e..0df58dfda5a3e 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -18,6 +18,7 @@
#include <linux/cred.h>
#include <linux/uio.h>
#include <linux/fileattr.h>
+#include <kunit/visibility.h>
#include "hfsplus_fs.h"
#include "hfsplus_raw.h"
@@ -344,7 +345,8 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,
if (request_mask & STATX_BTIME) {
stat->result_mask |= STATX_BTIME;
- stat->btime = hfsp_mt2ut(hip->create_date);
+ stat->btime.tv_sec = hip->birthdate;
+ stat->btime.tv_nsec = 0;
}
if (inode->i_flags & S_APPEND)
@@ -598,9 +600,139 @@ void hfsplus_inode_write_fork(struct inode *inode,
fork->total_blocks = cpu_to_be32(HFSPLUS_I(inode)->alloc_blocks);
}
+/*
+ * hfsplus_read_timestamp - convert on-disk timestamp into 1970-base one
+ * @sb: superblock
+ * @cnid: catalog record ID
+ * @name: name of internal xattr that can keep the real timestamp
+ * @mt: on-disk timestamp
+ * @ut: pointer on converted timestamp [out]
+ * @has_xattr: pointer on flag that xattr exists [out]
+ *
+ * If on-disk timestamp is equal to HFSPLUS_EXT_TIMESTAMP_MARK, then
+ * the real timestamp (after February 2040) could be stored in
+ * the internal xattr. If the xattr is absent (for example, the record
+ * has been created by Mac OS X), then HFS_MAX_TIMESTAMP_SECS is used.
+ */
+int hfsplus_read_timestamp(struct super_block *sb, u32 cnid,
+ const char *name, __be32 mt,
+ time64_t *ut, bool *has_xattr)
+{
+ time64_t timestamp;
+ int err;
+
+ *ut = __hfsp_mt2ut(mt);
+ *has_xattr = false;
+
+ if (!hfsp_mt_is_ext_timestamp(mt))
+ return 0;
+
+ err = hfsplus_get_timestamp_xattr(sb, cnid, name, ×tamp);
+ if (err == -ENODATA || err == -EOPNOTSUPP) {
+ /* timestamp is really equal to HFS_MAX_TIMESTAMP_SECS */
+ return 0;
+ } else if (unlikely(err)) {
+ pr_warn("fail to extract timestamp: cnid %u, name %s, err %d\n",
+ cnid, name, err);
+ return err;
+ }
+
+ if (timestamp < HFS_MAX_TIMESTAMP_SECS) {
+ pr_warn("invalid timestamp in xattr: cnid %u, name %s, timestamp %lld\n",
+ cnid, name, timestamp);
+ /* keep xattr to be deleted or overwritten */
+ *has_xattr = true;
+ } else {
+ *ut = timestamp;
+ *has_xattr = true;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_IF_KUNIT(hfsplus_read_timestamp);
+
+static int hfsplus_inode_read_timestamps(struct inode *inode,
+ struct hfsplus_timestamps *timestamps)
+{
+ struct super_block *sb = inode->i_sb;
+ struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+ u32 cnid = inode->i_ino;
+ struct timespec64 ts = {0};
+ bool has_xattr;
+ int res = 0;
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ timestamps->access_date,
+ &ts.tv_sec, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ inode_set_atime_to_ts(inode, ts);
+ if (has_xattr)
+ set_bit(HFSPLUS_I_ATIME_XATTR, &hip->flags);
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ timestamps->content_mod_date,
+ &ts.tv_sec, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ inode_set_mtime_to_ts(inode, ts);
+ if (has_xattr)
+ set_bit(HFSPLUS_I_MTIME_XATTR, &hip->flags);
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ timestamps->attribute_mod_date,
+ &ts.tv_sec, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ inode_set_ctime_to_ts(inode, ts);
+ if (has_xattr)
+ set_bit(HFSPLUS_I_CTIME_XATTR, &hip->flags);
+
+ res = hfsplus_read_timestamp(sb, cnid,
+ XATTR_LINUX_CREATE_DATE_NAME,
+ timestamps->create_date,
+ &hip->birthdate, &has_xattr);
+ if (res)
+ goto finish_read_timestamps;
+
+ hip->create_date = timestamps->create_date;
+
+finish_read_timestamps:
+ return res;
+}
+
+static inline void
+hfsplus_copy_folder2timestamps(struct hfsplus_cat_folder *folder,
+ struct hfsplus_timestamps *timestamps)
+{
+ timestamps->create_date = folder->create_date;
+ timestamps->content_mod_date = folder->content_mod_date;
+ timestamps->attribute_mod_date = folder->attribute_mod_date;
+ timestamps->access_date = folder->access_date;
+ timestamps->backup_date = folder->backup_date;
+}
+
+static inline void
+hfsplus_copy_file2timestamps(struct hfsplus_cat_file *file,
+ struct hfsplus_timestamps *timestamps)
+{
+ timestamps->create_date = file->create_date;
+ timestamps->content_mod_date = file->content_mod_date;
+ timestamps->attribute_mod_date = file->attribute_mod_date;
+ timestamps->access_date = file->access_date;
+ timestamps->backup_date = file->backup_date;
+}
+
int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
{
hfsplus_cat_entry entry;
+ struct hfsplus_timestamps timestamps = {0};
int res = 0;
u16 type;
@@ -622,12 +754,14 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
goto out;
set_nlink(inode, 1);
inode->i_size = 2 + be32_to_cpu(folder->valence);
- inode_set_atime_to_ts(inode, hfsp_mt2ut(folder->access_date));
- inode_set_mtime_to_ts(inode,
- hfsp_mt2ut(folder->content_mod_date));
- inode_set_ctime_to_ts(inode,
- hfsp_mt2ut(folder->attribute_mod_date));
- HFSPLUS_I(inode)->create_date = folder->create_date;
+
+ hfsplus_copy_folder2timestamps(folder, ×tamps);
+ res = hfsplus_inode_read_timestamps(inode, ×tamps);
+ if (res) {
+ res = -EIO;
+ goto out;
+ }
+
HFSPLUS_I(inode)->fs_blocks = 0;
if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
HFSPLUS_I(inode)->subfolders =
@@ -668,12 +802,13 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
init_special_inode(inode, inode->i_mode,
be32_to_cpu(file->permissions.dev));
}
- inode_set_atime_to_ts(inode, hfsp_mt2ut(file->access_date));
- inode_set_mtime_to_ts(inode,
- hfsp_mt2ut(file->content_mod_date));
- inode_set_ctime_to_ts(inode,
- hfsp_mt2ut(file->attribute_mod_date));
- HFSPLUS_I(inode)->create_date = file->create_date;
+
+ hfsplus_copy_file2timestamps(file, ×tamps);
+ res = hfsplus_inode_read_timestamps(inode, ×tamps);
+ if (res) {
+ res = -EIO;
+ goto out;
+ }
} else {
pr_err("bad catalog entry used to create inode\n");
res = -EIO;
@@ -682,12 +817,126 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
return res;
}
+struct hfsplus_xattr_changes {
+ bool added;
+ bool removed;
+};
+
+/*
+ * Convert @ts into on-disk timestamp. The timestamp after February 2040
+ * is stored as HFSPLUS_EXT_TIMESTAMP_MARK with the real value in
+ * the internal xattr @name. The stale xattr is removed if timestamp
+ * becomes representable by on-disk field.
+ */
+static int hfsplus_inode_save_timestamp(struct inode *inode,
+ const char *name, int xattr_bit,
+ struct timespec64 ts, __be32 *date,
+ struct hfsplus_xattr_changes *xattr)
+{
+ struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+ time64_t stored;
+ int err;
+
+ *date = __hfsp_ut2mt(ts.tv_sec);
+
+ if (hfsp_ut_needs_xattr(ts.tv_sec)) {
+ /* don't rewrite xattr if nothing has been changed */
+ if (test_bit(xattr_bit, &hip->flags)) {
+ err = hfsplus_get_timestamp_xattr(inode->i_sb,
+ inode->i_ino,
+ name,
+ &stored);
+ if (!err && stored == ts.tv_sec)
+ return 0;
+ }
+
+ err = hfsplus_set_timestamp_xattr(inode, inode->i_ino,
+ name, ts.tv_sec);
+ if (err) {
+ clear_bit(xattr_bit, &hip->flags);
+ return err;
+ }
+
+ set_bit(xattr_bit, &hip->flags);
+ xattr->added = true;
+ } else if (test_bit(xattr_bit, &hip->flags)) {
+ err = hfsplus_remove_timestamp_xattr(inode, name);
+ if (err)
+ return err;
+
+ clear_bit(xattr_bit, &hip->flags);
+ xattr->removed = true;
+ }
+
+ return 0;
+}
+
+static void hfsplus_inode_save_timestamps(struct inode *inode,
+ struct hfsplus_timestamps *timestamps,
+ struct hfsplus_xattr_changes *changes)
+{
+ int res;
+
+ /*
+ * Failure of xattr operation is not critical. The timestamp
+ * is clamped by HFS_MAX_TIMESTAMP_SECS in such case.
+ * But the rest of the catalog record must be saved anyway.
+ */
+
+ res = hfsplus_inode_save_timestamp(inode,
+ XATTR_LINUX_ACCESS_DATE_NAME,
+ HFSPLUS_I_ATIME_XATTR,
+ inode_get_atime(inode),
+ ×tamps->access_date,
+ changes);
+ if (res) {
+ pr_warn_ratelimited("fail to save access date: ino %llu, err %d\n",
+ inode->i_ino, res);
+ }
+
+ res = hfsplus_inode_save_timestamp(inode,
+ XATTR_LINUX_CONTENT_MOD_DATE_NAME,
+ HFSPLUS_I_MTIME_XATTR,
+ inode_get_mtime(inode),
+ ×tamps->content_mod_date,
+ changes);
+ if (res) {
+ pr_warn_ratelimited("fail to save content mod date: ino %llu, err %d\n",
+ inode->i_ino, res);
+ }
+
+ res = hfsplus_inode_save_timestamp(inode,
+ XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME,
+ HFSPLUS_I_CTIME_XATTR,
+ inode_get_ctime(inode),
+ ×tamps->attribute_mod_date,
+ changes);
+ if (res) {
+ pr_warn_ratelimited("fail to save attribute mod date: ino %llu, err %d\n",
+ inode->i_ino, res);
+ }
+}
+
+static inline __be16
+hfsplus_update_xattr_exists_flag(struct inode *inode, __be16 flags,
+ struct hfsplus_xattr_changes *xattr)
+{
+ if (xattr->added)
+ flags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);
+ else if (xattr->removed && !hfsplus_attr_exists(inode, NULL))
+ flags &= cpu_to_be16(~HFSPLUS_XATTR_EXISTS);
+
+ return flags;
+}
+
int hfsplus_cat_write_inode(struct inode *inode)
{
struct inode *main_inode = inode;
struct hfs_btree *tree = HFSPLUS_SB(inode->i_sb)->cat_tree;
struct hfs_find_data fd;
hfsplus_cat_entry entry;
+ struct hfsplus_timestamps timestamps = {0};
+ struct hfsplus_xattr_changes changes = {0};
int res = 0;
hfs_dbg("inode->i_ino %llu\n", inode->i_ino);
@@ -718,9 +967,15 @@ int hfsplus_cat_write_inode(struct inode *inode)
sizeof(struct hfsplus_cat_folder));
/* simple node checks? */
hfsplus_cat_set_perms(inode, &folder->permissions);
- folder->access_date = hfsp_ut2mt(inode_get_atime(inode));
- folder->content_mod_date = hfsp_ut2mt(inode_get_mtime(inode));
- folder->attribute_mod_date = hfsp_ut2mt(inode_get_ctime(inode));
+
+ hfsplus_inode_save_timestamps(inode, ×tamps, &changes);
+ folder->access_date = timestamps.access_date;
+ folder->content_mod_date = timestamps.content_mod_date;
+ folder->attribute_mod_date = timestamps.attribute_mod_date;
+ folder->flags = hfsplus_update_xattr_exists_flag(inode,
+ folder->flags,
+ &changes);
+
folder->valence = cpu_to_be32(inode->i_size - 2);
if (folder->flags & cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT)) {
folder->subfolders =
@@ -753,9 +1008,15 @@ int hfsplus_cat_write_inode(struct inode *inode)
file->flags |= cpu_to_be16(HFSPLUS_FILE_LOCKED);
else
file->flags &= cpu_to_be16(~HFSPLUS_FILE_LOCKED);
- file->access_date = hfsp_ut2mt(inode_get_atime(inode));
- file->content_mod_date = hfsp_ut2mt(inode_get_mtime(inode));
- file->attribute_mod_date = hfsp_ut2mt(inode_get_ctime(inode));
+
+ hfsplus_inode_save_timestamps(inode, ×tamps, &changes);
+ file->access_date = timestamps.access_date;
+ file->content_mod_date = timestamps.content_mod_date;
+ file->attribute_mod_date = timestamps.attribute_mod_date;
+ file->flags = hfsplus_update_xattr_exists_flag(inode,
+ file->flags,
+ &changes);
+
hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
sizeof(struct hfsplus_cat_file));
}
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index ff7d6b3336a66..b10b53f6f8f9e 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -86,6 +86,7 @@ struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
mutex_init(&HFSPLUS_I(inode)->extents_lock);
HFSPLUS_I(inode)->rsrc_inode = NULL;
HFSPLUS_I(inode)->create_date = 0;
+ HFSPLUS_I(inode)->birthdate = 0;
HFSPLUS_I(inode)->linkid = 0;
HFSPLUS_I(inode)->flags = 0;
HFSPLUS_I(inode)->fs_blocks = 0;
@@ -511,6 +512,13 @@ static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)
if (!sbi->rsrc_clump_blocks)
sbi->rsrc_clump_blocks = 1;
+ sb->s_time_gran = NSEC_PER_SEC;
+ sb->s_time_min = HFS_MIN_TIMESTAMP_SECS;
+ /*
+ * Timestamps after HFS_MAX_TIMESTAMP_SECS are stored in xattrs.
+ */
+ sb->s_time_max = HFS_MAX_TIMESTAMP_SECS;
+
err = -EFBIG;
last_fs_block = sbi->total_blocks - 1;
last_fs_page = (last_fs_block << sbi->alloc_blksz_shift) >>
diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index 21a1c196c71f2..d3b1734496168 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -50,6 +50,12 @@ static bool is_known_namespace(const char *name)
return true;
}
+static bool is_linux_hfs_internal_xattr(const char *name)
+{
+ return !strncmp(name, XATTR_LINUX_HFS_PREFIX,
+ XATTR_LINUX_HFS_PREFIX_LEN);
+}
+
static u32 hfsplus_init_header_node(struct inode *attr_file,
u32 clump_size,
char *buf, u16 node_size)
@@ -319,6 +325,19 @@ static int hfsplus_create_attributes_file(struct super_block *sb)
hfsplus_mark_inode_dirty(attr_file, HFSPLUS_I_ATTR_DIRTY);
+ /*
+ * Store the fork of AttributesFile into the volume header right now.
+ * The AttributesFile can be created by hfsplus_cat_write_inode()
+ * (timestamps after 2040 are stored in xattrs) in the middle of
+ * sync operation. Then, the dirty AttributesFile's inode can be
+ * skipped by writeback and the volume header will be committed
+ * without AttributesFile. As a result, the AttributesFile will be
+ * not opened during the next mount.
+ */
+ hfsplus_inode_write_fork(attr_file, &sbi->s_vhdr->attr_file);
+ set_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags);
+ hfsplus_mark_mdb_dirty(sb);
+
sbi->attr_tree = hfs_btree_open(sb, HFSPLUS_ATTR_CNID);
if (!sbi->attr_tree)
pr_err("failed to load attributes file\n");
@@ -339,8 +358,7 @@ static int hfsplus_create_attributes_file(struct super_block *sb)
return err;
}
-static inline
-bool is_xattr_operation_supported(struct inode *inode)
+static inline bool is_xattr_operation_supported(struct inode *inode)
{
if (HFSPLUS_IS_RSRC(inode))
return false;
@@ -609,8 +627,9 @@ static ssize_t hfsplus_getxattr_finder_info(struct inode *inode,
return res;
}
-ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
- void *value, size_t size)
+static ssize_t __hfsplus_getxattr_nocheck(struct super_block *sb,
+ u32 cnid, const char *name,
+ void *value, size_t size)
{
struct hfs_find_data fd;
hfsplus_attr_entry *entry;
@@ -619,13 +638,7 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
u16 record_length = 0;
ssize_t res;
- if (!is_xattr_operation_supported(inode))
- return -EOPNOTSUPP;
-
- if (!strcmp_xattr_finder_info(name))
- return hfsplus_getxattr_finder_info(inode, value, size);
-
- if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
+ if (!HFSPLUS_SB(sb)->attr_tree)
return -EOPNOTSUPP;
entry = hfsplus_alloc_attr_entry();
@@ -634,18 +647,18 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
return -ENOMEM;
}
- res = hfs_find_init(HFSPLUS_SB(inode->i_sb)->attr_tree, &fd);
+ res = hfs_find_init(HFSPLUS_SB(sb)->attr_tree, &fd);
if (res) {
pr_err("can't init xattr find struct\n");
goto failed_getxattr_init;
}
- res = hfsplus_find_attr(inode->i_sb, inode->i_ino, name, &fd);
+ res = hfsplus_find_attr(sb, cnid, name, &fd);
if (res) {
if (res == -ENOENT || res == -ENODATA)
res = -ENODATA;
else
- pr_err("xattr search failed\n");
+ pr_err("xattr searching failed\n");
goto out;
}
@@ -693,6 +706,38 @@ ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
return res;
}
+static inline ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
+ void *value, size_t size)
+{
+ if (!is_xattr_operation_supported(inode))
+ return -EOPNOTSUPP;
+
+ if (!strcmp_xattr_finder_info(name))
+ return hfsplus_getxattr_finder_info(inode, value, size);
+
+ return __hfsplus_getxattr_nocheck(inode->i_sb, (u32)inode->i_ino,
+ name, value, size);
+}
+
+static inline char *hfsplus_build_xattr_name(const char *name,
+ const char *prefix,
+ size_t prefixlen)
+{
+ char *xattr_name;
+ size_t len = NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1;
+
+ xattr_name = kzalloc(len, GFP_KERNEL);
+ if (!xattr_name)
+ return ERR_PTR(-ENOMEM);
+
+ if (snprintf(xattr_name, len, "%s%s", prefix, name) >= len) {
+ kfree(xattr_name);
+ return ERR_PTR(-ENAMETOOLONG);
+ }
+
+ return xattr_name;
+}
+
ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
void *value, size_t size,
const char *prefix, size_t prefixlen)
@@ -704,13 +749,9 @@ ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
inode->i_ino, name ? name : NULL,
prefix ? prefix : NULL);
- xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1,
- GFP_KERNEL);
- if (!xattr_name)
- return -ENOMEM;
-
- strcpy(xattr_name, prefix);
- strcpy(xattr_name + prefixlen, name);
+ xattr_name = hfsplus_build_xattr_name(name, prefix, prefixlen);
+ if (IS_ERR(xattr_name))
+ return PTR_ERR(xattr_name);
res = __hfsplus_getxattr(inode, xattr_name, value, size);
kfree(xattr_name);
@@ -718,7 +759,114 @@ ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
hfs_dbg("finished: res %d\n", res);
return res;
+}
+
+static ssize_t hfsplus_getxattr_nocheck(struct super_block *sb, u32 cnid,
+ const char *name,
+ void *value, size_t size,
+ const char *prefix, size_t prefixlen)
+{
+ int res;
+ char *xattr_name;
+ hfs_dbg("cnid %u, name %s, prefix %s\n",
+ cnid, name ? name : NULL,
+ prefix ? prefix : NULL);
+
+ xattr_name = hfsplus_build_xattr_name(name, prefix, prefixlen);
+ if (IS_ERR(xattr_name))
+ return PTR_ERR(xattr_name);
+
+ res = __hfsplus_getxattr_nocheck(sb, cnid, xattr_name, value, size);
+ kfree(xattr_name);
+
+ hfs_dbg("finished: res %d\n", res);
+
+ return res;
+}
+
+/*
+ * Get the timestamp stored in the internal xattr @name
+ * of catalog record @cnid. The caller can hold the catalog tree lock.
+ */
+int hfsplus_get_timestamp_xattr(struct super_block *sb, u32 cnid,
+ const char *name, time64_t *ts)
+{
+ __be64 value;
+ ssize_t res;
+
+ res = hfsplus_getxattr_nocheck(sb, cnid, name,
+ &value, sizeof(value),
+ XATTR_LINUX_HFS_PREFIX,
+ XATTR_LINUX_HFS_PREFIX_LEN);
+ if (res < 0)
+ return res;
+
+ if (res != sizeof(value))
+ return -EIO;
+
+ *ts = (time64_t)be64_to_cpu(value);
+ return 0;
+}
+
+/*
+ * Store the timestamp @ts into the internal xattr @name of catalog
+ * record @cnid. The caller must hold the catalog tree lock and it is
+ * caller's responsibility to set HFSPLUS_XATTR_EXISTS flag in
+ * the catalog record.
+ */
+int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,
+ const char *name, time64_t ts)
+{
+ struct super_block *sb = inode->i_sb;
+ char xattr_name[XATTR_LINUX_HFS_NAME_MAX];
+ __be64 value = cpu_to_be64(ts);
+ int err;
+
+ hfs_dbg("ino %llu, cnid %u, name %s, ts %lld\n",
+ inode->i_ino, cnid, name, ts);
+
+ if (!HFSPLUS_SB(sb)->attr_tree) {
+ err = hfsplus_create_attributes_file(sb);
+ if (unlikely(err))
+ return err;
+
+ if (!HFSPLUS_SB(sb)->attr_tree)
+ return -EIO;
+ }
+
+ if (snprintf(xattr_name, sizeof(xattr_name), "%s%s",
+ XATTR_LINUX_HFS_PREFIX, name) >= sizeof(xattr_name))
+ return -ENAMETOOLONG;
+
+ return hfsplus_set_attr_cnid(inode, cnid, xattr_name,
+ &value, sizeof(value));
+}
+
+/*
+ * Remove the internal xattr @name of @inode. The caller must hold
+ * the catalog tree lock and it is caller's responsibility to update
+ * HFSPLUS_XATTR_EXISTS flag in the catalog record.
+ */
+int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name)
+{
+ char xattr_name[XATTR_LINUX_HFS_NAME_MAX];
+ int err;
+
+ hfs_dbg("ino %llu, name %s\n", inode->i_ino, name);
+
+ if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
+ return 0;
+
+ if (snprintf(xattr_name, sizeof(xattr_name), "%s%s",
+ XATTR_LINUX_HFS_PREFIX, name) >= sizeof(xattr_name))
+ return -ENAMETOOLONG;
+
+ err = hfsplus_delete_attr(inode, xattr_name);
+ if (err == -ENOENT || err == -ENODATA)
+ err = 0;
+
+ return err;
}
static inline int can_list(const char *xattr_name)
@@ -726,6 +874,10 @@ static inline int can_list(const char *xattr_name)
if (!xattr_name)
return 0;
+ /* Internal xattrs of the driver are hidden */
+ if (is_linux_hfs_internal_xattr(xattr_name))
+ return 0;
+
return strncmp(xattr_name, XATTR_TRUSTED_PREFIX,
XATTR_TRUSTED_PREFIX_LEN) ||
capable(CAP_SYS_ADMIN);
@@ -998,6 +1150,10 @@ static int hfsplus_osx_getxattr(const struct xattr_handler *handler,
if (is_known_namespace(name))
return -EOPNOTSUPP;
+ /* Internal xattrs of the driver are hidden */
+ if (is_linux_hfs_internal_xattr(name))
+ return -EOPNOTSUPP;
+
/*
* osx is the namespace we use to indicate an unprefixed
* attribute on the filesystem (like the ones that OS X
@@ -1020,6 +1176,10 @@ static int hfsplus_osx_setxattr(const struct xattr_handler *handler,
if (is_known_namespace(name))
return -EOPNOTSUPP;
+ /* Internal xattrs of the driver cannot be changed by user */
+ if (is_linux_hfs_internal_xattr(name))
+ return -EOPNOTSUPP;
+
/*
* osx is the namespace we use to indicate an unprefixed
* attribute on the filesystem (like the ones that OS X
diff --git a/fs/hfsplus/xattr.h b/fs/hfsplus/xattr.h
index 15cc55e414100..8f6283f85f133 100644
--- a/fs/hfsplus/xattr.h
+++ b/fs/hfsplus/xattr.h
@@ -12,6 +12,24 @@
#include <linux/xattr.h>
+/*
+ * Internal xattrs of Linux HFS+ driver. Timestamps beyond
+ * HFS_MAX_TIMESTAMP_SECS (February 2040) cannot be represented by
+ * 32-bit on-disk fields. Such timestamp is stored as the maximal value
+ * (HFSPLUS_EXT_TIMESTAMP_MARK) in the catalog record and the real value
+ * is kept in the xattr as big-endian 64-bit seconds since
+ * 00:00 GMT, Jan. 1, 1970.
+ */
+#define XATTR_LINUX_HFS_PREFIX "linux_hfs."
+#define XATTR_LINUX_HFS_PREFIX_LEN \
+ (sizeof(XATTR_LINUX_HFS_PREFIX) - 1)
+#define XATTR_LINUX_HFS_NAME_MAX 64
+#define XATTR_LINUX_CREATE_DATE_NAME "create_date_u64"
+#define XATTR_LINUX_CONTENT_MOD_DATE_NAME "content_mod_date_u64"
+#define XATTR_LINUX_ATTRIBUTE_MOD_DATE_NAME "attribute_mod_date_u64"
+#define XATTR_LINUX_ACCESS_DATE_NAME "access_date_u64"
+#define XATTR_LINUX_BACKUP_DATE_NAME "backup_date_u64"
+
extern const struct xattr_handler hfsplus_xattr_osx_handler;
extern const struct xattr_handler hfsplus_xattr_user_handler;
extern const struct xattr_handler hfsplus_xattr_trusted_handler;
@@ -23,16 +41,18 @@ int __hfsplus_setxattr(struct inode *inode, const char *name,
const void *value, size_t size, int flags);
int hfsplus_setxattr(struct inode *inode, const char *name,
- const void *value, size_t size, int flags,
- const char *prefix, size_t prefixlen);
-
-ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,
- void *value, size_t size);
-
+ const void *value, size_t size, int flags,
+ const char *prefix, size_t prefixlen);
ssize_t hfsplus_getxattr(struct inode *inode, const char *name,
void *value, size_t size,
const char *prefix, size_t prefixlen);
+int hfsplus_get_timestamp_xattr(struct super_block *sb, u32 cnid,
+ const char *name, time64_t *ts);
+int hfsplus_set_timestamp_xattr(struct inode *inode, u32 cnid,
+ const char *name, time64_t ts);
+int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name);
+
ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
int hfsplus_init_security(struct inode *inode, struct inode *dir,
diff --git a/include/linux/hfs_common.h b/include/linux/hfs_common.h
index d6a615e74b26e..d4e91dea23628 100644
--- a/include/linux/hfs_common.h
+++ b/include/linux/hfs_common.h
@@ -667,4 +667,17 @@ typedef union {
struct hfsplus_attr_key attr;
} __packed hfsplus_btree_key;
+/*
+ * There are two time systems. Both are based on seconds since
+ * a particular time/date.
+ * Unix: signed little-endian since 00:00 GMT, Jan. 1, 1970
+ * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
+ */
+#define HFS_UTC_OFFSET 2082844800U
+
+/* January 1, 1904, 00:00:00 UTC */
+#define HFS_MIN_TIMESTAMP_SECS -2082844800LL
+/* February 6, 2040, 06:28:15 UTC */
+#define HFS_MAX_TIMESTAMP_SECS 2212122495LL
+
#endif /* _HFS_COMMON_H_ */
|
| 15/3 | 2026/10/14 04:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25110 output: 36 thoughts: 541 Thoughts: **Analyzing the HFS+ 64-bit Timestamp Patch Series** Okay, let's dive into this patch series. My initial concern is always uninitialized memory access, potential information leaks to userspace, or uninitialized branching that KMSAN would catch. We need to be meticulous. First, the diff touches a range of files within the HFS and HFS+ filesystems: `hfs_fs.h`, `hfsplus/Makefile`, a suite of `*.c` files (attributes, catalog, directory, inode, super, xattr), and a `hfsplus_time_test.c`, along with associated header files. The broad stroke here is adding 64-bit timestamp support to HFS+. The approach is to store timestamps past Feb 6, 2040 (the 32-bit timestamp limit) within internal extended attributes, prefixed `linux_hfs.<timestamp_name>`, and clamped to `HFSPLUS_EXT_TIMESTAMP_MARK` on disk. We also get KUnit tests for time conversion which is good. Now for the details. `include/linux/hfs_common.h` moves the definitions for `HFS_UTC_OFFSET`, `HFS_MIN_TIMESTAMP_SECS`, and `HFS_MAX_TIMESTAMP_SECS` from `hfs_fs.h`. That's a refactoring, pretty standard. The `fs/hfsplus/attributes.c` file has the most interesting changes. The functions `hfsplus_create_attr_nolock` and `hfsplus_delete_attr_nolock` now take a `cnid` parameter, which is a nice improvement by avoiding `inode->i_ino` use. There's a new function `hfsplus_set_attr_cnid` to handle creating or replacing xattr's on a given catalog record, which means a new `hfsplus_alloc_attr_entry()` is called to allocate `entry_ptr`, and that looks like the heart of the change and is where uninitialized memory or info leaks could start. We have a set of calls involving `hfs_find_init`, `hfsplus_delete_attr_nolock`, and `hfsplus_create_attr_nolock`. So, the key point is around that `hfsplus_alloc_attr_entry()` call and what `entry_ptr` does. This is where I'll focus most of my attention. I'll need to either grep for that function or read the code closely to understand the allocation and initialization of `entry_ptr`. That's where any vulnerabilities are likely to lurk. I need to understand how the xattr storage is managed here. |
| 16/3 | 2026/10/14 04:41 | tool | grepper |
0mArgs:{
"Expression": "hfsplus_alloc_attr_entry",
"PathPrefixes": [
"fs/hfsplus/"
]
}Results: {
"Output": "fs/hfsplus/attributes.c=50=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\n--\nfs/hfsplus/attributes.c-83-\nfs/hfsplus/attributes.c:84:hfsplus_attr_entry *hfsplus_alloc_attr_entry(void)\nfs/hfsplus/attributes.c-85-{\n--\nfs/hfsplus/attributes.c=263=int hfsplus_create_attr(struct inode *inode,\n--\nfs/hfsplus/attributes.c-279-\nfs/hfsplus/attributes.c:280:\tentry_ptr = hfsplus_alloc_attr_entry();\nfs/hfsplus/attributes.c-281-\tif (!entry_ptr)\n--\nfs/hfsplus/attributes.c=456=int hfsplus_replace_attr(struct inode *inode,\n--\nfs/hfsplus/attributes.c-472-\nfs/hfsplus/attributes.c:473:\tentry_ptr = hfsplus_alloc_attr_entry();\nfs/hfsplus/attributes.c-474-\tif (!entry_ptr)\n--\nfs/hfsplus/attributes.c=509=int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/attributes.c-525-\nfs/hfsplus/attributes.c:526:\tentry_ptr = hfsplus_alloc_attr_entry();\nfs/hfsplus/attributes.c-527-\tif (!entry_ptr)\n--\nfs/hfsplus/hfsplus_fs.h=351=int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,\nfs/hfsplus/hfsplus_fs.h-352-\t\t\t u32 cnid, const char *name);\nfs/hfsplus/hfsplus_fs.h:353:hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);\nfs/hfsplus/hfsplus_fs.h-354-void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry);\n--\nfs/hfsplus/xattr.c=630=static ssize_t __hfsplus_getxattr_nocheck(struct super_block *sb,\n--\nfs/hfsplus/xattr.c-643-\nfs/hfsplus/xattr.c:644:\tentry = hfsplus_alloc_attr_entry();\nfs/hfsplus/xattr.c-645-\tif (!entry) {\n"
} |
| 17/3 | 2026/10/14 04:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26968 output: 36 thoughts: 27 Thoughts: Okay, let's dive into this. Here's my take on understanding this code: **Analyzing `hfsplus_alloc_attr_entry` in `fs/hfsplus/attributes.c`** Alright, I'm heading into the `fs/hfsplus/attributes.c` file. Specifically, I'm focusing in on the `hfsplus_alloc_attr_entry` function. This function has to be key to how HFS+ manages attribute allocation, which is a critical aspect of how the file system functions. I'm already anticipating this is where I'll find the logic for how attribute entries are created, organized, and tracked within the HFS+ structure. I need to understand this to have a solid grasp of HFS+ attribute handling at a low level. It's time to dig in and decipher its internal mechanisms. |
| 18/3 | 2026/10/14 04:41 | tool | read-file |
0mArgs:{
"File": "fs/hfsplus/attributes.c",
"FirstLine": 80,
"LineCount": 30
}Results: {
"Contents": " 80:\t\n 81:\t\treturn 0;\n 82:\t}\n 83:\t\n 84:\thfsplus_attr_entry *hfsplus_alloc_attr_entry(void)\n 85:\t{\n 86:\t\treturn kmem_cache_alloc(hfsplus_attr_tree_cachep, GFP_KERNEL);\n 87:\t}\n 88:\t\n 89:\tvoid hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry)\n 90:\t{\n 91:\t\tif (entry)\n 92:\t\t\tkmem_cache_free(hfsplus_attr_tree_cachep, entry);\n 93:\t}\n 94:\t\n 95:\t#define HFSPLUS_INVALID_ATTR_RECORD -1\n 96:\t\n 97:\tstatic int hfsplus_attr_build_record(hfsplus_attr_entry *entry, int record_type,\n 98:\t\t\t\t\tu32 cnid, const void *value, size_t size)\n 99:\t{\n 100:\t\tif (record_type == HFSPLUS_ATTR_FORK_DATA) {\n 101:\t\t\t/*\n 102:\t\t\t * Mac OS X supports only inline data attributes.\n 103:\t\t\t * Do nothing\n 104:\t\t\t */\n 105:\t\t\tmemset(entry, 0, sizeof(*entry));\n 106:\t\t\treturn sizeof(struct hfsplus_attr_fork_data);\n 107:\t\t} else if (record_type == HFSPLUS_ATTR_EXTENTS) {\n 108:\t\t\t/*\n 109:\t\t\t * Mac OS X supports only inline data attributes.\n"
} |
| 19/3 | 2026/10/14 04:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27659 output: 37 thoughts: 15 Thoughts: Here's a summary of my thought process: **Diving into `hfsplus_attr_build_record`** Okay, let's get down to brass tacks. I'm going to take a closer look at the `hfsplus_attr_build_record` function. I need to understand exactly how this crucial function works. My gut tells me it's responsible for the construction of attribute records within the HFS+ filesystem, but I need to solidify that understanding. I'll need to dissect its implementation to grasp the intricacies of how it structures and populates these records, probably considering the various data types and attributes it has to handle. I'll be scrutinizing the logic, paying close attention to any edge cases or potential vulnerabilities related to data allocation, record size calculations, and alignment. Knowing this thoroughly will aid my overall analysis. |
| 20/3 | 2026/10/14 04:41 | tool | read-file |
0mArgs:{
"File": "fs/hfsplus/attributes.c",
"FirstLine": 105,
"LineCount": 45
}Results: {
"Contents": " 105:\t\t\tmemset(entry, 0, sizeof(*entry));\n 106:\t\t\treturn sizeof(struct hfsplus_attr_fork_data);\n 107:\t\t} else if (record_type == HFSPLUS_ATTR_EXTENTS) {\n 108:\t\t\t/*\n 109:\t\t\t * Mac OS X supports only inline data attributes.\n 110:\t\t\t * Do nothing.\n 111:\t\t\t */\n 112:\t\t\tmemset(entry, 0, sizeof(*entry));\n 113:\t\t\treturn sizeof(struct hfsplus_attr_extents);\n 114:\t\t} else if (record_type == HFSPLUS_ATTR_INLINE_DATA) {\n 115:\t\t\tu16 len;\n 116:\t\n 117:\t\t\tmemset(entry, 0, sizeof(struct hfsplus_attr_inline_data));\n 118:\t\t\tentry-\u003einline_data.record_type = cpu_to_be32(record_type);\n 119:\t\t\tif (size \u003c= HFSPLUS_MAX_INLINE_DATA_SIZE)\n 120:\t\t\t\tlen = size;\n 121:\t\t\telse {\n 122:\t\t\t\thfs_dbg(\"value size %zu is too big\\n\", size);\n 123:\t\t\t\treturn HFSPLUS_INVALID_ATTR_RECORD;\n 124:\t\t\t}\n 125:\t\t\tentry-\u003einline_data.length = cpu_to_be16(len);\n 126:\t\t\tmemcpy(entry-\u003einline_data.raw_bytes, value, len);\n 127:\t\t\t/*\n 128:\t\t\t * Align len on two-byte boundary.\n 129:\t\t\t * It needs to add pad byte if we have odd len.\n 130:\t\t\t */\n 131:\t\t\tlen = round_up(len, 2);\n 132:\t\t\treturn offsetof(struct hfsplus_attr_inline_data, raw_bytes) +\n 133:\t\t\t\t\t\tlen;\n 134:\t\t} else /* invalid input */\n 135:\t\t\tmemset(entry, 0, sizeof(*entry));\n 136:\t\n 137:\t\treturn HFSPLUS_INVALID_ATTR_RECORD;\n 138:\t}\n 139:\t\n 140:\tint hfsplus_find_attr(struct super_block *sb, u32 cnid,\n 141:\t\t\t\tconst char *name, struct hfs_find_data *fd)\n 142:\t{\n 143:\t\tint err = 0;\n 144:\t\n 145:\t\thfs_dbg(\"name %s, cnid %d\\n\", name ? name : NULL, cnid);\n 146:\t\n 147:\t\tif (!HFSPLUS_SB(sb)-\u003eattr_tree) {\n 148:\t\t\tpr_err(\"attributes file doesn't exist\\n\");\n 149:\t\t\treturn -EINVAL;\n"
} |
| 21/3 | 2026/10/14 04:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28643 output: 38 thoughts: 1298 Thoughts: **Analyzing HFS+ Extended Attributes and Timestamps** Okay, so I'm looking at this HFS+ code, and I'm zeroing out `entry` with `memset` before filling it. Good practice. I'm digging into how extended attributes (xattrs) are handled. Specifically, let's look at `hfsplus_build_xattr_name`. It uses `kzalloc` to allocate memory for the xattr name, which is good because it ensures the memory is initialized to zero. That's one less potential issue to worry about. Now, let's consider the `is_create_date_identical` function. It's comparing create dates. The code checks if the create date is different from the inode's create date. If they're equal, it moves on, which looks correct. However, if the create date is an extended timestamp, it calls `hfsplus_read_timestamp`. This is where it gets interesting, as it checks for an xattr with the create timestamp. I'm now focusing on `hfsplus_read_timestamp` and `hfsplus_get_timestamp_xattr` because these handle reading the extended timestamp. In `hfsplus_read_timestamp`, it calls `hfsplus_get_timestamp_xattr`. And in `hfsplus_get_timestamp_xattr`, there's a local `__be64 value` on the stack. Here's the critical point: `hfsplus_getxattr_nocheck` is called with the address of `value`. Now, `hfsplus_getxattr_nocheck` itself doesn't initialize `value`. So, if `hfsplus_getxattr_nocheck` returns the correct size (8 bytes), the code dereferences that uninitialized, or rather, potentially garbage, value. That means `*ts = (time64_t)be64_to_cpu(value);` is reading a potentially uninitialized value. I really need to check the exact behavior of `__hfsplus_getxattr_nocheck` in `fs/hfsplus/xattr.c` from lines 630 to 710 to be absolutely sure what it's doing with `value` on the stack. This might be a subtle but critical bug. |
| 22/3 | 2026/10/14 04:41 | tool | read-file |
0mArgs:{
"File": "fs/hfsplus/xattr.c",
"FirstLine": 635,
"LineCount": 80
}Results: {
"Contents": " 635:\t\thfsplus_attr_entry *entry;\n 636:\t\t__be32 xattr_record_type;\n 637:\t\tu32 record_type;\n 638:\t\tu16 record_length = 0;\n 639:\t\tssize_t res;\n 640:\t\n 641:\t\tif (!HFSPLUS_SB(sb)-\u003eattr_tree)\n 642:\t\t\treturn -EOPNOTSUPP;\n 643:\t\n 644:\t\tentry = hfsplus_alloc_attr_entry();\n 645:\t\tif (!entry) {\n 646:\t\t\tpr_err(\"can't allocate xattr entry\\n\");\n 647:\t\t\treturn -ENOMEM;\n 648:\t\t}\n 649:\t\n 650:\t\tres = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\n 651:\t\tif (res) {\n 652:\t\t\tpr_err(\"can't init xattr find struct\\n\");\n 653:\t\t\tgoto failed_getxattr_init;\n 654:\t\t}\n 655:\t\n 656:\t\tres = hfsplus_find_attr(sb, cnid, name, \u0026fd);\n 657:\t\tif (res) {\n 658:\t\t\tif (res == -ENOENT || res == -ENODATA)\n 659:\t\t\t\tres = -ENODATA;\n 660:\t\t\telse\n 661:\t\t\t\tpr_err(\"xattr searching failed\\n\");\n 662:\t\t\tgoto out;\n 663:\t\t}\n 664:\t\n 665:\t\thfs_bnode_read(fd.bnode, \u0026xattr_record_type,\n 666:\t\t\t\tfd.entryoffset, sizeof(xattr_record_type));\n 667:\t\trecord_type = be32_to_cpu(xattr_record_type);\n 668:\t\tif (record_type == HFSPLUS_ATTR_INLINE_DATA) {\n 669:\t\t\trecord_length = hfs_bnode_read_u16(fd.bnode,\n 670:\t\t\t\t\tfd.entryoffset +\n 671:\t\t\t\t\toffsetof(struct hfsplus_attr_inline_data,\n 672:\t\t\t\t\tlength));\n 673:\t\t\tif (record_length \u003e HFSPLUS_MAX_INLINE_DATA_SIZE) {\n 674:\t\t\t\tpr_err(\"invalid xattr record size\\n\");\n 675:\t\t\t\tres = -EIO;\n 676:\t\t\t\tgoto out;\n 677:\t\t\t}\n 678:\t\t} else if (record_type == HFSPLUS_ATTR_FORK_DATA ||\n 679:\t\t\t\trecord_type == HFSPLUS_ATTR_EXTENTS) {\n 680:\t\t\tpr_err(\"only inline data xattr are supported\\n\");\n 681:\t\t\tres = -EOPNOTSUPP;\n 682:\t\t\tgoto out;\n 683:\t\t} else {\n 684:\t\t\tpr_err(\"invalid xattr record\\n\");\n 685:\t\t\tres = -EIO;\n 686:\t\t\tgoto out;\n 687:\t\t}\n 688:\t\n 689:\t\tif (size) {\n 690:\t\t\thfs_bnode_read(fd.bnode, entry, fd.entryoffset,\n 691:\t\t\t\t\toffsetof(struct hfsplus_attr_inline_data,\n 692:\t\t\t\t\t\traw_bytes) + record_length);\n 693:\t\t}\n 694:\t\n 695:\t\tif (size \u003e= record_length) {\n 696:\t\t\tmemcpy(value, entry-\u003einline_data.raw_bytes, record_length);\n 697:\t\t\tres = record_length;\n 698:\t\t} else\n 699:\t\t\tres = size ? -ERANGE : record_length;\n 700:\t\n 701:\tout:\n 702:\t\thfs_find_exit(\u0026fd);\n 703:\t\n 704:\tfailed_getxattr_init:\n 705:\t\thfsplus_destroy_attr_entry(entry);\n 706:\t\treturn res;\n 707:\t}\n 708:\t\n 709:\tstatic inline ssize_t __hfsplus_getxattr(struct inode *inode, const char *name,\n 710:\t\t\t\t\t\t void *value, size_t size)\n 711:\t{\n 712:\t\tif (!is_xattr_operation_supported(inode))\n 713:\t\t\treturn -EOPNOTSUPP;\n 714:\t\n"
} |
| 23/3 | 2026/10/14 04:41 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31705 output: 31 thoughts: 519 Thoughts: **Analyzing Potential Information Leaks in the HFS+ Filesystem** Okay, let's break this down. I'm focusing on a specific code block (lines 695-699), particularly the `memcpy` operation. The critical point is that if `res` equals the size of `value`, then the `memcpy` copies exactly the full size of `value`, which is 8 bytes in this scenario. If `record_length` isn't 8, then it's clear `res` won't equal `sizeof(value)`. This gives a clear condition for when `value` is completely written. However, I need to consider user-space implications. Are there any potential information leaks to user space through xattrs? To investigate this, I'm checking for places where timestamps or internal xattrs could be accessed. I notice the `is_linux_hfs_internal_xattr` function, which seems crucial. It checks if an xattr name starts with "XATTR_LINUX_HFS_PREFIX," which I assume is an internal prefix. I examined `hfsplus_listxattr`, `hfsplus_osx_getxattr`, and `hfsplus_osx_setxattr`. In all three functions, the `is_linux_hfs_internal_xattr` function is used to hide internal xattrs. `hfsplus_listxattr` simply filters them out while the other two return an error if the user tries to access them. Now, I'm thinking, are there *other* xattr handlers that *might* access xattrs that start with the prefix? To be thorough, I will need to grep for instances of the string `xattr_handler` across the hfsplus file system. I should have a good idea of which potential handlers exist after that step. |
| 24/3 | 2026/10/14 04:42 | tool | grepper |
0mArgs:{
"Expression": "xattr_handler",
"PathPrefixes": [
"fs/hfsplus/"
]
}Results: {
"Output": "fs/hfsplus/super.c=453=static int hfsplus_fill_super(struct super_block *sb, struct fs_context *fc)\n--\nfs/hfsplus/super.c-572-\t}\nfs/hfsplus/super.c:573:\tsb-\u003es_xattr = hfsplus_xattr_handlers;\nfs/hfsplus/super.c-574-\n--\nfs/hfsplus/xattr.c=14=static int hfsplus_removexattr(struct inode *inode, const char *name);\nfs/hfsplus/xattr.c-15-\nfs/hfsplus/xattr.c:16:const struct xattr_handler * const hfsplus_xattr_handlers[] = {\nfs/hfsplus/xattr.c-17-\t\u0026hfsplus_xattr_osx_handler,\n--\nfs/hfsplus/xattr.c=1058=static int hfsplus_removexattr(struct inode *inode, const char *name)\n--\nfs/hfsplus/xattr.c-1141-\nfs/hfsplus/xattr.c:1142:static int hfsplus_osx_getxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr.c-1143-\t\t\t\tstruct dentry *unused, struct inode *inode,\n--\nfs/hfsplus/xattr.c-1165-\nfs/hfsplus/xattr.c:1166:static int hfsplus_osx_setxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr.c-1167-\t\t\t\tstruct mnt_idmap *idmap,\n--\nfs/hfsplus/xattr.c-1191-\nfs/hfsplus/xattr.c:1192:const struct xattr_handler hfsplus_xattr_osx_handler = {\nfs/hfsplus/xattr.c-1193-\t.prefix\t= XATTR_MAC_OSX_PREFIX,\n--\nfs/hfsplus/xattr.h-32-\nfs/hfsplus/xattr.h:33:extern const struct xattr_handler hfsplus_xattr_osx_handler;\nfs/hfsplus/xattr.h:34:extern const struct xattr_handler hfsplus_xattr_user_handler;\nfs/hfsplus/xattr.h:35:extern const struct xattr_handler hfsplus_xattr_trusted_handler;\nfs/hfsplus/xattr.h:36:extern const struct xattr_handler hfsplus_xattr_security_handler;\nfs/hfsplus/xattr.h-37-\nfs/hfsplus/xattr.h:38:extern const struct xattr_handler * const hfsplus_xattr_handlers[];\nfs/hfsplus/xattr.h-39-\n--\nfs/hfsplus/xattr_security.c-15-\nfs/hfsplus/xattr_security.c:16:static int hfsplus_security_getxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr_security.c-17-\t\t\t\t struct dentry *unused, struct inode *inode,\n--\nfs/hfsplus/xattr_security.c-24-\nfs/hfsplus/xattr_security.c:25:static int hfsplus_security_setxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr_security.c-26-\t\t\t\t struct mnt_idmap *idmap,\n--\nfs/hfsplus/xattr_security.c=68=int hfsplus_init_security(struct inode *inode, struct inode *dir,\n--\nfs/hfsplus/xattr_security.c-74-\nfs/hfsplus/xattr_security.c:75:const struct xattr_handler hfsplus_xattr_security_handler = {\nfs/hfsplus/xattr_security.c-76-\t.prefix\t= XATTR_SECURITY_PREFIX,\n--\nfs/hfsplus/xattr_trusted.c-14-\nfs/hfsplus/xattr_trusted.c:15:static int hfsplus_trusted_getxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr_trusted.c-16-\t\t\t\t struct dentry *unused, struct inode *inode,\n--\nfs/hfsplus/xattr_trusted.c-23-\nfs/hfsplus/xattr_trusted.c:24:static int hfsplus_trusted_setxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr_trusted.c-25-\t\t\t\t struct mnt_idmap *idmap,\n--\nfs/hfsplus/xattr_trusted.c-33-\nfs/hfsplus/xattr_trusted.c:34:const struct xattr_handler hfsplus_xattr_trusted_handler = {\nfs/hfsplus/xattr_trusted.c-35-\t.prefix\t= XATTR_TRUSTED_PREFIX,\n--\nfs/hfsplus/xattr_user.c-14-\nfs/hfsplus/xattr_user.c:15:static int hfsplus_user_getxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr_user.c-16-\t\t\t\t struct dentry *unused, struct inode *inode,\n--\nfs/hfsplus/xattr_user.c-23-\nfs/hfsplus/xattr_user.c:24:static int hfsplus_user_setxattr(const struct xattr_handler *handler,\nfs/hfsplus/xattr_user.c-25-\t\t\t\t struct mnt_idmap *idmap,\n--\nfs/hfsplus/xattr_user.c-33-\nfs/hfsplus/xattr_user.c:34:const struct xattr_handler hfsplus_xattr_user_handler = {\nfs/hfsplus/xattr_user.c-35-\t.prefix\t= XATTR_USER_PREFIX,\n"
} |
| 25/3 | 2026/10/14 04:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34193 output: 39 thoughts: 111 Thoughts: **Examining Attribute Handler Logic** Okay, so I'm thinking through how these security attributes are handled. It seems pretty standard – user, trusted, and security handlers all tack on their own prefixes to the attributes, which is good for organization and avoiding collisions. The `osx` handler, though, is a bit of an outlier, picking up unprefixed attributes. But, ah, right, it does a check with `is_known_namespace` and now `is_linux_hfs_internal_xattr`. That makes sense. Ensures we're not stepping on anything we shouldn't. But then, a thought strikes me: what about `hfsplus_removexattr`? If we're careful on the *get* side, we need to be just as cautious on the *remove* side. Let's see how this is implemented. I need to take a look at the `fs/hfsplus/xattr.c` file and dive into the `hfsplus_removexattr` implementation. I need to make sure this isn't leaving a vulnerability for a malicious actor. |
| 26/3 | 2026/10/14 04:42 | tool | read-file |
0mArgs:{
"File": "fs/hfsplus/xattr.c",
"FirstLine": 1055,
"LineCount": 40
}Results: {
"Contents": "1055:\t\treturn res;\n1056:\t}\n1057:\t\n1058:\tstatic int hfsplus_removexattr(struct inode *inode, const char *name)\n1059:\t{\n1060:\t\tint err;\n1061:\t\tstruct hfs_find_data cat_fd;\n1062:\t\tu16 flags;\n1063:\t\tu16 cat_entry_type;\n1064:\t\tint is_xattr_acl_deleted;\n1065:\t\tint is_all_xattrs_deleted;\n1066:\t\n1067:\t\thfs_dbg(\"ino %llu, name %s\\n\",\n1068:\t\t\tinode-\u003ei_ino, name ? name : NULL);\n1069:\t\n1070:\t\tif (!HFSPLUS_SB(inode-\u003ei_sb)-\u003eattr_tree)\n1071:\t\t\treturn -EOPNOTSUPP;\n1072:\t\n1073:\t\tif (!strcmp_xattr_finder_info(name))\n1074:\t\t\treturn -EOPNOTSUPP;\n1075:\t\n1076:\t\terr = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003ecat_tree, \u0026cat_fd);\n1077:\t\tif (err) {\n1078:\t\t\tpr_err(\"can't init xattr find struct\\n\");\n1079:\t\t\treturn err;\n1080:\t\t}\n1081:\t\n1082:\t\terr = hfsplus_find_cat(inode-\u003ei_sb, inode-\u003ei_ino, \u0026cat_fd);\n1083:\t\tif (err) {\n1084:\t\t\tpr_err(\"catalog searching failed\\n\");\n1085:\t\t\tgoto end_removexattr;\n1086:\t\t}\n1087:\t\n1088:\t\terr = hfsplus_delete_attr(inode, name);\n1089:\t\tif (err)\n1090:\t\t\tgoto end_removexattr;\n1091:\t\n1092:\t\tis_xattr_acl_deleted = !strcmp_xattr_acl(name);\n1093:\t\tis_all_xattrs_deleted = !hfsplus_attr_exists(inode, NULL);\n1094:\t\n"
} |
| 27/3 | 2026/10/14 04:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35189 output: 33 thoughts: 3124 Thoughts: **HFS+ Attribute Timestamp Analysis**
Okay, let's break this down systematically. My initial concern was uninitialized memory potentially leading to incorrect `btime` values in `statx()`. After tracing the code paths, I am quite certain that the `birthdate` field in `hfsplus` inodes is properly initialized. I see that `HFSPLUS_I(inode)->birthdate` is explicitly set to zero during inode initialization in `hfsplus_iget()`. It is also zeroed when creating a new inode via `hfsplus_set_create_date()`. Furthermore, it is read and set during inode read via `hfsplus_inode_read_timestamps` through `hfsplus_read_timestamp()`. Therefore, `stat->btime.tv_sec = hip->birthdate; stat->btime.tv_nsec = 0;` should always be safe and deterministic.
Now, let's carefully go through the timestamp logic within `hfsplus_inode_read_timestamps()`. The local `struct timespec64 ts` is initialized to zero (`{0}`). Then, `hfsplus_read_timestamp()` writes to `&ts.tv_sec`, and then this is used to populate atime, mtime, and ctime. While `ts.tv_nsec` remains zero, which is correct and expected.
Looking at `hfsplus_cat_build_record()`, `hfsplus_cat_write_inode()`, and `hfsplus_cat_read_inode()`, it is clear that `struct hfsplus_timestamps timestamps` are initialized to zero using either `memset` or `{0}` in these functions as well. This ensures all timestamp fields are explicitly set to their default values.
I noticed a key function, `hfsplus_read_timestamp()`, and now I must ensure this is safe. First, it assigns the result of `__hfsp_mt2ut()` (which returns a maximum timestamp in case the input is the mark for an extended timestamp) to the output value. Then, I see `hfsplus_get_timestamp_xattr()` is called to retrieve the timestamp xattr. If there is no such xattr, then the timestamp is not an extended timestamp, and the value from `__hfsp_mt2ut()` is used, and the function returns. If there is an error, this error is propagated. If the timestamp read from the extended attribute is invalid (too small), the behavior is to keep the xattr and not overwrite it.
Let's double-check the `hfsplus_get_timestamp_xattr()` function to confirm this. Here, the timestamp is read from the xattr. The code reads the xattr value and casts it to a `time64_t`. Crucially, `hfsplus_getxattr_nocheck()` is used to retrieve the value. The size check ensures the attribute is completely read. The `value` is later copied into via `memcpy(value, entry->inline_data.raw_bytes, record_length)` as the code iterates over the btree. This confirms the value read is fully initialized.
Now, if `hfsplus_get_timestamp_xattr()` fails (returns error), `hfsplus_read_timestamp()` uses the HFS+ metadata value (`__hfsp_mt2ut()`) instead, guaranteeing initialization.
Let me also check how timestamps are written via xattrs, especially through `hfsplus_set_timestamp_xattr()`. The code transforms the `ts` into a `__be64` value. The function calls `hfsplus_set_attr_cnid()`. Within that function, there is another check. The `memset(entry, 0, sizeof(struct hfsplus_attr_inline_data))` ensures the entry is zeroed. The code uses `hfsplus_attr_build_record()` to build the attribute record. Here, the inline data is zeroed, and the data is then copied into the btree.
Let's ensure the `hfs_find_init` function correctly initializes `fd`.
I need to keep in mind, even if `hfs_find_init` has a bug, the structure should be safely initialized at the beginning of `hfsplus_set_attr_cnid()`. I think the problem is covered by checking how other function call `hfs_find_init`.
|
| 28/3 | 2026/10/14 04:42 | tool | grepper |
0mArgs:{
"Expression": "hfs_find_init",
"PathPrefixes": [
"fs/hfsplus/"
]
}Results: {
"Output": "fs/hfsplus/attributes.c=180=int hfsplus_attr_exists(struct inode *inode, const char *name)\n--\nfs/hfsplus/attributes.c-191-\nfs/hfsplus/attributes.c:192:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-193-\tif (err)\n--\nfs/hfsplus/attributes.c=263=int hfsplus_create_attr(struct inode *inode,\n--\nfs/hfsplus/attributes.c-283-\nfs/hfsplus/attributes.c:284:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-285-\tif (err)\n--\nfs/hfsplus/attributes.c=385=int hfsplus_delete_attr(struct inode *inode, const char *name)\n--\nfs/hfsplus/attributes.c-398-\nfs/hfsplus/attributes.c:399:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-400-\tif (err)\n--\nfs/hfsplus/attributes.c=417=int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid)\n--\nfs/hfsplus/attributes.c-428-\nfs/hfsplus/attributes.c:429:\terr = hfs_find_init(HFSPLUS_SB(dir-\u003ei_sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-430-\tif (err)\n--\nfs/hfsplus/attributes.c=456=int hfsplus_replace_attr(struct inode *inode,\n--\nfs/hfsplus/attributes.c-476-\nfs/hfsplus/attributes.c:477:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-478-\tif (err)\n--\nfs/hfsplus/attributes.c=509=int hfsplus_set_attr_cnid(struct inode *inode, u32 cnid,\n--\nfs/hfsplus/attributes.c-529-\nfs/hfsplus/attributes.c:530:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/attributes.c-531-\tif (err)\n--\nfs/hfsplus/bfind.c-14-\nfs/hfsplus/bfind.c:15:int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)\nfs/hfsplus/bfind.c-16-{\n--\nfs/hfsplus/catalog.c=324=int hfsplus_create_cat(u32 cnid, struct inode *dir,\n--\nfs/hfsplus/catalog.c-335-\t\tstr-\u003ename, cnid, inode-\u003ei_nlink);\nfs/hfsplus/catalog.c:336:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/catalog.c-337-\tif (err)\n--\nfs/hfsplus/catalog.c=419=int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str)\n--\nfs/hfsplus/catalog.c-427-\thfs_dbg(\"name %s, cnid %u\\n\", str ? str-\u003ename : NULL, cnid);\nfs/hfsplus/catalog.c:428:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/catalog.c-429-\tif (err)\n--\nfs/hfsplus/catalog.c=512=int hfsplus_rename_cat(u32 cnid,\n--\nfs/hfsplus/catalog.c-524-\t\tdst_dir-\u003ei_ino, dst_name-\u003ename);\nfs/hfsplus/catalog.c:525:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026src_fd);\nfs/hfsplus/catalog.c-526-\tif (err)\n--\nfs/hfsplus/dir.c=67=static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,\n--\nfs/hfsplus/dir.c-80-\tdentry-\u003ed_fsdata = NULL;\nfs/hfsplus/dir.c:81:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/dir.c-82-\tif (err)\n--\nfs/hfsplus/dir.c=167=static int hfsplus_readdir(struct file *file, struct dir_context *ctx)\n--\nfs/hfsplus/dir.c-180-\nfs/hfsplus/dir.c:181:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/dir.c-182-\tif (err)\n--\nfs/hfsplus/extents.c=133=static int hfsplus_ext_write_extent_locked(struct inode *inode)\n--\nfs/hfsplus/extents.c-139-\nfs/hfsplus/extents.c:140:\t\tres = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003eext_tree, \u0026fd);\nfs/hfsplus/extents.c-141-\t\tif (res)\n--\nfs/hfsplus/extents.c=210=static int hfsplus_ext_read_extent(struct inode *inode, u32 block)\n--\nfs/hfsplus/extents.c-219-\nfs/hfsplus/extents.c:220:\tres = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003eext_tree, \u0026fd);\nfs/hfsplus/extents.c-221-\tif (!res) {\n--\nfs/hfsplus/extents.c=395=int hfsplus_free_fork(struct super_block *sb, u32 cnid,\n--\nfs/hfsplus/extents.c-416-\nfs/hfsplus/extents.c:417:\tres = hfs_find_init(HFSPLUS_SB(sb)-\u003eext_tree, \u0026fd);\nfs/hfsplus/extents.c-418-\tif (res)\n--\nfs/hfsplus/extents.c=546=void hfsplus_file_truncate(struct inode *inode)\n--\nfs/hfsplus/extents.c-584-\nfs/hfsplus/extents.c:585:\tres = hfs_find_init(HFSPLUS_SB(sb)-\u003eext_tree, \u0026fd);\nfs/hfsplus/extents.c-586-\tif (res) {\n--\nfs/hfsplus/hfsplus_fs.h=291=static inline unsigned short hfsplus_min_io_size(struct super_block *sb)\n--\nfs/hfsplus/hfsplus_fs.h-324-#define hfs_brec_remove hfsplus_brec_remove\nfs/hfsplus/hfsplus_fs.h:325:#define hfs_find_init hfsplus_find_init\nfs/hfsplus/hfsplus_fs.h-326-#define hfs_find_exit hfsplus_find_exit\n--\nfs/hfsplus/hfsplus_fs.h=410=int hfs_brec_remove(struct hfs_find_data *fd);\n--\nfs/hfsplus/hfsplus_fs.h-412-/* bfind.c */\nfs/hfsplus/hfsplus_fs.h:413:int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd);\nfs/hfsplus/hfsplus_fs.h-414-void hfs_find_exit(struct hfs_find_data *fd);\n--\nfs/hfsplus/inode.c=932=int hfsplus_cat_write_inode(struct inode *inode)\n--\nfs/hfsplus/inode.c-949-\nfs/hfsplus/inode.c:950:\tif (hfs_find_init(tree, \u0026fd))\nfs/hfsplus/inode.c-951-\t\t/* panic? */\n--\nfs/hfsplus/super.c=65=struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)\n--\nfs/hfsplus/super.c-98-\t inode-\u003ei_ino == HFSPLUS_ROOT_CNID) {\nfs/hfsplus/super.c:99:\t\terr = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/super.c-100-\t\tif (!err) {\n--\nfs/hfsplus/super.c=429=static inline int hfsplus_get_hidden_dir_entry(struct super_block *sb,\n--\nfs/hfsplus/super.c-435-\nfs/hfsplus/super.c:436:\terr = hfs_find_init(HFSPLUS_SB(sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/super.c-437-\tif (unlikely(err))\n--\nfs/hfsplus/xattr.c=204=static int hfsplus_create_attributes_file(struct super_block *sb)\n--\nfs/hfsplus/xattr.c-234-\t\t * possible to be here. But really __setxattr() method\nfs/hfsplus/xattr.c:235:\t\t * first of all calls hfs_find_init() for lookup in\nfs/hfsplus/xattr.c-236-\t\t * B-tree of CatalogFile. This method locks mutex of\n--\nfs/hfsplus/xattr.c=369=int __hfsplus_setxattr(struct inode *inode, const char *name,\n--\nfs/hfsplus/xattr.c-388-\nfs/hfsplus/xattr.c:389:\terr = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003ecat_tree, \u0026cat_fd);\nfs/hfsplus/xattr.c-390-\tif (err) {\n--\nfs/hfsplus/xattr.c=580=static ssize_t hfsplus_getxattr_finder_info(struct inode *inode,\n--\nfs/hfsplus/xattr.c-592-\tif (size \u003e= record_len) {\nfs/hfsplus/xattr.c:593:\t\tres = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/xattr.c-594-\t\tif (res) {\n--\nfs/hfsplus/xattr.c=630=static ssize_t __hfsplus_getxattr_nocheck(struct super_block *sb,\n--\nfs/hfsplus/xattr.c-649-\nfs/hfsplus/xattr.c:650:\tres = hfs_find_init(HFSPLUS_SB(sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/xattr.c-651-\tif (res) {\n--\nfs/hfsplus/xattr.c=886=static ssize_t hfsplus_listxattr_finder_info(struct dentry *dentry,\n--\nfs/hfsplus/xattr.c-897-\nfs/hfsplus/xattr.c:898:\tres = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003ecat_tree, \u0026fd);\nfs/hfsplus/xattr.c-899-\tif (res) {\n--\nfs/hfsplus/xattr.c=954=ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-975-\nfs/hfsplus/xattr.c:976:\terr = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003eattr_tree, \u0026fd);\nfs/hfsplus/xattr.c-977-\tif (err) {\n--\nfs/hfsplus/xattr.c=1058=static int hfsplus_removexattr(struct inode *inode, const char *name)\n--\nfs/hfsplus/xattr.c-1075-\nfs/hfsplus/xattr.c:1076:\terr = hfs_find_init(HFSPLUS_SB(inode-\u003ei_sb)-\u003ecat_tree, \u0026cat_fd);\nfs/hfsplus/xattr.c-1077-\tif (err) {\n"
} |
| 29/3 | 2026/10/14 04:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42736 output: 37 thoughts: 23 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into `hfs_find_init`'s Implementation** Okay, time to get my hands dirty. I need to understand what `hfs_find_init` is actually doing. I'm going to jump straight into `bfind.c`. That's where it's likely defined, given its purpose – the name screams "binary search" or similar file finding mechanisms, and it would likely be grouped with its supporting function calls. Let's see how it sets up whatever data structures are involved and what initial conditions it's ensuring before a search can even begin. I'm expecting some initialization of internal state, possibly pre-calculating offsets or building lookup tables, or at least handling some setup for a more refined search algorithm implementation. I'll be particularly interested in whether it uses an external library for specific file system actions. |
| 30/3 | 2026/10/14 04:42 | tool | read-file |
0mArgs:{
"File": "fs/hfsplus/bfind.c",
"FirstLine": 14,
"LineCount": 35
}Results: {
"Contents": " 14:\t\n 15:\tint hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd)\n 16:\t{\n 17:\t\tvoid *ptr;\n 18:\t\n 19:\t\tfd-\u003etree = tree;\n 20:\t\tfd-\u003ebnode = NULL;\n 21:\t\thfs_find_result_init(fd);\n 22:\t\tptr = kzalloc(tree-\u003emax_key_len * 2 + 4, GFP_KERNEL);\n 23:\t\tif (!ptr)\n 24:\t\t\treturn -ENOMEM;\n 25:\t\tfd-\u003esearch_key = ptr;\n 26:\t\tfd-\u003ekey = ptr + tree-\u003emax_key_len + 2;\n 27:\t\thfs_dbg(\"cnid %d, caller %ps\\n\",\n 28:\t\t\ttree-\u003ecnid, __builtin_return_address(0));\n 29:\t\tmutex_lock_nested(\u0026tree-\u003etree_lock,\n 30:\t\t\t\thfsplus_btree_lock_class(tree));\n 31:\t\treturn 0;\n 32:\t}\n 33:\t\n 34:\tvoid hfs_find_exit(struct hfs_find_data *fd)\n 35:\t{\n 36:\t\thfs_bnode_put(fd-\u003ebnode);\n 37:\t\tkfree(fd-\u003esearch_key);\n 38:\t\thfs_dbg(\"cnid %d, caller %ps\\n\",\n 39:\t\t\tfd-\u003etree-\u003ecnid, __builtin_return_address(0));\n 40:\t\tmutex_unlock(\u0026fd-\u003etree-\u003etree_lock);\n 41:\t\tfd-\u003etree = NULL;\n 42:\t}\n 43:\t\n 44:\tint hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode,\n 45:\t\t\t\t\tstruct hfs_find_data *fd,\n 46:\t\t\t\t\tint *begin,\n 47:\t\t\t\t\tint *end,\n 48:\t\t\t\t\tint *cur_rec)\n"
} |
| 31/3 | 2026/10/14 04:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43530 output: 34 thoughts: 1383 Thoughts: **Analyzing Timestamp Initialization and User Space Data Exposure in HFS+ Filesystem Code** Okay, so I've been diving into this HFS+ code, specifically focusing on how the file creation timestamp is handled and whether there's any risk of uninitialized data being exposed to user space. It looks like `hfs_find_init` fully initializes the `fd->search_key`, `fd->key`, `fd->tree`, and `fd->bnode` structures, so that's good. Now, I'm scrutinizing the `is_create_date_identical` function in `fs/hfsplus/dir.c`. The core concern is around the interaction with extended attributes (xattrs) and potential uninitialized values. Initially, it seemed like `timestamp` in `is_create_date_identical` might not be initialized, but on closer inspection of the code path through `hfsplus_read_timestamp`, my concerns are alleviated. The key is realizing that `time64_t timestamp;` is a local variable within `hfsplus_read_timestamp`, which is then passed via a pointer to `hfsplus_get_timestamp_xattr` and *crucially* `*ut` (which points to `timestamp` in the caller's context) *is* initialized regardless of the outcome of xattr retrieval. Specifically, if the timestamp xattr is not present or an error occurs, `*ut` is assigned `__hfsp_mt2ut(mt)` before any further use. Even if `timestamp` has an invalid value, that value is never directly used to compare agains the inode birthdate. Therefore, the subsequent checks within `is_create_date_identical` are safe in regards to uninitialized data. To be absolutely sure about any uninitialized memory being exposed to user space, I'm also going through the patch to check every instance where data might be copied to user space or used in conditional branching. Let's look at `hfsplus_getattr` first. We have: * `stat->result_mask |= STATX_BTIME;` * `stat->btime.tv_sec = hip->birthdate;` * `stat->btime.tv_nsec = 0;` `btime` is part of the `struct kstat *stat`. `statx` is the system call that copies this data to userspace. Fortunately, the code assigns to *both* `tv_sec` and `tv_nsec` within `struct statx_timestamp`, so no issue there. That's all the fields, as well. Next, I need to check if `hfsplus_listxattr` copies any uninitialized data to userspace, so I'll need to dig into that function now. |
| 32/3 | 2026/10/14 04:42 | tool | grepper |
0mArgs:{
"Expression": "hfsplus_listxattr",
"PathPrefixes": [
"fs/hfsplus/"
]
}Results: {
"Output": "fs/hfsplus/dir.c=657=const struct inode_operations hfsplus_dir_inode_operations = {\n--\nfs/hfsplus/dir.c-667-\t.getattr\t\t= hfsplus_getattr,\nfs/hfsplus/dir.c:668:\t.listxattr\t\t= hfsplus_listxattr,\nfs/hfsplus/dir.c-669-\t.fileattr_get\t\t= hfsplus_fileattr_get,\n--\nfs/hfsplus/inode.c=446=static const struct inode_operations hfsplus_file_inode_operations = {\n--\nfs/hfsplus/inode.c-448-\t.getattr\t= hfsplus_getattr,\nfs/hfsplus/inode.c:449:\t.listxattr\t= hfsplus_listxattr,\nfs/hfsplus/inode.c-450-\t.fileattr_get\t= hfsplus_fileattr_get,\n--\nfs/hfsplus/inode.c=454=static const struct inode_operations hfsplus_symlink_inode_operations = {\n--\nfs/hfsplus/inode.c-457-\t.getattr\t= hfsplus_getattr,\nfs/hfsplus/inode.c:458:\t.listxattr\t= hfsplus_listxattr,\nfs/hfsplus/inode.c-459-};\n--\nfs/hfsplus/inode.c=461=static const struct inode_operations hfsplus_special_inode_operations = {\n--\nfs/hfsplus/inode.c-463-\t.getattr\t= hfsplus_getattr,\nfs/hfsplus/inode.c:464:\t.listxattr\t= hfsplus_listxattr,\nfs/hfsplus/inode.c-465-};\n--\nfs/hfsplus/xattr.c=872=static inline int can_list(const char *xattr_name)\n--\nfs/hfsplus/xattr.c-885-\nfs/hfsplus/xattr.c:886:static ssize_t hfsplus_listxattr_finder_info(struct dentry *dentry,\nfs/hfsplus/xattr.c-887-\t\t\t\t\t\tchar *buffer, size_t size)\n--\nfs/hfsplus/xattr.c-953-\nfs/hfsplus/xattr.c:954:ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size)\nfs/hfsplus/xattr.c-955-{\n--\nfs/hfsplus/xattr.c-969-\nfs/hfsplus/xattr.c:970:\tres = hfsplus_listxattr_finder_info(dentry, buffer, size);\nfs/hfsplus/xattr.c-971-\tif (res \u003c 0)\n--\nfs/hfsplus/xattr.h=54=int hfsplus_remove_timestamp_xattr(struct inode *inode, const char *name);\nfs/hfsplus/xattr.h-55-\nfs/hfsplus/xattr.h:56:ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);\nfs/hfsplus/xattr.h-57-\n"
} |
| 33/3 | 2026/10/14 04:42 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46412 output: 37 thoughts: 2292 Thoughts: **Analyzing HFS+ Timestamp Handling and Catalog Updates** Okay, let's break this down. First, I'm checking `can_list`, specifically how it handles listing extended attributes (xattrs). Internal xattrs, like `linux_hfs.*`, are intentionally hidden from listxattr calls. That makes sense. Next, I'm digging into `hfsplus_inode_save_timestamp`. The goal is to understand how timestamps are saved as xattrs. The key is that if a timestamp *needs* to be saved as an xattr, it only writes the xattr if the stored value is *different* from the current one, optimizing write operations. The code reads the stored timestamp via `hfsplus_get_timestamp_xattr`, *if* the `xattr_bit` flag is set, using `test_bit`. The `stored` value is assigned *only* if `hfsplus_get_timestamp_xattr` succeeds. Now, looking at `hfsplus_inode_save_timestamps`, this function calls `hfsplus_inode_save_timestamp` for the access, modification, and change timestamps. Crucially, it unconditionally sets the `date` field, using `__hfsp_ut2mt`, before any xattr checks are performed within the called function. That field is always going to be initialized. I have to verify where `timestamps.create_date` and `timestamps.backup_date` are set. Going upstream to `hfsplus_cat_write_inode`, I see that only `access_date`, `content_mod_date`, and `attribute_mod_date` are transferred from the `timestamps` struct to the catalog entry (`folder`). The `create_date` and `backup_date` are *not* used in this function, because this part is only updating a folder read via `hfs_bnode_read`. However, in `hfsplus_cat_build_record`, it's different. I'm seeing that, in fact, `hfsplus_copy_timestamps2folder` and `hfsplus_copy_timestamps2file` are the methods where the timestamp fields of the struct `timestamps` is assigned to a folder or file entry, respectively. In the file case, the `create_date` is determined conditionally: if `cnid == inode->i_ino`, the method `hfsplus_set_create_date` is called. It sets the `create_date` and related fields, but if the inodes are hard-linked, the `create_date` is set to the current time. I need to confirm that `file->backup_date` and `folder->backup_date` are never assigned. I need to see what happens to `entry` before `hfsplus_cat_build_record`. The `hfsplus_create_cat` function builds the record via calling `hfsplus_cat_build_record`. It looks like `hfsplus_cat_build_record` initializes the cat entry. I need to verify what parts of the record `hfsplus_cat_build_record` touches to conclude my investigation. |
| 34/3 | 2026/10/14 04:43 | tool | read-file |
0mArgs:{
"File": "fs/hfsplus/catalog.c",
"FirstLine": 150,
"LineCount": 90
}Results: {
"Contents": " 150:\t\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\n 151:\t\n 152:\t\tif (!S_ISDIR(inode-\u003ei_mode) \u0026\u0026 cnid != inode-\u003ei_ino)\n 153:\t\t\treturn HFSPLUS_I(sbi-\u003ehidden_dir)-\u003ebirthdate;\n 154:\t\n 155:\t\treturn HFSPLUS_I(inode)-\u003ebirthdate;\n 156:\t}\n 157:\t\n 158:\tstatic int hfsplus_cat_build_record(hfsplus_cat_entry *entry,\n 159:\t\t\t\t\t u32 cnid, struct inode *inode)\n 160:\t{\n 161:\t\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\n 162:\t\tstruct hfsplus_timestamps timestamps = {0};\n 163:\t\n 164:\t\tif (S_ISDIR(inode-\u003ei_mode)) {\n 165:\t\t\tstruct hfsplus_cat_folder *folder;\n 166:\t\n 167:\t\t\tfolder = \u0026entry-\u003efolder;\n 168:\t\t\tmemset(folder, 0, sizeof(*folder));\n 169:\t\t\tfolder-\u003etype = cpu_to_be16(HFSPLUS_FOLDER);\n 170:\t\t\tif (test_bit(HFSPLUS_SB_HFSX, \u0026sbi-\u003eflags))\n 171:\t\t\t\tfolder-\u003eflags |= cpu_to_be16(HFSPLUS_HAS_FOLDER_COUNT);\n 172:\t\t\tfolder-\u003eid = cpu_to_be32(inode-\u003ei_ino);\n 173:\t\n 174:\t\t\thfsplus_set_create_date(inode, \u0026timestamps);\n 175:\t\t\thfsplus_copy_timestamps2folder(\u0026timestamps, folder);\n 176:\t\t\tif (hfsp_ut_needs_xattr(HFSPLUS_I(inode)-\u003ebirthdate))\n 177:\t\t\t\tfolder-\u003eflags |= cpu_to_be16(HFSPLUS_XATTR_EXISTS);\n 178:\t\n 179:\t\t\thfsplus_cat_set_perms(inode, \u0026folder-\u003epermissions);\n 180:\t\t\tif (inode == sbi-\u003ehidden_dir)\n 181:\t\t\t\t/* invisible and namelocked */\n 182:\t\t\t\tfolder-\u003euser_info.frFlags = cpu_to_be16(0x5000);\n 183:\t\t\treturn sizeof(*folder);\n 184:\t\t} else {\n 185:\t\t\tstruct hfsplus_cat_file *file;\n 186:\t\n 187:\t\t\tfile = \u0026entry-\u003efile;\n 188:\t\t\tmemset(file, 0, sizeof(*file));\n 189:\t\t\tfile-\u003etype = cpu_to_be16(HFSPLUS_FILE);\n 190:\t\t\tfile-\u003eflags = cpu_to_be16(HFSPLUS_FILE_THREAD_EXISTS);\n 191:\t\t\tfile-\u003eid = cpu_to_be32(cnid);\n 192:\t\n 193:\t\t\tif (cnid == inode-\u003ei_ino) {\n 194:\t\t\t\thfsplus_set_create_date(inode, \u0026timestamps);\n 195:\t\t\t} else {\n 196:\t\t\t\t/*\n 197:\t\t\t\t * Hard link record: don't change creation date\n 198:\t\t\t\t * of the linked inode.\n 199:\t\t\t\t */\n 200:\t\t\t\t__be32 now = __hfsp_ut2mt(ktime_get_real_seconds());\n 201:\t\n 202:\t\t\t\ttimestamps.create_date = now;\n 203:\t\t\t\ttimestamps.content_mod_date = now;\n 204:\t\t\t\ttimestamps.attribute_mod_date = now;\n 205:\t\t\t\ttimestamps.access_date = now;\n 206:\t\t\t}\n 207:\t\t\thfsplus_copy_timestamps2file(\u0026timestamps, file);\n 208:\t\n 209:\t\t\tif (cnid == inode-\u003ei_ino) {\n 210:\t\t\t\thfsplus_cat_set_perms(inode, \u0026file-\u003epermissions);\n 211:\t\t\t\tif (S_ISLNK(inode-\u003ei_mode)) {\n 212:\t\t\t\t\tfile-\u003euser_info.fdType =\n 213:\t\t\t\t\t\tcpu_to_be32(HFSP_SYMLINK_TYPE);\n 214:\t\t\t\t\tfile-\u003euser_info.fdCreator =\n 215:\t\t\t\t\t\tcpu_to_be32(HFSP_SYMLINK_CREATOR);\n 216:\t\t\t\t} else {\n 217:\t\t\t\t\tfile-\u003euser_info.fdType =\n 218:\t\t\t\t\t\tcpu_to_be32(sbi-\u003etype);\n 219:\t\t\t\t\tfile-\u003euser_info.fdCreator =\n 220:\t\t\t\t\t\tcpu_to_be32(sbi-\u003ecreator);\n 221:\t\t\t\t}\n 222:\t\t\t\tif (HFSPLUS_FLG_IMMUTABLE \u0026\n 223:\t\t\t\t\t\t(file-\u003epermissions.rootflags |\n 224:\t\t\t\t\t\tfile-\u003epermissions.userflags))\n 225:\t\t\t\t\tfile-\u003eflags |=\n 226:\t\t\t\t\t\tcpu_to_be16(HFSPLUS_FILE_LOCKED);\n 227:\t\t\t} else {\n 228:\t\t\t\tfile-\u003euser_info.fdType =\n 229:\t\t\t\t\tcpu_to_be32(HFSP_HARDLINK_TYPE);\n 230:\t\t\t\tfile-\u003euser_info.fdCreator =\n 231:\t\t\t\t\tcpu_to_be32(HFSP_HFSPLUS_CREATOR);\n 232:\t\t\t\tfile-\u003euser_info.fdFlags =\n 233:\t\t\t\t\tcpu_to_be16(0x100);\n 234:\t\t\t\tfile-\u003ecreate_date =\n 235:\t\t\t\t\tHFSPLUS_I(sbi-\u003ehidden_dir)-\u003ecreate_date;\n 236:\t\t\t\tfile-\u003epermissions.dev =\n 237:\t\t\t\t\tcpu_to_be32(HFSPLUS_I(inode)-\u003elinkid);\n 238:\t\t\t}\n 239:\t\n"
} |
| 35/3 | 2026/10/14 04:43 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51005 output: 436 thoughts: 947 Thoughts: **KMSAN Assessment: No New Risks Detected**
Okay, so first things first, `memset` is used right at the start to zero out both the `folder` and `file` structs, so that's a good initial step. Now, let's dive into this patch series and see why KMSAN isn't needed here. I'll focus on the four key criteria for needing KMSAN.
1. **Kernel Structures to User Space:** I see that `hfsplus_getattr` sets the `stat->btime` fields from `hip->birthdate`. But hold on, `hip->birthdate` is always initialized, either during the `iget` process to zero or via `read_timestamps` and `cat_build_record`. Also, the btime fields are always fully initialized. There are no uninitialized fields or padding that could cause a problem. Regarding internal xattrs, they are hidden from user space and can't be read or written directly.
2. **Conditional Logic & Uninitialized Variables:** Let's look at `hfsplus_read_timestamp`. The `timestamp` is only read if `hfsplus_get_timestamp_xattr` succeeds, so the code looks good. The pointers `*has_xattr` and `*ut` are unconditionally set. In `hfsplus_inode_read_timestamps` and `hfsplus_inode_save_timestamp`, local `timespec64` structs are initialized. Looking at `is_create_date_identical`, both `timestamp` and `has_xattr` are initialized by `hfsplus_read_timestamp` when returning 0. All of the branches and conditions look like they're relying on properly initialized variables.
3. **Complex Data Structures:** All newly introduced structures, like `timestamps` and `changes`, are stack-allocated and initialized to zero (`= {0}`). For `hfsplus_build_xattr_name`, we use `kzalloc`. `hfsplus_alloc_attr_entry` uses the slab cache, but `hfsplus_attr_build_record` memsets the entry to 0 before filling it. So everything gets zeroed out before being touched.
4. **Bounds Checks & Uninitialized Bytes:** I see nothing here that would allow surrounding code to access uninitialized bytes.
Given all of that, this patch series doesn't introduce any new or hidden uninitialized memory risks. Therefore, KMSAN is not necessary here. Standard KASAN and our existing kernel testing tools are more than sufficient.
To clarify the reasoning, KMSAN is for catching reads of uninitialized memory and information leaks to user space. But, all local structures here are zero-initialized, and allocated memory uses `kzalloc()` where needed. Inode timestamps are properly initialized. So, no risks.
KASAN will handle any issues around buffer boundaries or B-tree handling, which is what this patch primarily concerns.
So, I'm confident in setting `NeedsKMSAN = false`.
|
| 36/3 | 2026/10/14 04:43 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series adds 64-bit timestamp support to HFS+ by storing timestamps beyond February 2040 in internal extended attributes (\"linux_hfs.*\") and clamping on-disk 32-bit timestamps, along with corresponding KUnit test coverage.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and leaks of uninitialized kernel data to user space. In this patch:\n 1. All newly introduced stack structures (`struct hfsplus_timestamps`, `struct hfsplus_xattr_changes`, `struct timespec64`) are explicitly zero-initialized (`= {0}`).\n 2. In-memory inode timestamp fields (`birthdate`, `create_date`) are initialized to 0 in `hfsplus_iget()` and populated on inode read or creation.\n 3. The `statx` creation timestamp (`stat-\u003ebtime`) has both `tv_sec` and `tv_nsec` fully initialized in `hfsplus_getattr()`.\n 4. Dynamic allocations in `hfsplus_build_xattr_name()` use `kzalloc()`.\n 5. Inode/xattr record builders like `hfsplus_attr_build_record()` and `hfsplus_cat_build_record()` zero-fill record memory before writing.\n 6. Return/output arguments in helper functions (`hfsplus_read_timestamp()`, `hfsplus_get_timestamp_xattr()`) are always initialized before use, and internal xattrs are filtered from `listxattr` and user-facing APIs.\n- KASAN and standard sanitizers already adequately cover any risks related to buffer limits, memory allocations, or B-tree traversal/record bounds.\n\nTherefore, this patch series does not introduce uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series adds 64-bit timestamp support to HFS+ by storing timestamps beyond February 2040 in internal extended attributes (\"linux_hfs.*\") and clamping on-disk 32-bit timestamps, along with corresponding KUnit test coverage.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory (stack, heap, or page allocations) and leaks of uninitialized kernel data to user space. In this patch:\n 1. All newly introduced stack structures (`struct hfsplus_timestamps`, `struct hfsplus_xattr_changes`, `struct timespec64`) are explicitly zero-initialized (`= {0}`).\n 2. In-memory inode timestamp fields (`birthdate`, `create_date`) are initialized to 0 in `hfsplus_iget()` and populated on inode read or creation.\n 3. The `statx` creation timestamp (`stat-\u003ebtime`) has both `tv_sec` and `tv_nsec` fully initialized in `hfsplus_getattr()`.\n 4. Dynamic allocations in `hfsplus_build_xattr_name()` use `kzalloc()`.\n 5. Inode/xattr record builders like `hfsplus_attr_build_record()` and `hfsplus_cat_build_record()` zero-fill record memory before writing.\n 6. Return/output arguments in helper functions (`hfsplus_read_timestamp()`, `hfsplus_get_timestamp_xattr()`) are always initialized before use, and internal xattrs are filtered from `listxattr` and user-facing APIs.\n- KASAN and standard sanitizers already adequately cover any risks related to buffer limits, memory allocations, or B-tree traversal/record bounds.\n\nTherefore, this patch series does not introduce uninitialized memory risks, and a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|