From patchwork Tue Mar 3 19:27:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 184148 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp4022239ile; Tue, 3 Mar 2020 11:27:43 -0800 (PST) X-Google-Smtp-Source: ADFU+vtyH51tfi6puaRl0IqdFeRelar+tBtsAZauPIpHy2poUuVPOzvTSa05dsatGZbgOASwIJFg X-Received: by 2002:aca:f405:: with SMTP id s5mr64082oih.93.1583263663907; Tue, 03 Mar 2020 11:27:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583263663; cv=none; d=google.com; s=arc-20160816; b=1BGn0a4XlwKhkEGFdFwbtBUTzoL8rHD32zkPmU9EFa8hm1+27J3hL+CESCzNBBXOEu GN4CjTrmrVCgCfjD029B119oncMONb3NlBkD6t4Kdmc1RsNGUJgRKylRCKRmMBowXcT7 SX/iZTBF6Tt4ffayMk+kyLmnVHNnMMoeE3icYGxJ5844MORealbzv8R13aMZ71rTwFUH UNENDpOBJrjL4u7gH+4lHkkiXoE096qdlmx9DejmxgVAoz1wEo3LosWOPj6sQqRW2CSB vLtGwr/ALJ2aLXMuAG/eb3qBOYug/qPQ6YuVH118PXnfkQ64+mCKnDljM+BGf/j2aOj+ LAMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature; bh=wHPIW3k4LSuZoH/VFSzg9lmzvUKrzKtZvi9uhDx5HPk=; b=wxQ5G8WL7Qf9BVMiz0m/x8tTqz6IhmFCRdJPnwBcmo1RXtocfTvqmqD8Q+Fnum9wZ6 BZZ7qrv4jM8NLh84DaGal+yLqBvmle+JhW4JpBbx61GJq6AffJlKoJMfwmMDzK8MypVv x9UMdggzp8zvRRajPjjbBpJXOlYP2wpHgOBjL6JgFP+Thqcjo2E1IndwGkb3eO+ZIvGU MzJOMnLgw0ct/baZfcXgS1ZZufLGGDqBtoBd6y25uh8G9mnyjM1U3d/xffgM8Blbd+Aj 27CIWgzdDK6I4H93vT1IqGsGmkjgz1BGNffmJ2wuDvcAe6VL+ETYFnVcnQdySgm4SalL H1JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=nfwIxz3H; dkim=pass header.i=@linaro.org header.s=google header.b=fq1c+xyC; spf=pass (google.com: domain of libc-alpha-return-110240-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-110240-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 22si2680597oij.227.2020.03.03.11.27.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Mar 2020 11:27:43 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-110240-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=nfwIxz3H; dkim=pass header.i=@linaro.org header.s=google header.b=fq1c+xyC; spf=pass (google.com: domain of libc-alpha-return-110240-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-110240-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=vult+rByPTSfeyfJ5lSnF1sAZWvZLYVjoa1zCDv5LmuAZrek0Tae9 q9vc4JzGcUP6MQ7JEPqJlKyShjjUQ5XrxF9VxEm2l6EciafcZOIC50O270AJB08+ SKcmwTaPdPNLENCPXzcKdq2fS04hOjWroOiPuuJ1i5KPgv0ky+gcKM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=uxwNNCM4sEdqzTfY2fyjYbu8A6I=; b=nfwIxz3HliqGXduKmUwLQXCqdvp0 rMwXTtkKPQRGq9HJRxye9OT+jtibORcrPw8CI0YBXsKEe67KAoRel41vRImZ2+Cz Nf2IZnTKRDXJ8QezHlQ5om7owqAtwcXD0tfJUybDA5UKwgUzDv0hz+MPut1c8VuU hgtTNP0nZ5+8nEE= Received: (qmail 127950 invoked by alias); 3 Mar 2020 19:27:34 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 127920 invoked by uid 89); 3 Mar 2020 19:27:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qt1-f196.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=wHPIW3k4LSuZoH/VFSzg9lmzvUKrzKtZvi9uhDx5HPk=; b=fq1c+xyCXPyruaAGKIrYFY9bjdatJy34eiUOvXnaIptEAsfTODKNT3N8x5SfJma68N KiSt7at7QO9oO0R2FG0uayAdbB/qjA7TkWynx9wZJa/k/P6khAsHaQnDfViygY4VHCTw zLn7/CKmI776ugVdXT0xVwp5TUbCJPNj1L7O6MwQ6JZxF6QOVlsNLmtAmKVXXM9shDIW I8FZfy2GQSyUnNHjoa/E5WMzQp6s/i53M+7hGByqY3Xpj8G7ewe0tJYlOeuf52x4dEnt fQNe4RWx6/WvyKzhbb3o7RguuSd07dBcm/K/5um3Bxgp5XbdFdJlWwVLmHC4DvwovsbP J11A== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] linux: Clear mode_t padding bits (BZ#25623) Date: Tue, 3 Mar 2020 16:27:25 -0300 Message-Id: <20200303192725.16847-1-adhemerval.zanella@linaro.org> The kernel might not clear the padding value for the ipc_perm mode fields in compat mode (32 bit running on a 64 bit kernel). It was fixed on v4.14 when the ipc compat code was refactored to move (commits 553f770ef71b, 469391684626, c0ebccb6fa1e). Although it is most likely a kernel issue, it was shown only due BZ#18231 fix which made all the SysVIPC mode_t 32-bit regardless of the kABI. This patch fixes it by explicit zeroing the upper bits for such cases. The __ASSUME_SYSVIPC_BROKEN_MODE_T case already handles it with the shift. (The aarch64 ipc_priv.h is superflous since __ASSUME_SYSVIPC_DEFAULT_IPC_64 is now defined as default). Checked on i686-linux-gnu on 3.10 and on 4.15 kernel. --- sysdeps/unix/sysv/linux/aarch64/ipc_priv.h | 21 --------------------- sysdeps/unix/sysv/linux/msgctl.c | 9 +++++++-- sysdeps/unix/sysv/linux/semctl.c | 9 +++++++-- sysdeps/unix/sysv/linux/shmctl.c | 9 +++++++-- 4 files changed, 21 insertions(+), 27 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/aarch64/ipc_priv.h -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/aarch64/ipc_priv.h b/sysdeps/unix/sysv/linux/aarch64/ipc_priv.h deleted file mode 100644 index 07a1c3a7d3..0000000000 --- a/sysdeps/unix/sysv/linux/aarch64/ipc_priv.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Old SysV permission definition for Linux. AArch64 version. - Copyright (C) 2016-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include /* For __key_t */ - -#define __IPC_64 0x0 diff --git a/sysdeps/unix/sysv/linux/msgctl.c b/sysdeps/unix/sysv/linux/msgctl.c index 27879e76cd..48801a3fba 100644 --- a/sysdeps/unix/sysv/linux/msgctl.c +++ b/sysdeps/unix/sysv/linux/msgctl.c @@ -61,7 +61,6 @@ __new_msgctl (int msqid, int cmd, struct msqid_ds *buf) int ret = msgctl_syscall (msqid, cmd, buf); -#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T if (ret >= 0) { switch (cmd) @@ -69,10 +68,16 @@ __new_msgctl (int msqid, int cmd, struct msqid_ds *buf) case IPC_STAT: case MSG_STAT: case MSG_STAT_ANY: +#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T buf->msg_perm.mode >>= 16; +#else + /* Old Linux kernel versions might not clear the mode padding. */ + if (sizeof ((struct msqid_ds){0}.msg_perm.mode + != sizeof ((struct __old_ipc_perm){0}.mode))) + buf->msg_perm.mode &= 0xFFFF; +#endif } } -#endif return ret; } diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c index 0c3eb0932f..580a72febe 100644 --- a/sysdeps/unix/sysv/linux/semctl.c +++ b/sysdeps/unix/sysv/linux/semctl.c @@ -92,7 +92,6 @@ __new_semctl (int semid, int semnum, int cmd, ...) int ret = semctl_syscall (semid, semnum, cmd, arg); -#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T if (ret >= 0) { switch (cmd) @@ -100,10 +99,16 @@ __new_semctl (int semid, int semnum, int cmd, ...) case IPC_STAT: case SEM_STAT: case SEM_STAT_ANY: +#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T arg.buf->sem_perm.mode >>= 16; +#else + /* Old Linux kernel versions might not clear the mode padding. */ + if (sizeof ((struct semid_ds){0}.sem_perm.mode + != sizeof ((struct __old_ipc_perm){0}.mode))) + arg.buf->sem_perm.mode &= 0xFFFF; +#endif } } -#endif return ret; } diff --git a/sysdeps/unix/sysv/linux/shmctl.c b/sysdeps/unix/sysv/linux/shmctl.c index 39fa861e17..9a44ad6920 100644 --- a/sysdeps/unix/sysv/linux/shmctl.c +++ b/sysdeps/unix/sysv/linux/shmctl.c @@ -63,7 +63,6 @@ __new_shmctl (int shmid, int cmd, struct shmid_ds *buf) int ret = shmctl_syscall (shmid, cmd, buf); -#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T if (ret >= 0) { switch (cmd) @@ -71,10 +70,16 @@ __new_shmctl (int shmid, int cmd, struct shmid_ds *buf) case IPC_STAT: case SHM_STAT: case SHM_STAT_ANY: +#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T buf->shm_perm.mode >>= 16; +#else + /* Old Linux kernel versions might not clear the mode padding. */ + if (sizeof ((struct shmid_ds){0}.shm_perm.mode) + != sizeof ((struct __old_ipc_perm){0}.mode)) + buf->shm_perm.mode &= 0xFFFF; +#endif } } -#endif return ret; }