Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

autofs: use flexible array in ioctl structure

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

authored by

Arnd Bergmann and committed by
Kees Cook
e910c8e3 b45861ed

+3 -3
+1 -1
Documentation/filesystems/autofs-mount-control.rst
··· 196 196 struct args_ismountpoint ismountpoint; 197 197 }; 198 198 199 - char path[0]; 199 + char path[]; 200 200 }; 201 201 202 202 The ioctlfd field is a mount point file descriptor of an autofs mount
+1 -1
Documentation/filesystems/autofs.rst
··· 467 467 struct args_ismountpoint ismountpoint; 468 468 }; 469 469 470 - char path[0]; 470 + char path[]; 471 471 }; 472 472 473 473 For the **OPEN_MOUNT** and **IS_MOUNTPOINT** commands, the target
+1 -1
include/uapi/linux/auto_dev-ioctl.h
··· 109 109 struct args_ismountpoint ismountpoint; 110 110 }; 111 111 112 - char path[0]; 112 + char path[]; 113 113 }; 114 114 115 115 static inline void init_autofs_dev_ioctl(struct autofs_dev_ioctl *in)