Skip to content

Commit c7a4369

Browse files
committed
libtcb: make -DENABLE_SETFSUGID the default and only implementation
Use setfsuid/setfsgid instead of setreuid/setregid unconditionally. There is no clear benefits of using the latter, on the contrary, per POSIX setreuid and setregid functions affect all threads, making their users, tcb_drop_priv_r and tcb_gain_priv_r, unsuitable for threaded processes.
1 parent d73b965 commit c7a4369

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2023-01-20 Dmitry V. Levin <ldv at owl.openwall.com>
2+
3+
Make -DENABLE_SETFSUGID the default and only implementation.
4+
* libs/libtcb.c [!ENABLE_SETFSUGID]: Remove.
5+
* tcb.spec: Remove -DENABLE_SETFSUGID.
6+
* ci/run-build-and-tests.sh: Likewise.
7+
18
2021-09-30 Björn Esser <besser82 at fedoraproject.org>
29

310
pam_tcb: Fix "-Wpedantic".

ci/run-build-and-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ echo 'END OF BUILD ENVIRONMENT INFORMATION'
2929
nproc="$(nproc)" || nproc=1
3030
j="-j$nproc"
3131

32-
CFLAGS='-O2 -Wall -W -DENABLE_SETFSUGID -DENABLE_NLS -DNLS_PACKAGE=\"Linux-PAM\"' \
32+
CFLAGS='-O2 -Wall -W -DENABLE_NLS -DNLS_PACKAGE=\"Linux-PAM\"' \
3333
make -k $j CC="$CC" WERROR=1
3434

3535
if git status --porcelain |grep ^.; then

libs/libtcb.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sys/stat.h>
1010
#include <stdio.h>
1111
#include <stdlib.h>
12+
#include <sys/fsuid.h>
1213

1314
#include "tcb.h"
1415
#include "attribute.h"
@@ -140,8 +141,6 @@ int ulckpwdf_tcb(void)
140141
static gid_t glob_grplist[TCB_NGROUPS];
141142
static struct tcb_privs glob_privs = { glob_grplist, 0, -1, -1, 0 };
142143

143-
#ifdef ENABLE_SETFSUGID
144-
#include <sys/fsuid.h>
145144
/*
146145
* Two setfsuid() in a row - stupid, but how the hell am I supposed to check
147146
* whether setfsuid() succeeded?
@@ -160,20 +159,6 @@ static int ch_gid(gid_t gid, gid_t *save)
160159
*save = tmp;
161160
return (gid_t) setfsgid(gid) == gid;
162161
}
163-
#else
164-
static int ch_uid(uid_t uid, uid_t *save)
165-
{
166-
if (save)
167-
*save = geteuid();
168-
return setreuid(-1, uid) != -1;
169-
}
170-
static int ch_gid(gid_t gid, gid_t *save)
171-
{
172-
if (save)
173-
*save = getegid();
174-
return setregid(-1, gid) != -1;
175-
}
176-
#endif
177162

178163
#define PRIV_MAGIC 0x1004000a
179164
#define PRIV_MAGIC_NONROOT 0xdead000a

tcb.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ building tcb-aware applications.
3838
%setup -q
3939

4040
%build
41-
CFLAGS="%optflags -DENABLE_SETFSUGID" %__make
41+
CFLAGS="%optflags" %__make
4242

4343
%install
4444
rm -rf %buildroot

0 commit comments

Comments
 (0)