From patchwork Tue Oct 17 11:59:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 78010 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C52D43857732 for ; Tue, 17 Oct 2023 12:02:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 38772385734F for ; Tue, 17 Oct 2023 11:59:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38772385734F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 38772385734F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543990; cv=none; b=jTFh3G0PXPIiNbGsubyK+Q0eqZhxDpjf4L/6MVTomKXJgR7uwzidkio4N+cgus/Dg7tdBulO4BMi2c0CGb+ZOUe48HAiDiUFPGxEVeHJKAh1Su2o758zZd5wa6nBGruO1yhUU2Prz4zqH5ixweH1EfyUdMpGRoJqioyQwvE3BtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697543990; c=relaxed/simple; bh=xr9CoCmxmBORDzsO2A3pnkbrU5spyInZ/YmFuQtNZWY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Nr8JoP4XljM8RGKsM+9gxYdTB2CaErARdSyj8geph2OM6vBLesckwkpaywewaYmRMjGOw+GqiLy73iJvXaBFIZ1dHPh7PcnV+ygeNGlx5TZlLm+VAAlZmRkBxZNjtasbuvb0wL+2/kLTQK+nhNX5WyexrxfOn5v7GOIqyJEFaEo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697543987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NOG1tqiWFSHqtXLgIrrow4TJwznQiaM5nzmU0FleGyA=; b=aWiQIeCdJJDFF+lWrit/kh1uefi2L2ZvXOkfPwGbGX1rDbtj69bsht2jYmbfYGchdp1wj8 Nt+g73Dl4s4kolLBaSrYCmpAE/DHzh5cCjx0xjShLxMqYeZ7kaRAopB5cc1GKe11u5s2Nv K8QTfhF0aj5NnwZoUE9nvW1HAC89qaQ= Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-393-ckBAW67uOIS1hiTC67OqdQ-1; Tue, 17 Oct 2023 07:59:46 -0400 X-MC-Unique: ckBAW67uOIS1hiTC67OqdQ-1 Received: by mail-yb1-f198.google.com with SMTP id 3f1490d57ef6-d9a581346c4so7527889276.0 for ; Tue, 17 Oct 2023 04:59:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697543985; x=1698148785; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NOG1tqiWFSHqtXLgIrrow4TJwznQiaM5nzmU0FleGyA=; b=g+LGFsxUrdIGHyOWhVyywaVO5YIodwnFmX4QzoIZzwaorrm9YKBv/9RfmYPva3Bi1U Befovui1LAMxtw8SjT3pBIM0H5SsKZZcWnKOXGw2c+jEsR/LwG+un0HijbO9xgXCW+qm Slgs/XD+xctu6AfnIaKEmWJx01MoFuextfl/cWGLwqrVxW9scR5Edm9YQiHRDc43RlLh 1Ls4g6wwSmBf2G5iE9LVMH2IxrxETiP34IGvO4Fw8utIW/2Oq05JFj2odhzsqvfmxTYH NDfJFtz3A/00nORLbbBI5b/eH5/ZSRIK/ery4oOySkmFHrCDRVxW4vWj8xy8hIpKTBFv DDAA== X-Gm-Message-State: AOJu0YxcZrPp10wd2YlA31VqMrawQ2p9WTP+gHDxmWn/cC5ShKwv2SDJ 9utuM68tp8XMC46ciUvnF8eNsB7WS7PFhsDtQUknoEGsr+O5ERk3UvGuzsueGwTQkuLoHGUftys 1trqwifB5vYkbENbmWMEU/XfjESXkMuvR4ERQErcUXx0/o9E5wZbbLaZSeuhTu00Z+CbAh3XbYZ fIMtFk X-Received: by 2002:a25:40c:0:b0:d9a:4da4:b793 with SMTP id 12-20020a25040c000000b00d9a4da4b793mr1854575ybe.62.1697543985618; Tue, 17 Oct 2023 04:59:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMe0emhjqfcS//7X+NtQaJN4QTVbSz8HEaUGWd4hvMyKYnZ5ZRZRX4PaTHnmTjgKiLgBxY0Q== X-Received: by 2002:a25:40c:0:b0:d9a:4da4:b793 with SMTP id 12-20020a25040c000000b00d9a4da4b793mr1854553ybe.62.1697543985214; Tue, 17 Oct 2023 04:59:45 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id y18-20020ad457d2000000b0065afd35c762sm486587qvx.91.2023.10.17.04.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:59:44 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v3] posix: Deprecate group_member for Linux Date: Tue, 17 Oct 2023 07:59:39 -0400 Message-ID: <20231017115942.1425796-1-josimmon@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org The alloca usage in group_member could lead to stack overflow on Linux. Removing the alloca usage would require group_member to handle the error condition where memory could not be allocated and that cannot be done since group_member returns a boolean value. Thus deprecate group_member. Add a testcase. --- Changes to v2: * Move the linux group_member.h to the bits directory * Include the correct group_member.h in posix/unistd.h NEWS | 5 ++- bits/group_member.h | 31 ++++++++++++++++ posix/Makefile | 4 ++ posix/tst-group_member.c | 41 +++++++++++++++++++++ posix/unistd.h | 6 +-- sysdeps/unix/sysv/linux/bits/group_member.h | 32 ++++++++++++++++ 6 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 bits/group_member.h create mode 100644 posix/tst-group_member.c create mode 100644 sysdeps/unix/sysv/linux/bits/group_member.h diff --git a/NEWS b/NEWS index cc4b81f0ac..eadd8c5981 100644 --- a/NEWS +++ b/NEWS @@ -40,7 +40,10 @@ Major new features: Deprecated and removed features, and other changes affecting compatibility: - [Add deprecations, removals and changes affecting compatibility here] +* Deprecated group_member on Linux as it uses alloca to allocate a large + buffer and has no capability for indicating failure for other memory + allocations. + Changes to build and runtime requirements: diff --git a/bits/group_member.h b/bits/group_member.h new file mode 100644 index 0000000000..a8035c4ed7 --- /dev/null +++ b/bits/group_member.h @@ -0,0 +1,31 @@ +/* group_member declaration + Copyright (C) 2023 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 + . */ + +#ifndef _UNISTD_H +# error "Never use directly; include instead." +#endif + +#ifndef _GROUP_MEMBER_H +#define _GROUP_MEMBER_H 1 + +#ifdef __USE_GNU +/* Return nonzero iff the calling process is in group GID. */ +extern int group_member (__gid_t __gid) __THROW; +#endif + +#endif /* GROUP_MEMBER_H */ diff --git a/posix/Makefile b/posix/Makefile index c36b9d981e..d3e3c08fd1 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -29,6 +29,7 @@ headers := \ bits/getopt_core.h \ bits/getopt_ext.h \ bits/getopt_posix.h \ + bits/group_member.h \ bits/local_lim.h \ bits/mman_ext.h \ bits/posix1_lim.h \ @@ -294,6 +295,7 @@ tests := \ tst-glob_symlinks \ tst-gnuglob \ tst-gnuglob64 \ + tst-group_member \ tst-mmap \ tst-mmap-offset \ tst-nanosleep \ @@ -615,6 +617,8 @@ bug-glob1-ARGS = "$(objpfx)" tst-execvp3-ARGS = --test-dir=$(objpfx) CFLAGS-tst-spawn3.c += -DOBJPFX=\"$(objpfx)\" +CFLAGS-tst-group_member.c += -Wno-error=deprecated-declarations + # Test voluntarily overflows struct dirent CFLAGS-bug-glob2.c += $(no-fortify-source) diff --git a/posix/tst-group_member.c b/posix/tst-group_member.c new file mode 100644 index 0000000000..7f70841832 --- /dev/null +++ b/posix/tst-group_member.c @@ -0,0 +1,41 @@ +/* Basic tests for group_member. + Copyright (C) 2023 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 +#include +#include +#include + +#include + +static int do_test (void) +{ + int n; + gid_t *groups; + + n = getgroups (0, NULL); + groups = alloca (n * sizeof (*groups)); + n = getgroups (n, groups); + + while (n-- > 0) + TEST_COMPARE (1, group_member(groups[n])); + + return EXIT_SUCCESS; +} + +#include diff --git a/posix/unistd.h b/posix/unistd.h index 0477527a60..b65d4c63d0 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -710,10 +710,10 @@ extern __gid_t getegid (void) __THROW; of its supplementary groups in LIST and return the number written. */ extern int getgroups (int __size, __gid_t __list[]) __THROW __wur __fortified_attr_access (__write_only__, 2, 1); + #ifdef __USE_GNU -/* Return nonzero iff the calling process is in group GID. */ -extern int group_member (__gid_t __gid) __THROW; -#endif +# include +#endif /* Set the user ID of the calling process to UID. If the calling process is the super-user, set the real diff --git a/sysdeps/unix/sysv/linux/bits/group_member.h b/sysdeps/unix/sysv/linux/bits/group_member.h new file mode 100644 index 0000000000..8b47c1e379 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/group_member.h @@ -0,0 +1,32 @@ +/* group_member declaration + Copyright (C) 2023 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 + . */ + +#ifndef _UNISTD_H +# error "Never use directly; include instead." +#endif + +#ifndef _GROUP_MEMBER_H +#define _GROUP_MEMBER_H 1 + +#ifdef __USE_GNU +/* Return nonzero iff the calling process is in group GID. Deprecated */ +extern int group_member (__gid_t __gid) __THROW + __attribute_deprecated_msg__ ("may overflow the stack"); +#endif + +#endif /* GROUP_MEMBER_H */