]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
aarch64: morello: fix missing variadic argument in fcntl
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 15 Jul 2022 13:10:53 +0000 (14:10 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:50 +0000 (14:46 +0100)
In fcntl va_arg is currently used even if the caller did not pass
any variadic arguments. This is undefined behaviour and does not
work with the Morello purecap ABI, so use a helper macro.

When the argument is missing, the result of the helper macro is
arbitrary as it will be ignored by the kernel, we just have to
ensure it does not cause a runtime crash.

sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h
sysdeps/unix/sysv/linux/fcntl64.c
sysdeps/unix/sysv/linux/fcntl_nocancel.c

index 5db89b096d75d1b6d6b6b9458674bf2e1217969a..bad64a0674a717c5846ba7127a73c515c944271f 100644 (file)
@@ -105,6 +105,8 @@ typedef __intcap_t __sysarg_t;
   LOAD_ARGS_6 (c0, c1, c2, c3, c4, c5)         \
   register __sysarg_t _x6 asm ("c6") = _x6tmp;
 
+# define FCNTL_VA_ARG(a, t) (a ? va_arg(a, t) : 0)
+
 #endif /* __ASSEMBLER__ */
 
 /* Disable pointer mangling for purecap ABI.  */
index 5192b2d67266790d461a5002ce1bd861129a87b1..0b6afd3b59e7b936ff6dc94c7b9c3aacb220ee4d 100644 (file)
 # define __NR_fcntl64 __NR_fcntl
 #endif
 
+#ifndef FCNTL_VA_ARG
+# define FCNTL_VA_ARG(a, t) va_arg(a, t)
+#endif
+
 #ifndef FCNTL_ADJUST_CMD
 # define FCNTL_ADJUST_CMD(__cmd) __cmd
 #endif
@@ -40,7 +44,7 @@ __libc_fcntl64 (int fd, int cmd, ...)
   void *arg;
 
   va_start (ap, cmd);
-  arg = va_arg (ap, void *);
+  arg = FCNTL_VA_ARG (ap, void *);
   va_end (ap);
 
   cmd = FCNTL_ADJUST_CMD (cmd);
index 7c38e223990109bee0a62a30081b937da166cd8b..f21b56d95bf87cfff6290cfb00760eb98ed04b4f 100644 (file)
 # define __NR_fcntl64 __NR_fcntl
 #endif
 
+#ifndef FCNTL_VA_ARG
+# define FCNTL_VA_ARG(a, t) va_arg(a, t)
+#endif
+
 #ifndef FCNTL_ADJUST_CMD
 # define FCNTL_ADJUST_CMD(__cmd) __cmd
 #endif
@@ -37,7 +41,7 @@ __fcntl64_nocancel (int fd, int cmd, ...)
   void *arg;
 
   va_start (ap, cmd);
-  arg = va_arg (ap, void *);
+  arg = FCNTL_VA_ARG (ap, void *);
   va_end (ap);
 
   cmd = FCNTL_ADJUST_CMD (cmd);