[RFC 5/5] hostfs: set timestamps on file creation

Johannes Berg johannes at sipsolutions.net
Thu Nov 19 05:24:42 PST 2026


From: Benjamin Berg <benjamin.berg at intel.com>

Otherwise we will create the file and then read the timestamps from the
host file system. If the file is not touched/written afterwards, then
the host time can leak into the container.

Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
Signed-off-by: Johannes Berg <johannes.berg at intel.com>
---
 fs/hostfs/hostfs_kern.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 09640dd6f373..587ec51d34d6 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -747,6 +747,7 @@ static struct inode *hostfs_iget(struct super_block *sb, char *name)
 static int hostfs_create(const struct mnt_idmap *idmap, struct inode *dir,
 			 struct dentry *dentry, umode_t mode)
 {
+	struct timespec64 ts;
 	struct inode *inode;
 	char *name;
 	int fd;
@@ -766,6 +767,11 @@ static int hostfs_create(const struct mnt_idmap *idmap, struct inode *dir,
 	if (IS_ERR(inode))
 		return PTR_ERR(inode);
 
+	/* Use the internal time for the new inode */
+	ts = inode_set_ctime_current(inode);
+	inode_set_atime_to_ts(inode, ts);
+	inode_set_mtime_to_ts(inode, ts);
+
 	HOSTFS_I(inode)->fd = fd;
 	HOSTFS_I(inode)->mode = FMODE_READ | FMODE_WRITE;
 	d_instantiate(dentry, inode);
-- 
2.56.1




More information about the linux-um mailing list