security: Exit on failure of env_set_user()
CVE-2026-32107. Prevent possible privilege escalation if setuid() fails.
This commit is contained in:
+29
-21
@@ -40,7 +40,7 @@
|
||||
#include "xrdp_sockets.h"
|
||||
|
||||
/******************************************************************************/
|
||||
int
|
||||
void
|
||||
env_set_user(int uid,
|
||||
const struct list *env_names, const struct list *env_values)
|
||||
{
|
||||
@@ -58,32 +58,40 @@ env_set_user(int uid,
|
||||
error = g_getuser_info_by_uid(uid, &pw_username, &pw_gid, &pw_shell,
|
||||
&pw_dir, 0);
|
||||
|
||||
if (error == 0)
|
||||
if (error != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ALWAYS,
|
||||
"fatal error getting user info for uid %d: %s", uid,
|
||||
g_get_strerror());
|
||||
goto fatal;
|
||||
}
|
||||
g_rm_temp_dir();
|
||||
g_clearenv();
|
||||
#ifdef HAVE_SETUSERCONTEXT
|
||||
error = g_set_allusercontext(uid);
|
||||
if (g_set_allusercontext(uid) != 0)
|
||||
{
|
||||
LOG(LOG_LEVEL_ALWAYS,
|
||||
"fatal error setting allusercontext for uid %d: %s",
|
||||
uid, g_get_strerror());
|
||||
goto fatal;
|
||||
}
|
||||
#else
|
||||
/* Set some of the things setusercontext() handles on other
|
||||
* systems */
|
||||
|
||||
/* Primary group. Note that secondary groups should already
|
||||
/* GID/UID. Note that secondary groups should already
|
||||
* have been set, if we're not using setusercontext() */
|
||||
error = g_setgid(pw_gid);
|
||||
|
||||
if (error == 0)
|
||||
if (g_setgid(pw_gid) != 0 || g_setuid(uid) != 0)
|
||||
{
|
||||
error = g_setuid(uid);
|
||||
LOG(LOG_LEVEL_ALWAYS,
|
||||
"fatal error getting setting uid:gid to %d:%d - %s",
|
||||
uid, pw_gid, g_get_strerror());
|
||||
goto fatal;
|
||||
}
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
g_setenv_log("PATH", "/sbin:/bin:/usr/bin:/usr/local/bin", 1);
|
||||
}
|
||||
#endif
|
||||
if (error == 0)
|
||||
{
|
||||
|
||||
g_setenv_log("SHELL", pw_shell, 1);
|
||||
g_setenv_log("USER", pw_username, 1);
|
||||
g_setenv_log("LOGNAME", pw_username, 1);
|
||||
@@ -131,17 +139,17 @@ env_set_user(int uid,
|
||||
g_setenv_log("XAUTHORITY", text, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(LOG_LEVEL_ERROR,
|
||||
"error getting user info for uid %d", uid);
|
||||
}
|
||||
|
||||
g_free(pw_username);
|
||||
g_free(pw_dir);
|
||||
g_free(pw_shell);
|
||||
|
||||
return error;
|
||||
return;
|
||||
|
||||
fatal:
|
||||
g_free(pw_username);
|
||||
g_free(pw_dir);
|
||||
g_free(pw_shell);
|
||||
|
||||
g_exit(1);
|
||||
}
|
||||
|
||||
@@ -46,10 +46,12 @@ env_check_password_file(const char *filename, const char *password);
|
||||
* @param uid user ID
|
||||
* @param env_names List of session environment variables to set
|
||||
* @param env_values List of session environment values to set
|
||||
* @return 0 on success, g_getuser_info() error codes on error
|
||||
*
|
||||
* On error, the calling process exits, to prevent privilege
|
||||
* escalations.
|
||||
*
|
||||
*/
|
||||
int
|
||||
void
|
||||
env_set_user(int uid,
|
||||
const struct list *env_names, const struct list *env_values);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user