* [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
@ 2021-03-11 12:03 Adhemerval Zanella
2021-03-11 12:13 ` Florian Weimer
0 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2021-03-11 12:03 UTC (permalink / raw)
To: libc-alpha
Now that fstat is implemented on top fstatat we need to handle negative
inputs.
Checked on x86_64-linux-gnu and on i686-linux-gnu.
---
io/Makefile | 2 +-
io/fstat.c | 6 ++
io/fstat64.c | 6 ++
io/tst-stat.c | 102 ++++++++++++++++++++++++++++++
sysdeps/unix/sysv/linux/fstat.c | 6 ++
sysdeps/unix/sysv/linux/fstat64.c | 12 ++++
6 files changed, 133 insertions(+), 1 deletion(-)
create mode 100644 io/tst-stat.c
diff --git a/io/Makefile b/io/Makefile
index b7bebe923f..d145d88f4e 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -68,7 +68,7 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \
tst-fts tst-fts-lfs tst-open-tmpfile \
tst-copy_file_range tst-getcwd-abspath tst-lockf \
tst-ftw-lnk tst-file_change_detection tst-lchmod \
- tst-ftw-bz26353
+ tst-ftw-bz26353 tst-stat tst-stat-lfs
# Likewise for statx, but we do not need static linking here.
tests-internal += tst-statx
diff --git a/io/fstat.c b/io/fstat.c
index dc117361ff..17f31bf3b3 100644
--- a/io/fstat.c
+++ b/io/fstat.c
@@ -16,10 +16,16 @@
<https://www.gnu.org/licenses/>. */
#include <sys/stat.h>
+#include <errno.h>
int
__fstat (int fd, struct stat *buf)
{
+ if (fd < 0)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
return __fstatat (fd, "", buf, AT_EMPTY_PATH);
}
diff --git a/io/fstat64.c b/io/fstat64.c
index addf379775..618170695c 100644
--- a/io/fstat64.c
+++ b/io/fstat64.c
@@ -16,10 +16,16 @@
<https://www.gnu.org/licenses/>. */
#include <sys/stat.h>
+#include <errno.h>
int
__fstat64 (int fd, struct stat64 *buf)
{
+ if (fd < 0)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
return __fstatat64 (fd, "", buf, AT_EMPTY_PATH);
}
hidden_def (__fstat64)
diff --git a/io/tst-stat.c b/io/tst-stat.c
new file mode 100644
index 0000000000..445ac4176c
--- /dev/null
+++ b/io/tst-stat.c
@@ -0,0 +1,102 @@
+/* Basic tests for stat, lstat, fstat, and fstatat.
+ Copyright (C) 2021 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <array_length.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <support/check.h>
+#include <support/support.h>
+#include <support/temp_file.h>
+#include <support/xunistd.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <unistd.h>
+
+static void
+stat_check (int fd, const char *path, struct stat *st)
+{
+ TEST_COMPARE (stat (path, st), 0);
+}
+
+static void
+lstat_check (int fd, const char *path, struct stat *st)
+{
+ TEST_COMPARE (lstat (path, st), 0);
+}
+
+static void
+fstat_check (int fd, const char *path, struct stat *st)
+{
+ /* Test for invalid fstat input (BZ #27559). */
+ TEST_COMPARE (fstat (AT_FDCWD, st), -1);
+ TEST_COMPARE (errno, EBADF);
+
+ TEST_COMPARE (fstat (fd, st), 0);
+}
+
+static void
+fstatat_check (int fd, const char *path, struct stat *st)
+{
+ TEST_COMPARE (fstatat (fd, "", st, 0), -1);
+ TEST_COMPARE (errno, ENOENT);
+
+ TEST_COMPARE (fstatat (fd, path, st, 0), 0);
+}
+
+typedef void (*test_t)(int, const char *path, struct stat *);
+
+static int
+do_test (void)
+{
+ char *path;
+ int fd = create_temp_file ("tst-fstat.", &path);
+ TEST_VERIFY_EXIT (fd >= 0);
+ support_write_file_string (path, "abc");
+
+ struct statx stx;
+ TEST_COMPARE (statx (fd, path, 0, STATX_BASIC_STATS, &stx), 0);
+
+ test_t tests[] = { stat_check, lstat_check, fstat_check, fstatat_check };
+
+ for (int i = 0; i < array_length (tests); i++)
+ {
+ struct stat st;
+ tests[i](fd, path, &st);
+
+ TEST_COMPARE (stx.stx_dev_major, major (st.st_dev));
+ TEST_COMPARE (stx.stx_dev_minor, minor (st.st_dev));
+ TEST_COMPARE (stx.stx_ino, st.st_ino);
+ TEST_COMPARE (stx.stx_mode, st.st_mode);
+ TEST_COMPARE (stx.stx_nlink, st.st_nlink);
+ TEST_COMPARE (stx.stx_uid, st.st_uid);
+ TEST_COMPARE (stx.stx_gid, st.st_gid);
+ TEST_COMPARE (stx.stx_rdev_major, major (st.st_rdev));
+ TEST_COMPARE (stx.stx_rdev_minor, minor (st.st_rdev));
+ TEST_COMPARE (stx.stx_blksize, st.st_blksize);
+ TEST_COMPARE (stx.stx_blocks, st.st_blocks);
+
+ TEST_COMPARE (stx.stx_ctime.tv_sec, st.st_ctim.tv_sec);
+ TEST_COMPARE (stx.stx_ctime.tv_nsec, st.st_ctim.tv_nsec);
+ TEST_COMPARE (stx.stx_mtime.tv_sec, st.st_mtim.tv_sec);
+ TEST_COMPARE (stx.stx_mtime.tv_nsec, st.st_mtim.tv_nsec);
+ }
+
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/unix/sysv/linux/fstat.c b/sysdeps/unix/sysv/linux/fstat.c
index fd64362205..31a172dcc8 100644
--- a/sysdeps/unix/sysv/linux/fstat.c
+++ b/sysdeps/unix/sysv/linux/fstat.c
@@ -19,11 +19,17 @@
#include <sys/stat.h>
#include <kernel_stat.h>
#include <fcntl.h>
+#include <errno.h>
#if !XSTAT_IS_XSTAT64
int
__fstat (int fd, struct stat *buf)
{
+ if (fd < 0)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
return __fstatat (fd, "", buf, AT_EMPTY_PATH);
}
diff --git a/sysdeps/unix/sysv/linux/fstat64.c b/sysdeps/unix/sysv/linux/fstat64.c
index 993abcb445..46de80b663 100644
--- a/sysdeps/unix/sysv/linux/fstat64.c
+++ b/sysdeps/unix/sysv/linux/fstat64.c
@@ -22,10 +22,16 @@
#include <fcntl.h>
#include <kernel_stat.h>
#include <stat_t64_cp.h>
+#include <errno.h>
int
__fstat64_time64 (int fd, struct __stat64_t64 *buf)
{
+ if (fd < 0)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
return __fstatat64_time64 (fd, "", buf, AT_EMPTY_PATH);
}
#if __TIMESIZE != 64
@@ -34,6 +40,12 @@ hidden_def (__fstat64_time64)
int
__fstat64 (int fd, struct stat64 *buf)
{
+ if (fd < 0)
+ {
+ __set_errno (EBADF);
+ return -1;
+ }
+
struct __stat64_t64 st_t64;
return __fstat64_time64 (fd, &st_t64)
?: __cp_stat64_t64_stat64 (&st_t64, buf);
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
2021-03-11 12:03 [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559) Adhemerval Zanella
@ 2021-03-11 12:13 ` Florian Weimer
2021-03-11 12:37 ` Adhemerval Zanella
0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2021-03-11 12:13 UTC (permalink / raw)
To: Adhemerval Zanella via Libc-alpha
* Adhemerval Zanella via Libc-alpha:
> Now that fstat is implemented on top fstatat we need to handle negative
> inputs.
Please mention AT_FDCWD in the commit message. Or add a comment to the
code that the check rejects AT_FDCWD, which would otherwise be accepted
by the kernel.
The patch looks okay otherwise.
Thanks,
Florian
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
2021-03-11 12:13 ` Florian Weimer
@ 2021-03-11 12:37 ` Adhemerval Zanella
2021-03-12 13:44 ` Stefan Liebler
0 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2021-03-11 12:37 UTC (permalink / raw)
To: Florian Weimer, Adhemerval Zanella via Libc-alpha
On 11/03/2021 09:13, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
>
>> Now that fstat is implemented on top fstatat we need to handle negative
>> inputs.
>
> Please mention AT_FDCWD in the commit message. Or add a comment to the
> code that the check rejects AT_FDCWD, which would otherwise be accepted
> by the kernel.
>
> The patch looks okay otherwise.
Ack. I will also add the missing tst-stat-lfs (which is just a wrapper
to set __FILE_OFFSET_BITS=64).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
2021-03-11 12:37 ` Adhemerval Zanella
@ 2021-03-12 13:44 ` Stefan Liebler
2021-03-12 13:57 ` Adhemerval Zanella
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Liebler @ 2021-03-12 13:44 UTC (permalink / raw)
To: libc-alpha, Adhemerval Zanella
On 3/11/21 1:37 PM, Adhemerval Zanella via Libc-alpha wrote:
>
>
> On 11/03/2021 09:13, Florian Weimer wrote:
>> * Adhemerval Zanella via Libc-alpha:
>>
>>> Now that fstat is implemented on top fstatat we need to handle negative
>>> inputs.
>>
>> Please mention AT_FDCWD in the commit message. Or add a comment to the
>> code that the check rejects AT_FDCWD, which would otherwise be accepted
>> by the kernel.
>>
>> The patch looks okay otherwise.
>
> Ack. I will also add the missing tst-stat-lfs (which is just a wrapper
> to set __FILE_OFFSET_BITS=64).
>
Hi Adhemerval,
I've just recognized that io/tst-stat is failing on my s390 (31bit) system:
tst-stat.c:94: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
right: 0 (0x0); from: st.st_ctim.tv_nsec
tst-stat.c:96: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
right: 0 (0x0); from: st.st_mtim.tv_nsec
tst-stat.c:94: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
right: 0 (0x0); from: st.st_ctim.tv_nsec
tst-stat.c:96: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
right: 0 (0x0); from: st.st_mtim.tv_nsec
tst-stat.c:94: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
right: 0 (0x0); from: st.st_ctim.tv_nsec
tst-stat.c:96: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
right: 0 (0x0); from: st.st_mtim.tv_nsec
tst-stat.c:94: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
right: 0 (0x0); from: st.st_ctim.tv_nsec
tst-stat.c:96: numeric comparison failure
left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
right: 0 (0x0); from: st.st_mtim.tv_nsec
error: 8 test failures
But I have to admit, I haven't looked into the test yet and won't be
able before next week. But I wanted to report it now.
Bye,
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
2021-03-12 13:44 ` Stefan Liebler
@ 2021-03-12 13:57 ` Adhemerval Zanella
2021-03-12 14:21 ` Adhemerval Zanella
0 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2021-03-12 13:57 UTC (permalink / raw)
To: Stefan Liebler, libc-alpha
On 12/03/2021 10:44, Stefan Liebler wrote:
> On 3/11/21 1:37 PM, Adhemerval Zanella via Libc-alpha wrote:
>>
>>
>> On 11/03/2021 09:13, Florian Weimer wrote:
>>> * Adhemerval Zanella via Libc-alpha:
>>>
>>>> Now that fstat is implemented on top fstatat we need to handle negative
>>>> inputs.
>>>
>>> Please mention AT_FDCWD in the commit message. Or add a comment to the
>>> code that the check rejects AT_FDCWD, which would otherwise be accepted
>>> by the kernel.
>>>
>>> The patch looks okay otherwise.
>>
>> Ack. I will also add the missing tst-stat-lfs (which is just a wrapper
>> to set __FILE_OFFSET_BITS=64).
>>
>
> Hi Adhemerval,
>
> I've just recognized that io/tst-stat is failing on my s390 (31bit) system:
> tst-stat.c:94: numeric comparison failure
>
> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>
> right: 0 (0x0); from: st.st_ctim.tv_nsec
>
> tst-stat.c:96: numeric comparison failure
>
> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
> right: 0 (0x0); from: st.st_mtim.tv_nsec
> tst-stat.c:94: numeric comparison failure
> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
> right: 0 (0x0); from: st.st_ctim.tv_nsec
> tst-stat.c:96: numeric comparison failure
> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
> right: 0 (0x0); from: st.st_mtim.tv_nsec
> tst-stat.c:94: numeric comparison failure
> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
> right: 0 (0x0); from: st.st_ctim.tv_nsec
> tst-stat.c:96: numeric comparison failure
> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
> right: 0 (0x0); from: st.st_mtim.tv_nsec
> tst-stat.c:94: numeric comparison failure
> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
> right: 0 (0x0); from: st.st_ctim.tv_nsec
> tst-stat.c:96: numeric comparison failure
> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
> right: 0 (0x0); from: st.st_mtim.tv_nsec
> error: 8 test failures
>
>
> But I have to admit, I haven't looked into the test yet and won't be
> able before next week. But I wanted to report it now.
>
> Bye,
> Stefan
I will check this out on a s390 system.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
2021-03-12 13:57 ` Adhemerval Zanella
@ 2021-03-12 14:21 ` Adhemerval Zanella
2021-03-16 13:57 ` Stefan Liebler
0 siblings, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2021-03-12 14:21 UTC (permalink / raw)
To: Stefan Liebler, libc-alpha
On 12/03/2021 10:57, Adhemerval Zanella wrote:
>
>
> On 12/03/2021 10:44, Stefan Liebler wrote:
>> On 3/11/21 1:37 PM, Adhemerval Zanella via Libc-alpha wrote:
>>>
>>>
>>> On 11/03/2021 09:13, Florian Weimer wrote:
>>>> * Adhemerval Zanella via Libc-alpha:
>>>>
>>>>> Now that fstat is implemented on top fstatat we need to handle negative
>>>>> inputs.
>>>>
>>>> Please mention AT_FDCWD in the commit message. Or add a comment to the
>>>> code that the check rejects AT_FDCWD, which would otherwise be accepted
>>>> by the kernel.
>>>>
>>>> The patch looks okay otherwise.
>>>
>>> Ack. I will also add the missing tst-stat-lfs (which is just a wrapper
>>> to set __FILE_OFFSET_BITS=64).
>>>
>>
>> Hi Adhemerval,
>>
>> I've just recognized that io/tst-stat is failing on my s390 (31bit) system:
>> tst-stat.c:94: numeric comparison failure
>>
>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>>
>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>>
>> tst-stat.c:96: numeric comparison failure
>>
>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>> tst-stat.c:94: numeric comparison failure
>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>> tst-stat.c:96: numeric comparison failure
>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>> tst-stat.c:94: numeric comparison failure
>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>> tst-stat.c:96: numeric comparison failure
>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>> tst-stat.c:94: numeric comparison failure
>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>> tst-stat.c:96: numeric comparison failure
>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>> error: 8 test failures
>>
>>
>> But I have to admit, I haven't looked into the test yet and won't be
>> able before next week. But I wanted to report it now.
>>
>> Bye,
>> Stefan
>
>
> I will check this out on a s390 system.
>
I think we stumbled on another kernel limitation/issue: the tst-stat uses
the __NR_fstatat64 call that for s390 will use the entrypoint:
arch/s390/kernel/compat_linux.c:
150 COMPAT_SYSCALL_DEFINE2(s390_stat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf)
151 {
152 struct kstat stat;
153 int ret = vfs_stat(filename, &stat);
154 if (!ret)
155 ret = cp_stat64(statbuf, &stat);
156 return ret;
157 }
And the cp_stat64 explicit omit the nanoseconds fields:
126 static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
127 {
128 struct stat64_emu31 tmp;
129
130 memset(&tmp, 0, sizeof(tmp));
131
132 tmp.st_dev = huge_encode_dev(stat->dev);
133 tmp.st_ino = stat->ino;
134 tmp.__st_ino = (u32)stat->ino;
135 tmp.st_mode = stat->mode;
136 tmp.st_nlink = (unsigned int)stat->nlink;
137 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
138 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
139 tmp.st_rdev = huge_encode_dev(stat->rdev);
140 tmp.st_size = stat->size;
141 tmp.st_blksize = (u32)stat->blksize;
142 tmp.st_blocks = (u32)stat->blocks;
143 tmp.st_atime = (u32)stat->atime.tv_sec;
144 tmp.st_mtime = (u32)stat->mtime.tv_sec;
145 tmp.st_ctime = (u32)stat->ctime.tv_sec;
146
147 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
148 }
It seems deliberated from a comment that hits the idea was to in the
future to use the __pad[6,7,8] (meant to nanoseconds) as the high
bits for the seconds part.
The straightforward fix would to just disable the nanoseconds check
for non-lfs interface. For LFS interface s390 will use statx as
other architectures, which should mitigate the issue on recent
kernels.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559)
2021-03-12 14:21 ` Adhemerval Zanella
@ 2021-03-16 13:57 ` Stefan Liebler
0 siblings, 0 replies; 7+ messages in thread
From: Stefan Liebler @ 2021-03-16 13:57 UTC (permalink / raw)
To: Adhemerval Zanella, libc-alpha
On 12/03/2021 15:21, Adhemerval Zanella wrote:
>
>
> On 12/03/2021 10:57, Adhemerval Zanella wrote:
>>
>>
>> On 12/03/2021 10:44, Stefan Liebler wrote:
>>> On 3/11/21 1:37 PM, Adhemerval Zanella via Libc-alpha wrote:
>>>>
>>>>
>>>> On 11/03/2021 09:13, Florian Weimer wrote:
>>>>> * Adhemerval Zanella via Libc-alpha:
>>>>>
>>>>>> Now that fstat is implemented on top fstatat we need to handle negative
>>>>>> inputs.
>>>>>
>>>>> Please mention AT_FDCWD in the commit message. Or add a comment to the
>>>>> code that the check rejects AT_FDCWD, which would otherwise be accepted
>>>>> by the kernel.
>>>>>
>>>>> The patch looks okay otherwise.
>>>>
>>>> Ack. I will also add the missing tst-stat-lfs (which is just a wrapper
>>>> to set __FILE_OFFSET_BITS=64).
>>>>
>>>
>>> Hi Adhemerval,
>>>
>>> I've just recognized that io/tst-stat is failing on my s390 (31bit) system:
>>> tst-stat.c:94: numeric comparison failure
>>>
>>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>>>
>>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>>>
>>> tst-stat.c:96: numeric comparison failure
>>>
>>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>>> tst-stat.c:94: numeric comparison failure
>>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>>> tst-stat.c:96: numeric comparison failure
>>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>>> tst-stat.c:94: numeric comparison failure
>>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>>> tst-stat.c:96: numeric comparison failure
>>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>>> tst-stat.c:94: numeric comparison failure
>>> left: 315117680 (0x12c85070); from: stx.stx_ctime.tv_nsec
>>> right: 0 (0x0); from: st.st_ctim.tv_nsec
>>> tst-stat.c:96: numeric comparison failure
>>> left: 315117680 (0x12c85070); from: stx.stx_mtime.tv_nsec
>>> right: 0 (0x0); from: st.st_mtim.tv_nsec
>>> error: 8 test failures
>>>
>>>
>>> But I have to admit, I haven't looked into the test yet and won't be
>>> able before next week. But I wanted to report it now.
>>>
>>> Bye,
>>> Stefan
>>
>>
>> I will check this out on a s390 system.
>>
>
> I think we stumbled on another kernel limitation/issue: the tst-stat uses
> the __NR_fstatat64 call that for s390 will use the entrypoint:
>
> arch/s390/kernel/compat_linux.c:
>
> 150 COMPAT_SYSCALL_DEFINE2(s390_stat64, const char __user *, filename, struct stat64_emu31 __user *, statbuf)
> 151 {
> 152 struct kstat stat;
> 153 int ret = vfs_stat(filename, &stat);
> 154 if (!ret)
> 155 ret = cp_stat64(statbuf, &stat);
> 156 return ret;
> 157 }
>
> And the cp_stat64 explicit omit the nanoseconds fields:
>
> 126 static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
> 127 {
> 128 struct stat64_emu31 tmp;
> 129
> 130 memset(&tmp, 0, sizeof(tmp));
> 131
> 132 tmp.st_dev = huge_encode_dev(stat->dev);
> 133 tmp.st_ino = stat->ino;
> 134 tmp.__st_ino = (u32)stat->ino;
> 135 tmp.st_mode = stat->mode;
> 136 tmp.st_nlink = (unsigned int)stat->nlink;
> 137 tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
> 138 tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
> 139 tmp.st_rdev = huge_encode_dev(stat->rdev);
> 140 tmp.st_size = stat->size;
> 141 tmp.st_blksize = (u32)stat->blksize;
> 142 tmp.st_blocks = (u32)stat->blocks;
> 143 tmp.st_atime = (u32)stat->atime.tv_sec;
> 144 tmp.st_mtime = (u32)stat->mtime.tv_sec;
> 145 tmp.st_ctime = (u32)stat->ctime.tv_sec;
> 146
> 147 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
> 148 }
>
> It seems deliberated from a comment that hits the idea was to in the
> future to use the __pad[6,7,8] (meant to nanoseconds) as the high
> bits for the seconds part.
>
> The straightforward fix would to just disable the nanoseconds check
> for non-lfs interface. For LFS interface s390 will use statx as
> other architectures, which should mitigate the issue on recent
> kernels.
>
Hi Adhemerval,
thanks very much for looking into it.
I've just posted this patch:
"[PATCH] Don't test nanoseconds for non-LFS interface in io/tst-stat.c"
https://sourceware.org/pipermail/libc-alpha/2021-March/123943.html
Thanks,
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-03-16 13:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 12:03 [PATCH] io: Return EBAFD for negative file descriptor on fstat (BZ #27559) Adhemerval Zanella
2021-03-11 12:13 ` Florian Weimer
2021-03-11 12:37 ` Adhemerval Zanella
2021-03-12 13:44 ` Stefan Liebler
2021-03-12 13:57 ` Adhemerval Zanella
2021-03-12 14:21 ` Adhemerval Zanella
2021-03-16 13:57 ` Stefan Liebler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).