From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by sourceware.org (Postfix) with ESMTPS id 106F43858D3C for ; Thu, 10 Nov 2022 12:27:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 106F43858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-13c569e5ff5so1966577fac.6 for ; Thu, 10 Nov 2022 04:27:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=05f3XcVO94q+djMMEyUxPJneEa/GW0vmj1zSCjwwkzk=; b=Mz4TL0rrf0eHN45PGuhLhm+M9Qm65NdXROwCwxTcwWyWXbMmMoDKmiyWFraIHADwaZ 4amtRVUTfmpiY58HmjSS1GhTj4Xz4AVN1TG78IRDLLugE2ue/27tmt5kSPV+xbycaAP0 qyH2/2dRuOxrlfc0JwxVen3EuWIVorCcGadWhz2jRE9mfHN0Y7RKzsFaVT63qoUBgxZv jjC0EJkEtf70dzNQb903sIoYMxsmyG7M7EN8+yIVqFOrhuJORwiMOKM3vd8qg+9Eu0wY aii3O7FpFkUk4OybxfJWvwgjED2sSIIaY2JpLmJxXn9CtZ4KbjuRPHfmOhXr4YBFcnM0 J+qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=05f3XcVO94q+djMMEyUxPJneEa/GW0vmj1zSCjwwkzk=; b=nmHucZb9o07TXZiLLLRXJ40/qttOyCFxd7XxVAt9Z6B3Zw4TU7TfsVHxUDNHbyQn/W fR/vI463Y7iuTDOW8Q5v5s7o8nve4UB3EBYJKSvoBdp0+xbasR9gKB07SA+2UG2fEBHh q8n7WLpaCCiMINIAHoE0JWrw8vRylPXY+twAdvHj20R7zfQ/h0Df1bGeeap4J8NOZL6x nuW67aLzNBCXP3P5Qt0d47dY23U2xTWNim+EwGMEu1ARVdh9eGFdIMJvXqEouORW41mZ 97djDrTxcimGzetNMyd4j6ZjYqgmqZYZDFsgWdR+JiU+rk5s7990GnAQsDaWfKAVzNhJ 2LrQ== X-Gm-Message-State: ACrzQf09RwWmYcwOX+w0HI+33X42w7w9F+H0ns3wkCF73pbhTW4pNFbp J/LMPgyZJ/zZEN8syJ/Wj9X93Q== X-Google-Smtp-Source: AMsMyM5fZk7VcUFHR2FKDTw3DxxGAH5Iy0hkMHfRutcKyXGhz4ynF1cPJ8QDiiSjZeDf6nP9TN/SXw== X-Received: by 2002:a05:6870:8c2b:b0:13a:bc43:2c53 with SMTP id ec43-20020a0568708c2b00b0013abc432c53mr1498522oab.77.1668083269108; Thu, 10 Nov 2022 04:27:49 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c1:1164:5982:d209:e8ed:b69a? ([2804:1b3:a7c1:1164:5982:d209:e8ed:b69a]) by smtp.gmail.com with ESMTPSA id m7-20020a056870058700b0013d6d924995sm7440956oap.19.2022.11.10.04.27.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Nov 2022 04:27:48 -0800 (PST) Message-ID: Date: Thu, 10 Nov 2022 09:27:45 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] Linux: Support __IPC_64 in sysvctl *ctl command arguments Content-Language: en-US To: Florian Weimer , libc-alpha@sourceware.org References: <87bkphij87.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <87bkphij87.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 08/11/22 12:00, Florian Weimer via Libc-alpha wrote: > Old applications pass __IPC_64 as part of the command argument because > old glibc did not check for unknown commands, and passed through the > arguments directly to the kernel, without adding __IPC_64. > Applications need to continue doing that for old glibc compatibility, > so this commit enables this approach in current glibc. > > For msgctl and shmctl, if no translation is required, make > direct system calls, as we did before the time64 changes. If > translation is required, mask __IPC_64 from the command argument. > > For semctl, the union-in-vararg argument handling means that > translation is needed on all architectures. > > Tested on i686-linux-gnu, powerpc64le-linux-gnu, x86_64-linux-gnu. > Built with build-many-glibcs.py. Sigh, another internal interface that bleed to userpace. The fix sounds reasonable to compatibility, just a typo below. Reviewed-by: Adhemerval Zanella > > --- > sysdeps/unix/sysv/linux/ipc_priv.h | 6 ++++++ > sysdeps/unix/sysv/linux/msgctl.c | 38 +++++++++++++++++++++++++------------- > sysdeps/unix/sysv/linux/semctl.c | 7 +++++++ > sysdeps/unix/sysv/linux/shmctl.c | 38 +++++++++++++++++++++++++------------- > 4 files changed, 63 insertions(+), 26 deletions(-) > > diff --git a/sysdeps/unix/sysv/linux/ipc_priv.h b/sysdeps/unix/sysv/linux/ipc_priv.h > index 87893a6757..2f50c31a8e 100644 > --- a/sysdeps/unix/sysv/linux/ipc_priv.h > +++ b/sysdeps/unix/sysv/linux/ipc_priv.h > @@ -63,4 +63,10 @@ struct __old_ipc_perm > # define __IPC_TIME64 0 > #endif > > +#if __IPC_TIME64 || defined __ASSUME_SYSVIPC_BROKEN_MODE_T > +# define IPC_CTL_NEED_TRANSLATION 1 > +#else > +# define IPC_CTL_NEED_TRANSLATION 0 > +#endif > + > #include > diff --git a/sysdeps/unix/sysv/linux/msgctl.c b/sysdeps/unix/sysv/linux/msgctl.c > index e824ebb095..67b43c0eff 100644 > --- a/sysdeps/unix/sysv/linux/msgctl.c > +++ b/sysdeps/unix/sysv/linux/msgctl.c > @@ -85,11 +85,19 @@ msgctl_syscall (int msqid, int cmd, msgctl_arg_t *buf) > int > __msgctl64 (int msqid, int cmd, struct __msqid64_ds *buf) > { > -#if __IPC_TIME64 > +#if IPC_CTL_NEED_TRANSLATION > +# if __IPC_TIME64 > struct kernel_msqid64_ds ksemid, *arg = NULL; > -#else > +# else > msgctl_arg_t *arg; > -#endif > +# endif > + > + /* Some applications pass the __IPC_64 flag in cmd, to invoke > + previously unsupported commands back when there was no EINVAL > + error checking in glibc. Mask the flag for the switch statements > + below. ,sgctl_syscall adds back the __IPC_64 flag for the actual s/,sgctl_syscall/msgctl_syscall > + system call. */ > + cmd &= ~__IPC_64; > > switch (cmd) > { > @@ -101,19 +109,19 @@ __msgctl64 (int msqid, int cmd, struct __msqid64_ds *buf) > case IPC_STAT: > case MSG_STAT: > case MSG_STAT_ANY: > -#if __IPC_TIME64 > +# if __IPC_TIME64 > if (buf != NULL) > { > msqid64_to_kmsqid64 (buf, &ksemid); > arg = &ksemid; > } > -# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > +# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > if (cmd == IPC_SET) > arg->msg_perm.mode *= 0x10000U; > -# endif > -#else > +# endif > +# else > arg = buf; > -#endif > +# endif > break; > > case IPC_INFO: > @@ -137,21 +145,25 @@ __msgctl64 (int msqid, int cmd, struct __msqid64_ds *buf) > case IPC_STAT: > case MSG_STAT: > case MSG_STAT_ANY: > -#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > +# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > arg->msg_perm.mode >>= 16; > -#else > +# else > /* Old Linux kernel versions might not clear the mode padding. */ > if (sizeof ((struct msqid_ds){0}.msg_perm.mode) > != sizeof (__kernel_mode_t)) > arg->msg_perm.mode &= 0xFFFF; > -#endif > +# endif > > -#if __IPC_TIME64 > +# if __IPC_TIME64 > kmsqid64_to_msqid64 (arg, buf); > -#endif > +# endif > } > > return ret; > + > +#else /* !IPC_CTL_NEED_TRANSLATION */ > + return msgctl_syscall (msqid, cmd, buf); > +#endif > } > #if __TIMESIZE != 64 > libc_hidden_def (__msgctl64) > diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c > index 77a8130c18..3458b018bc 100644 > --- a/sysdeps/unix/sysv/linux/semctl.c > +++ b/sysdeps/unix/sysv/linux/semctl.c > @@ -140,6 +140,13 @@ __semctl64 (int semid, int semnum, int cmd, ...) > union semun64 arg64 = { 0 }; > va_list ap; > > + /* Some applications pass the __IPC_64 flag in cmd, to invoke > + previously unsupported commands back when there was no EINVAL > + error checking in glibc. Mask the flag for the switch statements > + below. semctl_syscall adds back the __IPC_64 flag for the actual > + system call. */ > + cmd &= ~__IPC_64; > + > /* Get the argument only if required. */ > switch (cmd) > { > diff --git a/sysdeps/unix/sysv/linux/shmctl.c b/sysdeps/unix/sysv/linux/shmctl.c > index ea38935497..f00817a6f6 100644 > --- a/sysdeps/unix/sysv/linux/shmctl.c > +++ b/sysdeps/unix/sysv/linux/shmctl.c > @@ -85,11 +85,19 @@ shmctl_syscall (int shmid, int cmd, shmctl_arg_t *buf) > int > __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf) > { > -#if __IPC_TIME64 > +#if IPC_CTL_NEED_TRANSLATION > +# if __IPC_TIME64 > struct kernel_shmid64_ds kshmid, *arg = NULL; > -#else > +# else > shmctl_arg_t *arg; > -#endif > +# endif > + > + /* Some applications pass the __IPC_64 flag in cmd, to invoke > + previously unsupported commands back when there was no EINVAL > + error checking in glibc. Mask the flag for the switch statements > + below. shmctl_syscall adds back the __IPC_64 flag for the actual > + system call. */ > + cmd &= ~__IPC_64; > > switch (cmd) > { > @@ -103,19 +111,19 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf) > case IPC_STAT: > case SHM_STAT: > case SHM_STAT_ANY: > -#if __IPC_TIME64 > +# if __IPC_TIME64 > if (buf != NULL) > { > shmid64_to_kshmid64 (buf, &kshmid); > arg = &kshmid; > } > -# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > +# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > if (cmd == IPC_SET) > arg->shm_perm.mode *= 0x10000U; > -# endif > -#else > +# endif > +# else > arg = buf; > -#endif > +# endif > break; > > case IPC_INFO: > @@ -140,21 +148,25 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf) > case IPC_STAT: > case SHM_STAT: > case SHM_STAT_ANY: > -#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > +# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T > arg->shm_perm.mode >>= 16; > -#else > +# else > /* Old Linux kernel versions might not clear the mode padding. */ > if (sizeof ((struct shmid_ds){0}.shm_perm.mode) > != sizeof (__kernel_mode_t)) > arg->shm_perm.mode &= 0xFFFF; > -#endif > +# endif > > -#if __IPC_TIME64 > +# if __IPC_TIME64 > kshmid64_to_shmid64 (arg, buf); > -#endif > +# endif > } > > return ret; > + > +#else /* !IPC_CTL_NEED_TRANSLATION */ > + return shmctl_syscall (shmid, cmd, buf); > +#endif > } > #if __TIMESIZE != 64 > libc_hidden_def (__shmctl64) > > base-commit: 19934d629ee22bbd332f04da4320e4f624c9560c >