Skip to content

Commit f39dbf0

Browse files
author
git-core
committed
Change euid back to root before finally set a new id
Fixes a bug reported in a comment to the issue #9 against su-binary (see #9 (comment) for details). Thanks to Erik Pilsits (epilsits@gmail.com) for the report. Add the euid change before populate_environment() anticipating we have to merge the commit "Inherit LD_LIBRARY_PATH ...", which needs root credentials in order to successfully open /proc/<ppid>/environ.
1 parent 8afac1d commit f39dbf0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

su.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,15 @@ static void allow(const struct su_context *ctx)
319319
arg0 = p;
320320
}
321321

322+
/*
323+
* Set effective uid back to root, otherwise setres[ug]id will fail
324+
* if ctx->to.uid isn't root.
325+
*/
326+
if (seteuid(0)) {
327+
PLOGE("seteuid (root)");
328+
exit(EXIT_FAILURE);
329+
}
330+
322331
populate_environment(ctx);
323332

324333
if (setresgid(ctx->to.uid, ctx->to.uid, ctx->to.uid)) {

0 commit comments

Comments
 (0)