From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 9F5593851524; Thu, 27 Oct 2022 13:53:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F5593851524 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666878807; bh=oUY+r9rk7kfXiOA0gdsdCebK31Phnb/WRmkFEI7DTMc=; h=From:To:Subject:Date:From; b=R7yvvXGuuBv2czNxRJrv4w5Kl5lMrFUBBlRnv/7zRpYxHtcy8snO5fxiQr8HOFodO rFC5oWke1cBysNQ8YToQmykcZbVLhrprJVotaySgxmd0t4Zt10kw/KNcFIAuM+THVc dB/VSaXvWv8x25na8PDqq5ShPMviHK6hR6WTK8Ds= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] aarch64: morello: fix missing variadic argument in fcntl X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: d79c61b3b98e52154c421891ecb3bfb417f5a66c X-Git-Newrev: ab9182522f8de407c2447239ddb1f12218f43a15 Message-Id: <20221027135327.9F5593851524@sourceware.org> Date: Thu, 27 Oct 2022 13:53:27 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ab9182522f8de407c2447239ddb1f12218f43a15 commit ab9182522f8de407c2447239ddb1f12218f43a15 Author: Szabolcs Nagy Date: Fri Jul 15 14:10:53 2022 +0100 aarch64: morello: fix missing variadic argument in fcntl 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. Diff: --- sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h | 2 ++ sysdeps/unix/sysv/linux/fcntl64.c | 6 +++++- sysdeps/unix/sysv/linux/fcntl_nocancel.c | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h index 5db89b096d..bad64a0674 100644 --- a/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h +++ b/sysdeps/unix/sysv/linux/aarch64/morello/sysdep.h @@ -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. */ diff --git a/sysdeps/unix/sysv/linux/fcntl64.c b/sysdeps/unix/sysv/linux/fcntl64.c index 5192b2d672..0b6afd3b59 100644 --- a/sysdeps/unix/sysv/linux/fcntl64.c +++ b/sysdeps/unix/sysv/linux/fcntl64.c @@ -29,6 +29,10 @@ # 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); diff --git a/sysdeps/unix/sysv/linux/fcntl_nocancel.c b/sysdeps/unix/sysv/linux/fcntl_nocancel.c index 7c38e22399..f21b56d95b 100644 --- a/sysdeps/unix/sysv/linux/fcntl_nocancel.c +++ b/sysdeps/unix/sysv/linux/fcntl_nocancel.c @@ -26,6 +26,10 @@ # 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);