* [musl] [PATCH] statx: fix ENOSYS emulation not setting stx_rdev_*
@ 2024-09-13 20:00 Gabriel Ravier
2024-09-13 21:14 ` Rich Felker
0 siblings, 1 reply; 2+ messages in thread
From: Gabriel Ravier @ 2024-09-13 20:00 UTC (permalink / raw)
To: musl; +Cc: Gabriel Ravier
The current implementation of the statx function fails to set the
values of stx->stx_rdev_major and stx->stx_rdev_minor if the statx
syscall fails with ENOSYS and thus the statx function has to fall back
on fstatat-based emulation.
This commit fixes this.
Note: I have not strictly been able to test this in "natural
conditions", i.e. on a kernel without statx support, but I have been
able to test this on a kernel that has statx and fstatat support in
two different ways:
- by removing the call to __syscall(SYS_statx, ...) and replacing it with
`int err = -ENOSYS;`, and
- using a seccomp eBPF filter to catch statx syscalls and making them
return ENOSYS
---
src/linux/statx.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/linux/statx.c b/src/linux/statx.c
index 4616bff4..5f6dde92 100644
--- a/src/linux/statx.c
+++ b/src/linux/statx.c
@@ -21,6 +21,8 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct
stx->stx_dev_major = major(st.st_dev);
stx->stx_dev_minor = minor(st.st_dev);
+ stx->stx_rdev_major = major(st.st_rdev);
+ stx->stx_rdev_minor = minor(st.st_rdev);
stx->stx_ino = st.st_ino;
stx->stx_mode = st.st_mode;
stx->stx_nlink = st.st_nlink;
--
2.46.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [musl] [PATCH] statx: fix ENOSYS emulation not setting stx_rdev_*
2024-09-13 20:00 [musl] [PATCH] statx: fix ENOSYS emulation not setting stx_rdev_* Gabriel Ravier
@ 2024-09-13 21:14 ` Rich Felker
0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2024-09-13 21:14 UTC (permalink / raw)
To: Gabriel Ravier; +Cc: musl
[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]
On Fri, Sep 13, 2024 at 10:00:15PM +0200, Gabriel Ravier wrote:
> The current implementation of the statx function fails to set the
> values of stx->stx_rdev_major and stx->stx_rdev_minor if the statx
> syscall fails with ENOSYS and thus the statx function has to fall back
> on fstatat-based emulation.
>
> This commit fixes this.
>
> Note: I have not strictly been able to test this in "natural
> conditions", i.e. on a kernel without statx support, but I have been
> able to test this on a kernel that has statx and fstatat support in
> two different ways:
> - by removing the call to __syscall(SYS_statx, ...) and replacing it with
> `int err = -ENOSYS;`, and
> - using a seccomp eBPF filter to catch statx syscalls and making them
> return ENOSYS
> ---
> src/linux/statx.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/linux/statx.c b/src/linux/statx.c
> index 4616bff4..5f6dde92 100644
> --- a/src/linux/statx.c
> +++ b/src/linux/statx.c
> @@ -21,6 +21,8 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct
>
> stx->stx_dev_major = major(st.st_dev);
> stx->stx_dev_minor = minor(st.st_dev);
> + stx->stx_rdev_major = major(st.st_rdev);
> + stx->stx_rdev_minor = minor(st.st_rdev);
> stx->stx_ino = st.st_ino;
> stx->stx_mode = st.st_mode;
> stx->stx_nlink = st.st_nlink;
> --
> 2.46.0
Thanks. I recall back in the spring I was waiting on someone else who
proposed to fix this, but never followed up, so I'll go ahead and
merge your patch now. I also have further fixes which I'll commit
separately (attached).
Rich
[-- Attachment #2: 0001-statx-fix-uninitialized-attributes-mask-in-fallback-.patch --]
[-- Type: text/plain, Size: 1783 bytes --]
From 4ca8c267768e371930ef7ec9593a5f8b44a7f810 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Fri, 13 Sep 2024 17:08:11 -0400
Subject: [PATCH] statx: fix uninitialized attributes/mask in fallback path
commit b817541f1cfd38e4b81257b3215e276ea9d0fc61 introduced statx with
a fallback using fstatat, but failed to fill in stx_rdev_major/minor
and stx_attributes[_mask]. the rdev omission has been addressed
separately. rather than explicitly zeroing the attributes and their
mask, pre-fill the entire structure with zeros. this will also cover
the padding adjacent to stx_mode, in case it's ever used in the
future.
explicit zeroing of stx_btime is removed since, with this change, it
will already be pre-zeroed. as an aside, zeroing it was not strictly
necessary, since STATX_BASIC_STATS does not include STATX_BTIME and
thus does not indicate any validity for it.
---
src/linux/statx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/linux/statx.c b/src/linux/statx.c
index 5f6dde92..4fb96e4b 100644
--- a/src/linux/statx.c
+++ b/src/linux/statx.c
@@ -19,6 +19,7 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct
ret = fstatat(dirfd, path, &st, flags);
if (ret) return ret;
+ *stx = (struct statx){0};
stx->stx_dev_major = major(st.st_dev);
stx->stx_dev_minor = minor(st.st_dev);
stx->stx_rdev_major = major(st.st_rdev);
@@ -37,7 +38,6 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct
stx->stx_mtime.tv_nsec = st.st_mtim.tv_nsec;
stx->stx_ctime.tv_sec = st.st_ctim.tv_sec;
stx->stx_ctime.tv_nsec = st.st_ctim.tv_nsec;
- stx->stx_btime = (struct statx_timestamp){.tv_sec=0, .tv_nsec=0};
stx->stx_mask = STATX_BASIC_STATS;
return 0;
--
2.21.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-13 21:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-13 20:00 [musl] [PATCH] statx: fix ENOSYS emulation not setting stx_rdev_* Gabriel Ravier
2024-09-13 21:14 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).