]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix setgroups() use
authorKarel Zak <kzak@redhat.com>
Thu, 29 Jul 2021 09:50:48 +0000 (11:50 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 29 Jul 2021 09:50:48 +0000 (11:50 +0200)
* keep process in single supplementary group, which is the real group ID for the process

* make sure we have rights to call setgroups(), requires group permissions

Fixes: https://github.com/karelzak/util-linux/issues/1398
Signed-off-by: Karel Zak <kzak@redhat.com>
include/c.h

index c1e4c5ffc92b0f9c648f379fb7465e5f714b88f1..a4504e3ba5398691f9aa172336cbb6580ae46b28 100644 (file)
@@ -340,14 +340,16 @@ static inline size_t get_hostname_max(void)
 
 static inline int drop_permissions(void)
 {
+       gid_t newgid = getgid();
+
        errno = 0;
 
        /* drop supplementary groups */
-       if (setgroups(0, NULL) != 0)
+       if (geteuid() == 0 && setgroups(1, &newgid) != 0)
                goto fail;
 
        /* drop GID */
-       if (setgid(getgid()) < 0)
+       if (setgid(newgid) < 0)
                goto fail;
 
        /* drop UID */