[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1636974018-31285-1-git-send-email-zhongjubin@huawei.com>
Date: Mon, 15 Nov 2021 19:00:18 +0800
From: Jubin Zhong <zhongjubin@...wei.com>
To: <viro@...iv.linux.org.uk>
CC: <wangfangpeng1@...wei.com>, <kechengsong@...wei.com>,
<linux-fsdevel@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] fs: Fix truncate never updates m/ctime
From: zhongjubin <zhongjubin@...wei.com>
Syscall truncate() never updates m/ctime even if the file size is
changed. However, this is incorrect according to man file:
truncate (2):
If the size changed, then the st_ctime and st_mtime fields
(respectively, time of last status change and time of last modification;
see stat(2)) for the file are updated, and the set-user-ID and
set-group-ID mode bits may be cleared.
Check file size before do_truncate() to fix this.
Signed-off-by: zhongjubin <zhongjubin@...wei.com>
---
fs/open.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/open.c b/fs/open.c
index f732fb94600c..02404b759c2e 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -106,8 +106,11 @@ long vfs_truncate(const struct path *path, loff_t length)
goto put_write_and_out;
error = security_path_truncate(path);
- if (!error)
- error = do_truncate(mnt_userns, path->dentry, length, 0, NULL);
+ if (error)
+ goto put_write_and_out;
+
+ if (i_size_read(inode) != length)
+ error = do_truncate(mnt_userns, path->dentry, length, ATTR_MTIME | ATTR_CTIME, NULL);
put_write_and_out:
put_write_access(inode);
--
2.12.3
Powered by blists - more mailing lists