From patchwork Fri Oct 20 17:42:31 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: 1852731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MZ5J8kbP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SBsPB19Nvz23jM for ; Sat, 21 Oct 2023 04:42:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FC203858412 for ; Fri, 20 Oct 2023 17:42:52 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 221303858D35 for ; Fri, 20 Oct 2023 17:42:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 221303858D35 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 221303858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697823763; cv=none; b=Tw1jx1aXjaLdjmWQDCoMkevx5vTvg/0efV6Ms5gW57AvDlEG88sNAvDFeH8lEyz95t+Jnp15jOK93MjRuUGlG92bnPxmyFV5cl9/N4BU4inGrg3CRJerulHvrFyl1kM3E3hDShcAMYLnQBzIRvfOm9NZRSb7EgPQs+0hzNTITQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697823763; c=relaxed/simple; bh=VW4aPIJxAcgiU1pGzyjK1aCbFi+rVdSsDMJQENn73WM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KY4RFlDS8xRWxw0jHRcVSCAuCiLiXJG9qyT3p5uRXXk8qgms3aslxtZq8QozzdhYPxSjgFmkoXoPp+rGUqFykZ6OdUxc1KzKgPzdb1A7ep66w7f6FR7E9K8MUwSM7LB2c+1jLEyP2jDYda1iTpa4jQ2AJxY4XYDrf4WDb47R0XA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697823761; 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=MiDMk8YDWstmesAuVVps5ERL970vscPQS61YdoanXCo=; b=MZ5J8kbPF6Cbrlk/zp9mviEMcdG9ZEIlLx/yK3tHOsV/s221prpFsQzkFXHcmkQnwLfKhH hfCaMGSRtlrD8QGKpDkGtWJwy+PBM+UwrGB9eKctZy4poNOzyS2ocrufIx88dNvh92GGuQ Sg31bCfrWpDpzwahkhIfdc4WV+1gd64= Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-6dm3xErjOmmXS_b01A8PPA-1; Fri, 20 Oct 2023 13:42:40 -0400 X-MC-Unique: 6dm3xErjOmmXS_b01A8PPA-1 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-3b2df828525so1870698b6e.3 for ; Fri, 20 Oct 2023 10:42:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697823760; x=1698428560; 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=MiDMk8YDWstmesAuVVps5ERL970vscPQS61YdoanXCo=; b=qeHEaqhzf+eildDhPWJ1rUGa/76hyqOwHIHE480DEhXu8WHblZwITcurAbPiXZXerq 2QMukQfXv6zFwJxTRbrRyZCPW3RDB6SYFjcmbMXwRkwuMCCngSm6sPOe+vmJUf6UUIIL U5bmI9m6oruAFMgejqcuzR3XpzF7HUJcEIX+PDqOC3xr4yOt5KtBPAGcumBPMDUAa9Tb s2tZ1Py44qxRVOg8uGB+vuSqh/ko+LBjcgCXrFuQW5iSfs8W+jEmB8oIkdJM+G+4JNsc PFwRRRG1r2cW2MlXN3Hbs920WaLTGPpAZxLEvYb6FW+r3LsY5ZpKJy+v0N7quOF1697y Du+A== X-Gm-Message-State: AOJu0YwBXrP8C+PsyrNZTQ8lCp85UMLtL8BNjRkyymB/rKNZ8yLbbsPN dcPRV6QIn12uwkbROoKnWJ8/8ws7PQsc4BpkCfxk8Fb245pMH7JztGnybjRcsxly/a5+4CKTxhO ma1tO+t18T6bHdtKV8bVfwOF4hcumhb01N/DMXuRT1qs2Ej11HrFY0H33vsTzF9b9wq8tGtIUyx x4AirW X-Received: by 2002:a05:6808:ca:b0:3a8:b056:c3a2 with SMTP id t10-20020a05680800ca00b003a8b056c3a2mr2786025oic.47.1697823759472; Fri, 20 Oct 2023 10:42:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOhrhM58i2dbBLEQHyeXl/tzBUrMu1ddf3fNpdot8aJm0KVrRbOcv4U1kbAZ5ah2ELSil9KQ== X-Received: by 2002:a05:6808:ca:b0:3a8:b056:c3a2 with SMTP id t10-20020a05680800ca00b003a8b056c3a2mr2786009oic.47.1697823759028; Fri, 20 Oct 2023 10:42:39 -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 d23-20020ac85357000000b0041812703b7esm756779qto.52.2023.10.20.10.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:42:38 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v5] posix: Deprecate group_member for Linux Date: Fri, 20 Oct 2023 13:42:31 -0400 Message-ID: <20231020174235.1244927-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_H3, 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+incoming=patchwork.ozlabs.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 v4: * Rebase onto latest commit. NEWS | 4 ++ 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(+), 3 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 9432564444..c1f9e5d0cc 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,10 @@ Deprecated and removed features, and other changes affecting compatibility: ".tmp", to avoid examining temporary files created by the RPM and dpkg package managers. +* 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: * Building on LoongArch requires at a minimum binutils 2.41 for vector diff --git a/bits/group_member.h b/bits/group_member.h new file mode 100644 index 0000000000..7c43e7ee06 --- /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 _BITS_GROUP_MEMBER_H +# define _BITS_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 /* _BITS_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..0dd9505c76 --- /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 _BITS_GROUP_MEMBER_H +# define _BITS_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 /* _BITS_GROUP_MEMBER_H */