]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: statx() may return EINVAL if the kernel does not support the syscall
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 21 Jul 2023 16:15:59 +0000 (01:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 21 Jul 2023 17:20:22 +0000 (02:20 +0900)
When statx() is called with AT_STATX_DONT_SYNC, glibc's fallback code
returns EINVAL. See statx_generic() in glibc.

src/basic/mountpoint-util.c

index 3584f317876f533a00c84c61d8eab849b88171dd..d7b182f6dd0084170815fad510e9383b8e466a77 100644 (file)
@@ -223,7 +223,9 @@ int fd_is_mount_point(int fd, const char *filename, int flags) {
                   AT_STATX_DONT_SYNC,          /* don't go to the network for this – for similar reasons */
                   STATX_TYPE,
                   &sx) < 0) {
-                if (!ERRNO_IS_NOT_SUPPORTED(errno) && !ERRNO_IS_PRIVILEGE(errno))
+                if (!ERRNO_IS_NOT_SUPPORTED(errno) && /* statx() is not supported by the kernel. */
+                    !ERRNO_IS_PRIVILEGE(errno) &&     /* maybe filtered by seccomp. */
+                    errno != EINVAL)                  /* glibc's fallback method returns EINVAL when AT_STATX_DONT_SYNC is set. */
                         return -errno;
 
                 /* If statx() is not available or forbidden, fall back to name_to_handle_at() below */
@@ -371,7 +373,9 @@ int path_get_mnt_id_at(int dir_fd, const char *path, int *ret) {
                   AT_STATX_DONT_SYNC,  /* don't go to the network, mnt_id is a local concept */
                   STATX_MNT_ID,
                   &buf.sx) < 0) {
-                if (!ERRNO_IS_NOT_SUPPORTED(errno) && !ERRNO_IS_PRIVILEGE(errno))
+                if (!ERRNO_IS_NOT_SUPPORTED(errno) && /* statx() is not supported by the kernel. */
+                    !ERRNO_IS_PRIVILEGE(errno) &&     /* maybe filtered by seccomp. */
+                    errno != EINVAL)                  /* glibc's fallback method returns EINVAL when AT_STATX_DONT_SYNC is set. */
                         return -errno;
 
                 /* Fall back to name_to_handle_at() and then fdinfo if statx is not supported or we lack