autofs: use flexible array in ioctl structure
authorArnd Bergmann <arnd@arndb.de>
Tue, 23 May 2023 08:19:35 +0000 (10:19 +0200)
committerKees Cook <keescook@chromium.org>
Tue, 30 May 2023 23:42:00 +0000 (16:42 -0700)
Commit df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3") introduced a warning
for the autofs_dev_ioctl structure:

In function 'check_name',
    inlined from 'validate_dev_ioctl' at fs/autofs/dev-ioctl.c:131:9,
    inlined from '_autofs_dev_ioctl' at fs/autofs/dev-ioctl.c:624:8:
fs/autofs/dev-ioctl.c:33:14: error: 'strchr' reading 1 or more bytes from a region of size 0 [-Werror=stringop-overread]
   33 |         if (!strchr(name, '/'))
      |              ^~~~~~~~~~~~~~~~~
In file included from include/linux/auto_dev-ioctl.h:10,
                 from fs/autofs/autofs_i.h:10,
                 from fs/autofs/dev-ioctl.c:14:
include/uapi/linux/auto_dev-ioctl.h: In function '_autofs_dev_ioctl':
include/uapi/linux/auto_dev-ioctl.h:112:14: note: source object 'path' of size 0
  112 |         char path[0];
      |              ^~~~

This is easily fixed by changing the gnu 0-length array into a c99
flexible array. Since this is a uapi structure, we have to be careful
about possible regressions but this one should be fine as they are
equivalent here. While it would break building with ancient gcc versions
that predate c99, it helps building with --std=c99 and -Wpedantic builds
in user space, as well as non-gnu compilers. This means we probably
also want it fixed in stable kernels.

Cc: stable@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Cc: Gustavo A. R. Silva" <gustavoars@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230523081944.581710-1-arnd@kernel.org
Documentation/filesystems/autofs-mount-control.rst
Documentation/filesystems/autofs.rst
include/uapi/linux/auto_dev-ioctl.h

index bf4b511cdbe85dbb775030ac23761a7b9007e575..b5a379d25c40b3e3ebe17a514e40189216c21d38 100644 (file)
@@ -196,7 +196,7 @@ information and return operation results::
                    struct args_ismountpoint    ismountpoint;
            };
 
-           char path[0];
+           char path[];
     };
 
 The ioctlfd field is a mount point file descriptor of an autofs mount
index 4f490278d22fca8a27533bb16e5411ea42600f67..3b6e38e646cd8c362960351a84885f56202ccf1a 100644 (file)
@@ -467,7 +467,7 @@ Each ioctl is passed a pointer to an `autofs_dev_ioctl` structure::
                        struct args_ismountpoint        ismountpoint;
                };
 
-                char path[0];
+                char path[];
         };
 
 For the **OPEN_MOUNT** and **IS_MOUNTPOINT** commands, the target
index 62e625356dc81abd2e64cbd8818e265a23dc691a..08be539605fcab76bcb06593be4c2cd2676f6cf8 100644 (file)
@@ -109,7 +109,7 @@ struct autofs_dev_ioctl {
                struct args_ismountpoint        ismountpoint;
        };
 
-       char path[0];
+       char path[];
 };
 
 static inline void init_autofs_dev_ioctl(struct autofs_dev_ioctl *in)