From patchwork Tue Oct 17 14:05:14 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: 78036 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 583C23858430 for ; Tue, 17 Oct 2023 14:06:42 +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 21173385841D for ; Tue, 17 Oct 2023 14:06:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 21173385841D 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 21173385841D 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=1697551589; cv=none; b=EqnouVELLvT3pVq+ZpxqCF2JQvD/HduoWF5l3cnxvymAjKQom9fXnnaSSLVrzACZ7oIFdzWxERe6F2IXq0rUVRcPGbYXYnOvkIoK7LpLWRegT7EdcrxIS95yrv6AObkgOUiwaTb4C9+KmZsBCzNL2VDMCnkHhjc+17h4lhPuqbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697551589; c=relaxed/simple; bh=Fvnjzi9ipx8B2/W3RTYrv+bZYsjIBYthkOt7r1qQjxQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sSf/8vYn8QFLZkjF7n3PlgvlmiyiGzcjgQCDSXpuAf6pWBMnVgMNlWlcWHc4iQU+z5hn3XzjNg4ARr0/KmnU0xj66hooQGOXM/toNp4qXWzC/d+wO4mAHvgg7xksYG88lzOc0WzGoVV3oSOFTYDgXmGSOEf7gjD4GywxnyZK/Vc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697551586; 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=HGn4COjWilGUd9JP5CSQ7AxzE5kUtNKhwl2TdIFKreI=; b=W2BQvyf9QOIrnz1pmwvAylgRen953vL5U8cDxiq/AP2UGAP5aGsYMVLx9tqm2O33utnVcV HxRWR377LHV8flK40nnzz2t021Ay3XEAUc2M56kkRyvRAt0pkCjVToSlWsx+jzQLaT3Avx b1RTcsssRG+BGTPRzSBlwgZVrRh63xU= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-nYxKaCSmN3Clfd8KaAYh9w-1; Tue, 17 Oct 2023 10:06:25 -0400 X-MC-Unique: nYxKaCSmN3Clfd8KaAYh9w-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-5a7e4745acdso88706857b3.3 for ; Tue, 17 Oct 2023 07:06:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697551584; x=1698156384; 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=HGn4COjWilGUd9JP5CSQ7AxzE5kUtNKhwl2TdIFKreI=; b=fa9bO4xwcxK7S7c/WZH+9Qq5PlZwdiOGhLNrut+GOqDrfN7qkvpUIeftSYbamNwNRv 3JCtow5lojfJ1Tw14DYLrOLDVvAk9pfXR7SvlhyH3+gAtoEsWxjNjxJm7479ONMhHqvI gK2GXK0llNMnFoeV2qs2mFphIpP4ODEGj0hEfdoZ2bhtWIO5akTCKLeBuEqmcFNKEfud umlCQObncFDKBzZYSD2uDTlbV7u4R6NjCosjXVNxyby6ruueYRvbaE0WYkp9FTnW+zxD zi0xMUaDPnTahuDWyeB+PqhH0GU2a0XgZDpDo4tLDwE0ELsYR2HBSoHuup4w4+VGAxqd tzvg== X-Gm-Message-State: AOJu0YyFHAepdCZy89Ak6o4Nd3sVHcm97LSvTTGd+obLmxuRL/PXQ4Un TWAsBZIyiOpS05nPSL83I1IfXLxAptc9nP6Ck7Smq1EG2YeGDEdMUFvnxcqIT7xJKmpQ6ux5ALS WaKAXUFjt0zFZqLSceV8WdF6rVavFf9t4EEKOxRy4fmsYxZUY0zSXKcptcRgR0a14rFXqtfcT4B IVJRhD X-Received: by 2002:a81:6c88:0:b0:59f:761a:fe70 with SMTP id h130-20020a816c88000000b0059f761afe70mr2500807ywc.19.1697551584434; Tue, 17 Oct 2023 07:06:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUruh0bs0fXXN8sPDMvEvajVooqfc8HSwxDUyKutYq9ozUerTdG+4bcdTgpEIhXb3uJY/mmQ== X-Received: by 2002:a81:6c88:0:b0:59f:761a:fe70 with SMTP id h130-20020a816c88000000b0059f761afe70mr2500755ywc.19.1697551583843; Tue, 17 Oct 2023 07:06:23 -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 u73-20020a81844c000000b0059b085c4051sm631875ywf.85.2023.10.17.07.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 07:06:23 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v4] posix: Deprecate group_member for Linux Date: Tue, 17 Oct 2023 10:05:14 -0400 Message-ID: <20231017140621.759909-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 v3: * Fix include guards to match file location _BITS_GROUP_MEMBER_H * Fix indentation of preprocessor directives 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..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 */