[PATCH] Rename STAT_HAS_TIME32 to KERNEL_STAT64_HAS_TIME32

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Nov 7 18:08:22 GMT 2022



On 04/11/22 07:02, Arnd Bergmann wrote:
> On Fri, Nov 4, 2022, at 02:54, YunQiang Su wrote:
>> The macro name STAT_HAS_TIME32 is not so clear.
>>
>> This macro is used for some arch like MIPSn64.
>> The kernel_stat/kernel_stat64 of it has a 32bit unsigned time value.
>> Thus that has y2106 problem.
>> So we should statx to solve this problem.
> 
> I was surprised that you identified this as a y2106 problem
> rather than a y2038 problem, so I took a closer look at how this
> is handled in the kernel. I found a few interesting bits, in
> no particular order:
> 
> - mips-n64 does not have a 'stat64' interface, the kernel
>   only provides the 'stat', which has the same layout as
>   the n32 and o32 'stat64'. From the kernel perspective,
>   using KERNEL_STAT64_HAS_TIME32 seems like a misnomer,
>   but it's possible that glibc just names things differently
>   here.
> 
> - parisc64 has the same problem by only exposing a 32-bit
>   timestamp in stat, but unlike mips, it has both 'stat'
>   and 'stat64' interfaces, with both using the same layout
>   as the corresponding parisc32 syscalls. All other 64-bit
>   architectures have a 'stat' interface with 64-bit
>   timestamps, on alpha and sparc64 there is also a stat64
>   interface because the 'stat' version is limited in
>   other ways.
> 
> - There is a mix of signed and unsigned types in the
>   asm/stat.h headers, and you correctly identified mips64
>   as using an unsigned type (hence the y2106 limit),
>   however mips32 is one of the ones using a signed field,
>   and the kernel does not behave any different and
>   just relies on gcc's -fno-strict-overflow to truncate
>   a 64-bit time64_t into a 32-bit signed or unsigned
>   type either way.
> 
> - When I worked on the original time64 support for the
>   kernel, I'm sure we had discussed truncating the values
>   to the correct range on the stat interfaces, but this
>   has evidently never happened. We should probably add
>   such truncation, but we would have to decide whether to
>   truncate this to range of the declared type or more
>   sensibly to the range of the traditional time_t type.
> 
> - Note that common file systems like xfs and ext3
>   intentionally store filesystem timestamps as 'signed'
>   for compatibility with 32-bit user space, so there
>   is precedent for interpreting the values as signed
>   on 64-bit architectures when the range is limited.
> 
>         Arnd

In fact it was reported as an y2106 problem some time ago [1] and we
fixed on 2.34 [2].  And I give that STAT_HAS_TIME32 is not entirely
clear, since for glibc perspective is has multiple stat definitions.

And I agree with Arnd here, KERNEL_STAT_HAS_TIME32 would be more clear
(and glibc side it does have the kernel stat as kernel_stat).

It is good to have some confirmation that only mips has this issue,
for hppa we follow the current legacy 32 bit to use statx and ony
fallback if kernel is not present.

[1] https://sourceware.org/pipermail/libc-alpha/2021-March/123753.html
[2] https://sourceware.org/git/?p=glibc.git;a=commit;h=5b980d4809913088729982865188b754939bcd39


More information about the Libc-alpha mailing list