* [PATCH] ecryptfs: set s_time_gran to get correct time granularity
@ 2024-05-17 10:09 Frank Hsiao 蕭法宣
2024-12-06 12:29 ` Bert Wesarg
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Frank Hsiao 蕭法宣 @ 2024-05-17 10:09 UTC (permalink / raw)
To: code@tyhicks.com; +Cc: ecryptfs@vger.kernel.org
related to: https://bugs.launchpad.net/ecryptfs/+bug/1890486
This bug happens in the two following situations:
cp -p: copy a file and preserve its atime and mtime
touch -r: touch a file and use a ref file's time instead of current time
In fs/attr.c notify_change(), atime and mtime is truncated by timestamp_truncate(),
ecryptfs gets wrong s_time_gran (10^9 instead of original fs time granularity) and
truncates a/mtime to whole second. Setting s_time_gran when mounting ecryptfs
solves the issue.
Signed-off-by: Frank Hsiao 蕭法宣 <frankhsiao@qnap.com>
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index b2f6a1937d239..19dbe9d1187e1 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -567,6 +567,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type
*fs_type, int flags
s->s_blocksize = path.dentry->d_sb->s_blocksize;
s->s_magic = ECRYPTFS_SUPER_MAGIC;
s->s_stack_depth = path.dentry->d_sb->s_stack_depth + 1;
+ s->s_time_gran = path.dentry->d_sb->s_time_gran;
rc = -EINVAL;
if (s->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] ecryptfs: set s_time_gran to get correct time granularity
2024-05-17 10:09 [PATCH] ecryptfs: set s_time_gran to get correct time granularity Frank Hsiao 蕭法宣
@ 2024-12-06 12:29 ` Bert Wesarg
2026-02-23 19:11 ` Bert Wesarg
2025-01-08 6:56 ` 回覆: " Frank Hsiao 蕭法宣
2026-03-26 5:10 ` Tyler Hicks
2 siblings, 1 reply; 5+ messages in thread
From: Bert Wesarg @ 2024-12-06 12:29 UTC (permalink / raw)
To: Frank Hsiao 蕭法宣, code@tyhicks.com
Cc: ecryptfs@vger.kernel.org
Hi,
On 17.05.24 12:09, Frank Hsiao 蕭法宣 wrote:
> related to: https://bugs.launchpad.net/ecryptfs/+bug/1890486
>
> This bug happens in the two following situations:
> cp -p: copy a file and preserve its atime and mtime
> touch -r: touch a file and use a ref file's time instead of current time
was there some discussion for this solution. I came to the same conclusion but cannot test it right now.
Thanks
Bert
>
> In fs/attr.c notify_change(), atime and mtime is truncated by timestamp_truncate(),
> ecryptfs gets wrong s_time_gran (10^9 instead of original fs time granularity) and
> truncates a/mtime to whole second. Setting s_time_gran when mounting ecryptfs
> solves the issue.
>
> Signed-off-by: Frank Hsiao 蕭法宣 <frankhsiao@qnap.com>
>
> diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
> index b2f6a1937d239..19dbe9d1187e1 100644
> --- a/fs/ecryptfs/main.c
> +++ b/fs/ecryptfs/main.c
> @@ -567,6 +567,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type
> *fs_type, int flags
> s->s_blocksize = path.dentry->d_sb->s_blocksize;
> s->s_magic = ECRYPTFS_SUPER_MAGIC;
> s->s_stack_depth = path.dentry->d_sb->s_stack_depth + 1;
> + s->s_time_gran = path.dentry->d_sb->s_time_gran;
>
> rc = -EINVAL;
> if (s->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] ecryptfs: set s_time_gran to get correct time granularity
2024-12-06 12:29 ` Bert Wesarg
@ 2026-02-23 19:11 ` Bert Wesarg
0 siblings, 0 replies; 5+ messages in thread
From: Bert Wesarg @ 2026-02-23 19:11 UTC (permalink / raw)
To: Frank Hsiao 蕭法宣, code@tyhicks.com
Cc: ecryptfs@vger.kernel.org
Dear all,
On Fri, Dec 6, 2024 at 1:29 PM Bert Wesarg <bert.wesarg@googlemail.com> wrote:
>
> Hi,
>
> On 17.05.24 12:09, Frank Hsiao 蕭法宣 wrote:
> > related to: https://bugs.launchpad.net/ecryptfs/+bug/1890486
> >
> > This bug happens in the two following situations:
> > cp -p: copy a file and preserve its atime and mtime
> > touch -r: touch a file and use a ref file's time instead of current time
>
> was there some discussion for this solution. I came to the same conclusion but cannot test it right now.
now that there is renewed activity in eCryptfs (thanks, btw). Can we
please consider this patch for a next cycle?
Thanks.
Best
Bert
>
> Thanks
> Bert
>
> >
> > In fs/attr.c notify_change(), atime and mtime is truncated by timestamp_truncate(),
> > ecryptfs gets wrong s_time_gran (10^9 instead of original fs time granularity) and
> > truncates a/mtime to whole second. Setting s_time_gran when mounting ecryptfs
> > solves the issue.
> >
> > Signed-off-by: Frank Hsiao 蕭法宣 <frankhsiao@qnap.com>
> >
> > diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
> > index b2f6a1937d239..19dbe9d1187e1 100644
> > --- a/fs/ecryptfs/main.c
> > +++ b/fs/ecryptfs/main.c
> > @@ -567,6 +567,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type
> > *fs_type, int flags
> > s->s_blocksize = path.dentry->d_sb->s_blocksize;
> > s->s_magic = ECRYPTFS_SUPER_MAGIC;
> > s->s_stack_depth = path.dentry->d_sb->s_stack_depth + 1;
> > + s->s_time_gran = path.dentry->d_sb->s_time_gran;
> >
> > rc = -EINVAL;
> > if (s->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* 回覆: [PATCH] ecryptfs: set s_time_gran to get correct time granularity
2024-05-17 10:09 [PATCH] ecryptfs: set s_time_gran to get correct time granularity Frank Hsiao 蕭法宣
2024-12-06 12:29 ` Bert Wesarg
@ 2025-01-08 6:56 ` Frank Hsiao 蕭法宣
2026-03-26 5:10 ` Tyler Hicks
2 siblings, 0 replies; 5+ messages in thread
From: Frank Hsiao 蕭法宣 @ 2025-01-08 6:56 UTC (permalink / raw)
To: code@tyhicks.com; +Cc: ecryptfs@vger.kernel.org
Friendly ping, thanks.
________________________________________
寄件者: Frank Hsiao 蕭法宣 <frankhsiao@qnap.com>
寄件日期: 2024年5月17日 下午 06:09
收件者: code@tyhicks.com
副本: ecryptfs@vger.kernel.org
主旨: [PATCH] ecryptfs: set s_time_gran to get correct time granularity
related to: https://bugs.launchpad.net/ecryptfs/+bug/1890486
This bug happens in the two following situations:
cp -p: copy a file and preserve its atime and mtime
touch -r: touch a file and use a ref file's time instead of current time
In fs/attr.c notify_change(), atime and mtime is truncated by timestamp_truncate(),
ecryptfs gets wrong s_time_gran (10^9 instead of original fs time granularity) and
truncates a/mtime to whole second. Setting s_time_gran when mounting ecryptfs
solves the issue.
Signed-off-by: Frank Hsiao 蕭法宣 <frankhsiao@qnap.com>
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index b2f6a1937d239..19dbe9d1187e1 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -567,6 +567,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type
*fs_type, int flags
s->s_blocksize = path.dentry->d_sb->s_blocksize;
s->s_magic = ECRYPTFS_SUPER_MAGIC;
s->s_stack_depth = path.dentry->d_sb->s_stack_depth + 1;
+ s->s_time_gran = path.dentry->d_sb->s_time_gran;
rc = -EINVAL;
if (s->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] ecryptfs: set s_time_gran to get correct time granularity
2024-05-17 10:09 [PATCH] ecryptfs: set s_time_gran to get correct time granularity Frank Hsiao 蕭法宣
2024-12-06 12:29 ` Bert Wesarg
2025-01-08 6:56 ` 回覆: " Frank Hsiao 蕭法宣
@ 2026-03-26 5:10 ` Tyler Hicks
2 siblings, 0 replies; 5+ messages in thread
From: Tyler Hicks @ 2026-03-26 5:10 UTC (permalink / raw)
To: Frank Hsiao 蕭法宣, Bert Wesarg
Cc: ecryptfs@vger.kernel.org
On 2024-05-17 10:09:55, Frank Hsiao 蕭法宣 wrote:
> related to: https://bugs.launchpad.net/ecryptfs/+bug/1890486
>
> This bug happens in the two following situations:
> cp -p: copy a file and preserve its atime and mtime
> touch -r: touch a file and use a ref file's time instead of current time
>
> In fs/attr.c notify_change(), atime and mtime is truncated by timestamp_truncate(),
> ecryptfs gets wrong s_time_gran (10^9 instead of original fs time granularity) and
> truncates a/mtime to whole second. Setting s_time_gran when mounting ecryptfs
> solves the issue.
Thank you! This has been applied to the next branch of the
tyhicks/ecryptfs.git tree.
I apologize that this fix was forgotten for so long. Thanks to Bert for
raising it back up to my attention.
Given the long delay since you've sent this patch, I went ahead and
slightly modified the commit message to make it follow the guidelines
documented in the Documentation/process/submitting-patches.rst file. Let
me know if you have any objections:
===
ecryptfs: Set s_time_gran to get correct time granularity
Set the eCryptfs superblock time granularity, using the lower
filesystem's s_time_gran value, to prevent unnecessary inode timestamp
truncation to the granularity of a full second.
The use of utimensat(2) to set a timestamp with nanosecond precision
would trigger this bug. That occurred when using the following utilities
to update timestamps of a file:
* cp -p: copy a file and preserve its atime and mtime
* touch -r: touch a file and use a reference file's timestamps
Closes: https://bugs.launchpad.net/ecryptfs/+bug/1890486
Signed-off-by: Frank Hsiao 蕭法宣 <frankhsiao@qnap.com>
[tyhicks: Partially rewrite the commit message]
Signed-off-by: Tyler Hicks <code@tyhicks.com>
===
You can find a direct link below but please be aware that the commit hash is
unstable and, therefore, the URL may not be valid in the future.
[1/1] ecryptfs: Set s_time_gran to get correct time granularity
https://git.kernel.org/tyhicks/ecryptfs/c/7d9ebf33d85317f3f258c627de51701e2bf7642d
Tyler
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-26 5:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-17 10:09 [PATCH] ecryptfs: set s_time_gran to get correct time granularity Frank Hsiao 蕭法宣
2024-12-06 12:29 ` Bert Wesarg
2026-02-23 19:11 ` Bert Wesarg
2025-01-08 6:56 ` 回覆: " Frank Hsiao 蕭法宣
2026-03-26 5:10 ` Tyler Hicks
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox