From patchwork Fri Oct 13 19:44:45 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: 77679 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 BCEC33857702 for ; Fri, 13 Oct 2023 19:45:36 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BCEC33857702 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=::1 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697226336; cv=none; b=BhtVkpIjAFoJvyByiWaSG9dbHzvWM/KS6gJks3ZcTripSJthLddKuwZQoGa1wJF2Qn/nLdSmy4bfQWGu8akMlXtYs7Q5tZGTYBHplg0M4R3dhck5e0gONELFZ2DMlqjXkmnDoLew9+JqEKHUbbQGK66uFq7Et7dYrvVi996Navw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697226336; c=relaxed/simple; bh=tdHO/xpM2UKaZRY6nQ2Mgq2Ik1E8XUfPk97PSnngNW0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ixdtKxZ8YafVpQHEPTCRFhkFVjSppuussm39g5umUL2qOPA6UTW18VkhKeB4i6ttS5D7gZqqFhmfpql/MtJUNoKylEH7a/LXUp71SEmiYcQKAcHNWPEfiITr4oqie9XGVTkea76cdaPy1kZH2UY3gqNnoCLOt6eA+zc3a1dYjgQ= ARC-Authentication-Results: i=2; server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 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 86BBB3857706 for ; Fri, 13 Oct 2023 19:45:12 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 86BBB3857706 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=1697226314; cv=none; b=pevBS4E+I4w33egBw9TY8L25mgMpAygNgJT5ZzMS87HccNQ6g16DvBEiYcrox2AUD3KsstnQo1z/BfYsXSSZCnkzGQn/Rf7ohariS/sYrFn95dm4HUhFt+D7j7JeykNTtHUyNv5s7IMRFcMd1JJH8n8mEl8ATC2SJIoaQEvfhSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697226314; c=relaxed/simple; bh=tdHO/xpM2UKaZRY6nQ2Mgq2Ik1E8XUfPk97PSnngNW0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NFfPy4FngpmOQeY+WaQVPuyNsl4JRTKZsQK08minf8rtXN9Ynb8278xnhxUPTEAovRp7or2Byqmy8CctzrtKZ5jKu3hmA0WH51VxBxMhDYeejP8D2UXy20HOz1iVUYWGTOqE2H7ygcIHRDHhKVz8deApetifJxG0vvcXF0Rz2/k= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86BBB3857706 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=1697226312; 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: in-reply-to:in-reply-to:references:references; bh=R543CotT9kpZNouTmpjCMY59oOm7K2nKRepHCwyROPc=; b=SI+KWFWMVWsuOtinUNrwaHV4Uw91LFdrYCSDvRLfTo7XQ7SK4IgAj0ygafRZs3JWJQfCjk RevizE8qYAzovORkWXvnVhg1WYfN1/TsKGx310SuFYYHFfSn2NsLdX6qiJCqPCBTKun28p CZNv4h8tqgjlvHkzeKyUxKvopBFxgvo= 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-623-AFB8i-qIOPulpjxgN1JGew-1; Fri, 13 Oct 2023 15:45:01 -0400 X-MC-Unique: AFB8i-qIOPulpjxgN1JGew-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4196a386347so26495451cf.1 for ; Fri, 13 Oct 2023 12:45:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697226300; x=1697831100; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R543CotT9kpZNouTmpjCMY59oOm7K2nKRepHCwyROPc=; b=cSvmBG5yHosUUCQcl9n/E4KOTy96XQgbUHD+QaWY0dUh5b0Z5RbkMOol1G3HJkBCfz iWQ5TQM9VD6FxiJGKpT4QWaZSCdbhHvIH14/SoyehCjU/i30kopuivAJ/JLT3mgY7Ju+ dlXAD6n3FQLQWz1+n4jMd5cUrKKrlzHsIE05HW6pr9sJSeplxYtdSSYSLMBioaW4zqzE VAiKaMs4F2RhEHwToDs8rdeGndjGpTZN1vQ4lHQOlVQV4Mxx0EaoFCD88/P+SIkToPwE GSySBLlEQeEU5PiN2yTg/im6tpIN7hXQlTGpulW75ueVwU1xGpxL+pCVcy4iAMxlTw/K TBCg== X-Gm-Message-State: AOJu0YzvbcYPWZWzEbaLXnJRs+a6hwrDzOZmoRXzATSv6m4k+o3cjDPM qCPR0IBA5lDe2oIHNg8+h9BGfqlz4DxuqTyeZFcLxfRn0dzXKpUcmxzLBQyLJwHw9jZH60FbsgC 9SLPK8g0qpRhcwA74cMQ8DI1FFQ9jjQcIqW2G6eYQfrvrQzd8OGQjVb6psTFJm3pOO03vn8bKWa doLWGp X-Received: by 2002:ac8:5990:0:b0:417:eb3c:494e with SMTP id e16-20020ac85990000000b00417eb3c494emr28117963qte.59.1697226299929; Fri, 13 Oct 2023 12:44:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbl1EeiJpYqpwoOeKslx6fYPBK3QE2byH6Ku501Uate04RZm6LFrfJwA+inJBlmFHtOXRfRw== X-Received: by 2002:ac8:5990:0:b0:417:eb3c:494e with SMTP id e16-20020ac85990000000b00417eb3c494emr28117942qte.59.1697226299422; Fri, 13 Oct 2023 12:44: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 kc6-20020a05622a44c600b004109928c607sm843824qtb.43.2023.10.13.12.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 12:44:59 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v3 2/2] posix: Deprecate group_member for Linux Date: Fri, 13 Oct 2023 15:44:45 -0400 Message-ID: <20231013194452.2165882-3-josimmon@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013194452.2165882-1-josimmon@redhat.com> References: <20231013194452.2165882-1-josimmon@redhat.com> 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 either 1 or 0 for found or not found respectively. Thus deprecate group_member. Add a testcase. --- Changes since v2: * Add summary to both group_member.h files * Move group_member.h to bits/group_member.h and ensure it can only be included from unistd.h NEWS | 4 ++- bits/group_member.h | 35 ++++++++++++++++++++++ posix/Makefile | 4 +++ posix/tst-group_member.c | 41 ++++++++++++++++++++++++++ posix/unistd.h | 9 ++---- sysdeps/unix/sysv/linux/group_member.h | 36 ++++++++++++++++++++++ 6 files changed, 122 insertions(+), 7 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 c15b0dd0f9..0cfaf9c80a 100644 --- a/NEWS +++ b/NEWS @@ -43,7 +43,9 @@ 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..a0e60da5f6 --- /dev/null +++ b/bits/group_member.h @@ -0,0 +1,35 @@ +/* group_member and group_member2 declarations + + 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; +/* Return nonzero iff the calling process is in group GID. Return + -1 on error and set errno. */ +extern int group_member2 (__gid_t __gid) __THROW; +#endif + +#endif /* GROUP_MEMBER_H */ diff --git a/posix/Makefile b/posix/Makefile index b46ff3259c..13fd2843a3 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-group_member2 \ tst-mmap \ tst-mmap-offset \ @@ -616,6 +618,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 96816b186d..b65d4c63d0 100644 --- a/posix/unistd.h +++ b/posix/unistd.h @@ -710,13 +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; -/* Return nonzero iff the calling process is in group GID. Return - -1 on error and set errno. */ -extern int group_member2 (__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..7d6858e069 --- /dev/null +++ b/sysdeps/unix/sysv/linux/group_member.h @@ -0,0 +1,36 @@ +/* group_member and group_member2 declarations + + 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"); +/* Return nonzero iff the calling process is in group GID. Return + -1 on error and set errno. */ +extern int group_member2 (__gid_t __gid) __THROW; +#endif + +#endif /* GROUP_MEMBER_H */