Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] cifs: fix times assignments in cifs_posix_to_fattr()
@ 2026-11-16 15:45 koraynilay
  2026-11-16 22:23 ` Namjae Jeon
  2026-11-17 22:18 ` Paulo Alcantara
  0 siblings, 2 replies; 4+ messages in thread
From: koraynilay @ 2026-11-16 15:45 UTC (permalink / raw)
  To: Namjae Jeon, Paulo Alcantara
  Cc: Tom Talpey, Ronnie Sahlberg, Shyam Prasad N, Bharath SM,
	Aurelien Aptel, linux-cifs, linux-kernel, koraynilay, Sashiko

Currently cifs_posix_to_fattr() wrongly sets SMB's CreationTime to
fattr->cf_ctime.

Fix this by setting fattr->cf_createtime to SMB's CreationTime and
fattr->cf_ctime to SMB's ChangeTime, matching the behaviour of
__dir_info_to_fattr().

This patch also fixes a few related issues reported by sashiko on
another patch (see Sashiko Link tag).

Reproducers for these bugs, with /tmp as the local filesystem folder
exported as [test] in ksmbd.conf and /mnt as the smb folder mounted with
mount -t cifs:

  mount -t cifs //127.0.0.1/test /mnt -o username=ciao,password=c,posix

Issue 1: ctime clobbered by CreationTime during readdir

  mkdir -p /mnt/dir
  touch /mnt/dir/file
  sleep 4
  chmod 644 /mnt/dir/file
  stat -c "ctime and btime before readdir: %Z %W" /mnt/dir/file
  ls -lc /mnt/dir > /dev/null
  stat -c "ctime and btime after readdir:  %Z %W" /mnt/dir/file
  stat -c "ctime and btime on disk:        %Z %W" /tmp/dir/file

output before the fix, notice how ctime is the same as btime after the
readdir, while it's 4 seconds ahead (because of the sleep 4) before the
readdir (on disk timestamps are not touched):

  ctime and btime before readdir: 1794842068 1794842064
  ctime and btime after readdir:  1794842064 1794842064

  ctime and btime on disk:        1794842068 1794842064

output after the fix:

  ctime and btime before readdir: 1794842908 1794842904
  ctime and btime after readdir:  1794842908 1794842904

  ctime and btime on disk:        1794842908 1794842904

Issue 2: btime and ptime wiped out by readdir

[ no reproducer as it only happens after the linked patch series is
  applied, since it needs cifs_i->createtime = fattr->cf_createtime in
  cifs_fattr_to_inode() ]

Issue 3: in-memory inode aliasing (flock bypass on hardlink via readdir)

  mkdir -p /mnt/dir1 /mnt/dir2
  echo "test" > /mnt/dir1/h1
  ln /mnt/dir1/h1 /mnt/dir2/h2
  exec 3< /mnt/dir1/h1
  flock -x -n 3 # get exclusive lock
  ls /mnt/dir2 > /dev/null
  exec 4< /mnt/dir2/h2
  flock -x -n 4
  if [ $? -eq 0 ];then
  	echo "acquired: duplicate in-memory inode"
  else
  	echo "blocked: same inode"
  fi

output before the fix:

  acquired: duplicate in-memory inode

output after the fix:

  blocked: same inode

Fixes: 3d519bd1269f ("cifs: plumb smb2 POSIX dir enumeration")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20261115180343.576773-1-koray.fra%40gmail.com?part=10
Link: https://lore.kernel.org/all/20261115180343.576773-11-koray.fra@gmail.com/
Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
Thanks,
koraynilay

 fs/smb/client/readdir.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c
index 525f99181485..5d335f12eb24 100644
--- a/fs/smb/client/readdir.c
+++ b/fs/smb/client/readdir.c
@@ -253,9 +253,10 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,
 	fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
 	fattr->cf_eof = le64_to_cpu(info->EndOfFile);
 
+	fattr->cf_createtime = le64_to_cpu(info->CreationTime);
 	fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
 	fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
-	fattr->cf_ctime = cifs_NTtimeToUnix(info->CreationTime);
+	fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
 
 	fattr->cf_nlink = le32_to_cpu(info->HardLinks);
 	fattr->cf_cifsattrs = le32_to_cpu(info->DosAttributes);

base-commit: 9928f403dfafd17dfe45678bbc6f623f72528744
prerequisite-patch-id: 049ae0eba275b5be35a238833107e0b251a55aa2
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] cifs: fix times assignments in cifs_posix_to_fattr()
  2026-11-16 15:45 [PATCH] cifs: fix times assignments in cifs_posix_to_fattr() koraynilay
@ 2026-11-16 22:23 ` Namjae Jeon
  2026-11-17 22:18 ` Paulo Alcantara
  1 sibling, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2026-11-16 22:23 UTC (permalink / raw)
  To: koraynilay
  Cc: Paulo Alcantara, Tom Talpey, Ronnie Sahlberg, Shyam Prasad N,
	Bharath SM, Aurelien Aptel, linux-cifs, linux-kernel, Sashiko

On Tue, Nov 17, 2026 at 12:45 AM koraynilay <koray.fra@gmail.com> wrote:
>
> Currently cifs_posix_to_fattr() wrongly sets SMB's CreationTime to
> fattr->cf_ctime.
>
> Fix this by setting fattr->cf_createtime to SMB's CreationTime and
> fattr->cf_ctime to SMB's ChangeTime, matching the behaviour of
> __dir_info_to_fattr().
>
> This patch also fixes a few related issues reported by sashiko on
> another patch (see Sashiko Link tag).
>
> Reproducers for these bugs, with /tmp as the local filesystem folder
> exported as [test] in ksmbd.conf and /mnt as the smb folder mounted with
> mount -t cifs:
>
>   mount -t cifs //127.0.0.1/test /mnt -o username=ciao,password=c,posix
>
> Issue 1: ctime clobbered by CreationTime during readdir
>
>   mkdir -p /mnt/dir
>   touch /mnt/dir/file
>   sleep 4
>   chmod 644 /mnt/dir/file
>   stat -c "ctime and btime before readdir: %Z %W" /mnt/dir/file
>   ls -lc /mnt/dir > /dev/null
>   stat -c "ctime and btime after readdir:  %Z %W" /mnt/dir/file
>   stat -c "ctime and btime on disk:        %Z %W" /tmp/dir/file
>
> output before the fix, notice how ctime is the same as btime after the
> readdir, while it's 4 seconds ahead (because of the sleep 4) before the
> readdir (on disk timestamps are not touched):
>
>   ctime and btime before readdir: 1794842068 1794842064
>   ctime and btime after readdir:  1794842064 1794842064
>
>   ctime and btime on disk:        1794842068 1794842064
>
> output after the fix:
>
>   ctime and btime before readdir: 1794842908 1794842904
>   ctime and btime after readdir:  1794842908 1794842904
>
>   ctime and btime on disk:        1794842908 1794842904
>
> Issue 2: btime and ptime wiped out by readdir
>
> [ no reproducer as it only happens after the linked patch series is
>   applied, since it needs cifs_i->createtime = fattr->cf_createtime in
>   cifs_fattr_to_inode() ]
>
> Issue 3: in-memory inode aliasing (flock bypass on hardlink via readdir)
>
>   mkdir -p /mnt/dir1 /mnt/dir2
>   echo "test" > /mnt/dir1/h1
>   ln /mnt/dir1/h1 /mnt/dir2/h2
>   exec 3< /mnt/dir1/h1
>   flock -x -n 3 # get exclusive lock
>   ls /mnt/dir2 > /dev/null
>   exec 4< /mnt/dir2/h2
>   flock -x -n 4
>   if [ $? -eq 0 ];then
>         echo "acquired: duplicate in-memory inode"
>   else
>         echo "blocked: same inode"
>   fi
>
> output before the fix:
>
>   acquired: duplicate in-memory inode
>
> output after the fix:
>
>   blocked: same inode
>
> Fixes: 3d519bd1269f ("cifs: plumb smb2 POSIX dir enumeration")
> Cc: stable@vger.kernel.org
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20261115180343.576773-1-koray.fra%40gmail.com?part=10
> Link: https://lore.kernel.org/all/20261115180343.576773-11-koray.fra@gmail.com/
> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7
> Signed-off-by: koraynilay <koray.fra@gmail.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cifs: fix times assignments in cifs_posix_to_fattr()
  2026-11-16 15:45 [PATCH] cifs: fix times assignments in cifs_posix_to_fattr() koraynilay
  2026-11-16 22:23 ` Namjae Jeon
@ 2026-11-17 22:18 ` Paulo Alcantara
  2026-11-17 23:56   ` koraynilay
  1 sibling, 1 reply; 4+ messages in thread
From: Paulo Alcantara @ 2026-11-17 22:18 UTC (permalink / raw)
  To: koraynilay, Namjae Jeon
  Cc: Tom Talpey, Ronnie Sahlberg, Shyam Prasad N, Bharath SM,
	Aurelien Aptel, linux-cifs, linux-kernel, koraynilay, Sashiko

koraynilay <koray.fra@gmail.com> writes:

> Currently cifs_posix_to_fattr() wrongly sets SMB's CreationTime to
> fattr->cf_ctime.
>
> Fix this by setting fattr->cf_createtime to SMB's CreationTime and
> fattr->cf_ctime to SMB's ChangeTime, matching the behaviour of
> __dir_info_to_fattr().
> ...

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cifs: fix times assignments in cifs_posix_to_fattr()
  2026-11-17 22:18 ` Paulo Alcantara
@ 2026-11-17 23:56   ` koraynilay
  0 siblings, 0 replies; 4+ messages in thread
From: koraynilay @ 2026-11-17 23:56 UTC (permalink / raw)
  To: Paulo Alcantara, koraynilay, Namjae Jeon
  Cc: Tom Talpey, Ronnie Sahlberg, Shyam Prasad N, Bharath SM,
	Aurelien Aptel, linux-cifs, linux-kernel, Sashiko

[-- Attachment #1: Type: text/plain, Size: 462 bytes --]

On Tue Nov 17, 2026 at 11:18 PM CET, Paulo Alcantara wrote:
> koraynilay <koray.fra@gmail.com> writes:
>
>> Currently cifs_posix_to_fattr() wrongly sets SMB's CreationTime to
>> fattr->cf_ctime.
>>
>> Fix this by setting fattr->cf_createtime to SMB's CreationTime and
>> fattr->cf_ctime to SMB's ChangeTime, matching the behaviour of
>> __dir_info_to_fattr().
>> ...
>
> Applied.

Thanks! (also for applying the other patches)

Best,
koraynilay

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-17 23:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 15:45 [PATCH] cifs: fix times assignments in cifs_posix_to_fattr() koraynilay
2026-11-16 22:23 ` Namjae Jeon
2026-11-17 22:18 ` Paulo Alcantara
2026-11-17 23:56   ` koraynilay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox