From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 835673858C52 for ; Thu, 21 Sep 2023 16:21:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 835673858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695313263; 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=/FsFkoe5pNOsf6FG+FRcUKKeVQpjCtkJtkfSPvHVAl4=; b=FAnFRhLc130P9YlWWJSiqx5XHDFG3ITNcTEQmYQhKacwGmzemVT58Tjf5x8Z5e0dVtgShe 0hcsbLfNFqK+kzyjJk0nhZjDxQRWMEbrHmYm47nvtmKCuz1HWqdW7P3RDFwgLOkjmjN8CK Fx5SSo6RwYiwOkPA/Q3jGA6kDOfrSIY= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-173-OXr0DLn3PpmpL0WBMn4KcA-1; Thu, 21 Sep 2023 12:21:00 -0400 X-MC-Unique: OXr0DLn3PpmpL0WBMn4KcA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-774086da4dbso95104985a.0 for ; Thu, 21 Sep 2023 09:21:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695313259; x=1695918059; 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=/FsFkoe5pNOsf6FG+FRcUKKeVQpjCtkJtkfSPvHVAl4=; b=cDISIDN5bxIWfHP+rx18NUSW8RiIQ4CGFm4ga/r2oV0mgCPUn/wZ7EJ1eCK5KKxrbQ TU7TlC5AIa9+LP0Bn0X8cOw55cpKrs3c+2MCK4/ZRgqQ2o8KEkd2A6kpbmeXEqDVwtUs 11i527dHQiT5NSo+wQXIyBzySUDTLp+1dp5VqrQ7G+jgMcavliz22dx5dpynUQ9D8HTf IYTv2ZM27lAydEuYwF37Vg8koyfWeHFGp/b/93gfqPEo/RBAX2GdsTm54W9QOKLIWZz4 E6QYC9PBuHp1hRpxJtfNG/t2MOFuoxDbje9FrPYs1bkixiTsr+BGocHeX2iDw5hqqCBo N8hQ== X-Gm-Message-State: AOJu0YzKp9Qz27Lfm6z07e+6PhO6vHSJeP9Qm3kkS/FASPtL1ZksuUV7 qP6Yt32H1jRtM+yIhWE1qpAkt16Dmw2P7NK19oM844bwyw7UTFe4u4RemjnXdCiqtLyp2a+uyNe 7NPbuKZzkoQryzhw5xVnACZcvMkP31JPf/qfdBPHSuzPVFuVqbB92+ZPe17OZlmzYjwHXVEhjDL 0PmJkY X-Received: by 2002:a05:620a:1a94:b0:773:cea6:e5b9 with SMTP id bl20-20020a05620a1a9400b00773cea6e5b9mr6336534qkb.47.1695313259479; Thu, 21 Sep 2023 09:20:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEUUFMZt3HtMWPRrA7lwOEEEQJxZUkxPDSQIsuUGjbFJu6kcw5Lzqzc2Ab4ZZOfuZJupky/Q== X-Received: by 2002:a05:620a:1a94:b0:773:cea6:e5b9 with SMTP id bl20-20020a05620a1a9400b00773cea6e5b9mr6336515qkb.47.1695313259113; Thu, 21 Sep 2023 09:20:59 -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 oq36-20020a05620a612400b0076ef004f659sm721239qkn.1.2023.09.21.09.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 09:20:58 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] posix: Deprecate group_member for Linux Date: Thu, 21 Sep 2023 12:20:53 -0400 Message-ID: <20230921162057.3610289-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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. Thus deprecate group_member. Add a testcase. --- posix/Makefile | 3 ++ posix/group_member.h | 26 ++++++++++++++++ posix/tst-group_member.c | 41 ++++++++++++++++++++++++++ posix/unistd.h | 6 ++-- sysdeps/unix/sysv/linux/group_member.h | 27 +++++++++++++++++ 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 posix/group_member.h create mode 100644 posix/tst-group_member.c create mode 100644 sysdeps/unix/sysv/linux/group_member.h diff --git a/posix/Makefile b/posix/Makefile index 905cf9fb54..b7fffdd2fe 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -294,6 +294,7 @@ tests := \ tst-glob_symlinks \ tst-gnuglob \ tst-gnuglob64 \ + tst-group_member \ tst-mmap \ tst-mmap-offset \ tst-nanosleep \ @@ -615,6 +616,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/group_member.h b/posix/group_member.h new file mode 100644 index 0000000000..83d5220f2d --- /dev/null +++ b/posix/group_member.h @@ -0,0 +1,26 @@ +/* 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 _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/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..9b24569d4e --- /dev/null +++ b/sysdeps/unix/sysv/linux/group_member.h @@ -0,0 +1,27 @@ +/* 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 _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__; +#endif + +#endif /* GROUP_MEMBER_H */ -- 2.39.2