git: 5eaee33a2a70 - stable/15 - linux: getsockopt(): Simplify exporting groups a bit
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 23 Sep 2025 12:03:43 UTC
The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=5eaee33a2a701ef86026338fbfa9dda4634e3b2c commit 5eaee33a2a701ef86026338fbfa9dda4634e3b2c Author: Olivier Certner <olce@FreeBSD.org> AuthorDate: 2025-08-29 08:26:59 +0000 Commit: Olivier Certner <olce@FreeBSD.org> CommitDate: 2025-09-23 12:02:45 +0000 linux: getsockopt(): Simplify exporting groups a bit No functional change (intended). Go through conversion to a 'l_gid_t' before copying out in order to cope with differing group types (except for not representable values, of course). This is what is done, e.g., for getgroups() in 'linux_misc.c'. As Linux's group type is the same as ours on all architectures, we could as well just stop bothering and copy out our memory representation, eliminating the loop here. Whatever the choice, though, it has to be consistent here and there. Introduce 'out' of type 'l_gid_t' to avoid performing "by hand" array arithmetics when copying out. MFC after: 5 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52280 (cherry picked from commit 10b789d7e14862c77f77f07e8af84d73d73012c6) --- sys/compat/linux/linux_socket.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 539d153431c4..0e07b0a60ced 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -2179,6 +2179,7 @@ static int linux_getsockopt_so_peergroups(struct thread *td, struct linux_getsockopt_args *args) { + l_gid_t *out = PTRIN(args->optval); struct xucred xu; socklen_t xulen, len; int error, i; @@ -2197,13 +2198,12 @@ linux_getsockopt_so_peergroups(struct thread *td, return (error); } - /* - * "- 1" to skip the primary group. - */ + /* "- 1" to skip the primary group. */ for (i = 0; i < xu.cr_ngroups - 1; i++) { - error = copyout(xu.cr_groups + i + 1, - (void *)(args->optval + i * sizeof(l_gid_t)), - sizeof(l_gid_t)); + /* Copy to cope with a possible type discrepancy. */ + const l_gid_t g = xu.cr_groups[i + 1]; + + error = copyout(&g, out + i, sizeof(l_gid_t)); if (error != 0) return (error); }