[v2,2/2] posix: Deprecate group_member for Linux
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Testing passed
|
Commit Message
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 to v1:
* Add NEWS entry
NEWS | 4 ++-
posix/Makefile | 3 ++
posix/group_member.h | 29 ++++++++++++++++++
posix/tst-group_member.c | 41 ++++++++++++++++++++++++++
posix/unistd.h | 9 ++----
sysdeps/unix/sysv/linux/group_member.h | 30 +++++++++++++++++++
6 files changed, 109 insertions(+), 7 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
Comments
On Fri, 13 Oct 2023, Joe Simmons-Talbott wrote:
> 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.
I still don't expect this version to work with installed libc because it
doesn't add the new header to the headers list in posix/Makefile so it
won't be installed. And having a new installed header that's not in bits/
needs proper justification, which isn't provided in this commit message
(indeed seems completely unrelated to the commit summary).
> diff --git a/sysdeps/unix/sysv/linux/group_member.h b/sysdeps/unix/sysv/linux/group_member.h
> new file mode 100644
> index 0000000000..967b52df1b
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/group_member.h
> @@ -0,0 +1,30 @@
> +/* Copyright (C) 2023 Free Software Foundation, Inc.
New files should have a summary description on their first line, before
the copyright notice.
On Fri, Oct 13, 2023 at 03:53:35PM +0000, Joseph Myers wrote:
> On Fri, 13 Oct 2023, Joe Simmons-Talbott wrote:
>
> > 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.
>
> I still don't expect this version to work with installed libc because it
> doesn't add the new header to the headers list in posix/Makefile so it
> won't be installed. And having a new installed header that's not in bits/
> needs proper justification, which isn't provided in this commit message
> (indeed seems completely unrelated to the commit summary).
>
> > diff --git a/sysdeps/unix/sysv/linux/group_member.h b/sysdeps/unix/sysv/linux/group_member.h
> > new file mode 100644
> > index 0000000000..967b52df1b
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/group_member.h
> > @@ -0,0 +1,30 @@
> > +/* Copyright (C) 2023 Free Software Foundation, Inc.
>
> New files should have a summary description on their first line, before
> the copyright notice.
Thanks for the review. I've posted a v3 with these changes.
Thanks,
Joe
@@ -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:
@@ -294,6 +294,7 @@ tests := \
tst-glob_symlinks \
tst-gnuglob \
tst-gnuglob64 \
+ tst-group_member \
tst-group_member2 \
tst-mmap \
tst-mmap-offset \
@@ -616,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)
new file mode 100644
@@ -0,0 +1,29 @@
+/* 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
+ <https://www.gnu.org/licenses/>. */
+
+#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 */
new file mode 100644
@@ -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
+ <https://www.gnu.org/licenses/>. */
+
+#include <alloca.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+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 <support/test-driver.c>
@@ -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 <group_member.h>
+#endif
/* Set the user ID of the calling process to UID.
If the calling process is the super-user, set the real
new file mode 100644
@@ -0,0 +1,30 @@
+/* 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
+ <https://www.gnu.org/licenses/>. */
+
+#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 */