Re: [PATCH 2/2] cifs: fix negative timestamps being read from smb

From: Namjae Jeon

Date: Thu Nov 12 2026 - 20:08:02 EST


On Thu, Nov 12, 2026 at 8:16 PM koraynilay <koray.fra@xxxxxxxxx> wrote:
>
> When reading a timestamp before epoch 0, cifs converts it from NT format
> to Unix format without normalizing it, leading to the nanoseconds field
> to be used as a negative number, which leads to a garbled stat command
> output.
>
> This bug also violates a struct timespec64 invariant, as documented in
> the set_normalized_timespec64() kernel-doc:
> [...]
> * Note: The tv_nsec part is always in the range of 0 <= tv_nsec < NSEC_PER_SEC.
> * For negative values only the tv_sec field is negative !
> */
>
> Reproducer, 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=user,password=pass
> touch -d "1969-07-20 20:17:40.123456789" /tmp/test.txt
> stat -c "Server local (/tmp): %y" /tmp/test.txt
> stat -c "CIFS client (/mnt): %y" /mnt/test.txt --cached=never
> smbclient //127.0.0.1/test -U user%pass -c "allinfo test.txt"
>
> which prints (stat output is garbled because of negative value):
>
> Server local (/tmp): 1969-07-20 20:17:40.123456789 +0000
> CIFS client (/mnt): 1969-07-20 20:17:41.()*+,--00 +0000
> altname: TESTT~K6.TXT
> [...]
> access_time: Sun Jul 20 20:17:40 1969 UTC
> write_time: Sun Jul 20 20:17:40 1969 UTC
> [...]
>
> Fix this by using set_normalized_timespec64() in cifs_NTtimeToUnix().
>
> Fixes: 2ae83bf93882 ("[CIFS] Fix setting time before epoch (negative time values)")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.3
> Signed-off-by: koraynilay <koray.fra@xxxxxxxxx>
Looks good to me.
Reviewed-by: Namjae Jeon <linkinjeon@xxxxxxxxxx>