From patchwork Mon Oct 16 17:54:32 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: 77893 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 693C63857715 for ; Mon, 16 Oct 2023 17:55:17 +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 010D63858C3A for ; Mon, 16 Oct 2023 17:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 010D63858C3A 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 010D63858C3A 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=1697478904; cv=none; b=rul7qPiQN7sbh61bwlhUhHwed6vAk6zJKgXtTye+4HcjEKPv8hzV0u0omqIq/pLqVNWuCfPHGvbUrqmO7pmrHEmeNdj2VOeXImY1iCmUJZTlM3/9oBxiDk/7XuGyHyC9w1x4DvW9aDuLQJS2+HMGZvnzPeffISo7KmzHYOMJSNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697478904; c=relaxed/simple; bh=UMcdQnBgMSOhAfp7NcBoTYCCePf5amwNI4X3HJEMfGc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cVq+sidaDZXZZOabeFjOYVHW216NghiS8mVSP/FkO0zGlGE485y4/HuecS1vwEXp/1MZ/Tqu0DNJjojmTGTjiffwkunV/hC/4euKrQrO2rOlMAcNroYnjA0TtDm26q2SY/FwrdTtKt6qwDb3UimSUqWAImVgoPi+jyHBAWPNkgU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697478901; 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=XEKFSLmT7+jCTWnBHknaQXObAz/4AZ3dCXEYY3CexG0=; b=dvamIb46IVW5kh/3pS8h67ZAlf2BS2+ySkUyPQ1rbPtjudOjWagbN1MLLHyrbndo8gfx+q ClxSHPahO6Pi0uvl5FvtIge+8Oxvj6a5glFCPNBr9ADdZcYN9Nb+rMwGKpFkDNKb0/UF+u YulFp0CNowoSk95o/2kKVVbEth8KBAA= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-JutVczpdOGW8V4aCTX2U2w-1; Mon, 16 Oct 2023 13:54:40 -0400 X-MC-Unique: JutVczpdOGW8V4aCTX2U2w-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-41810af14a4so57104241cf.0 for ; Mon, 16 Oct 2023 10:54:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697478879; x=1698083679; 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=XEKFSLmT7+jCTWnBHknaQXObAz/4AZ3dCXEYY3CexG0=; b=hsMkyvSCJIRPwsvwq2cIWt6c8f2lXXP66xYbOyAlqWrSYsSnUBGFBx02W/AnMJuuVs a8NFkfIUGWNy4p6KbLvRgdoThxgsoUFsKe3BZnKQoRFtALJ3y/5hkWJUfSgzHVw1UQZ/ PmJ0uU+p0HUWYmVAJg8VA+NKFz5GpVLz3JM4LtTYeGuDPfBu0hERB3siL1hXLsznIqHe XI6yhPi/Dy3haD2d/NWZrtvWJAxDLaC4cn7sRjLqrhN2+PaTd86imFCWbrGiB3Ej5CUP kFwX2rBMuol19cEZ1G6ikuvtZlmgqCpjaBuSVmDM9N8pCMDpnTh7G+gE7qmEzRkJOgvC 35iQ== X-Gm-Message-State: AOJu0YxEpgrn0V5gr2kBztHCYldY4jH199A43QGHPdc7Nr7Di65nJWXQ ym1Y/MhB0G8kwVqqLfO198L/Jr1KUDzI1FrG8bcfzVndwfNFX/EhS0oXdsmJBX08kTbDXNGArjc UEfjT7cDgvvI7mEfvUi5+NknUZBkK9XnXWEWBcplSUHNxNK2qMxxLbfQ673pmUfDQWMncjCpsrv hS+Wc2 X-Received: by 2002:ac8:5a42:0:b0:417:bb09:ebb0 with SMTP id o2-20020ac85a42000000b00417bb09ebb0mr66660qta.17.1697478879347; Mon, 16 Oct 2023 10:54:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcrG/Q3wF2COXKZJq2mgXk+ejfc72n62xoWF4lhyQmvarKQfaoOVFflS1Kwrw5DFPdV5GK5g== X-Received: by 2002:ac8:5a42:0:b0:417:bb09:ebb0 with SMTP id o2-20020ac85a42000000b00417bb09ebb0mr66635qta.17.1697478878897; Mon, 16 Oct 2023 10:54:38 -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 v21-20020ac87295000000b0040331f93ee0sm3202652qto.77.2023.10.16.10.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 10:54:38 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v2] posix: Deprecate group_member for Linux Date: Mon, 16 Oct 2023 13:54:32 -0400 Message-ID: <20231016175436.3774330-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+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 v1: * Add NEWS entry * Move group_member.h to bits/group_member.h * Include bits/group_member.h in installed headers * Add tests to group_member.h files to only be included from 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/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/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..d73a9eeea2 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/group_member.h b/sysdeps/unix/sysv/linux/group_member.h new file mode 100644 index 0000000000..8b47c1e379 --- /dev/null +++ b/sysdeps/unix/sysv/linux/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 */