su should not chdir to home --- busybox-1.19.4/include/libbb.h +++ busybox-1.19.4/include/libbb.h @@ -1274,6 +1274,7 @@ #define SETUP_ENV_CHANGEENV (1 << 0) #define SETUP_ENV_CLEARENV (1 << 1) #define SETUP_ENV_TO_TMP (1 << 2) +#define SETUP_ENV_NO_CHDIR (1 << 4) extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; extern int correct_password(const struct passwd *pw) FAST_FUNC; /* Returns a malloced string */ --- busybox-1.19.4/libbb/setup_environment.c +++ busybox-1.19.4/libbb/setup_environment.c @@ -37,9 +37,11 @@ /* Change the current working directory to be the home directory * of the user */ - if (chdir(pw->pw_dir)) { - xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); - bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); + if ((flags & SETUP_ENV_NO_CHDIR) == 0) { + if (chdir(pw->pw_dir)) { + xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); + bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); + } } if (flags & SETUP_ENV_CLEARENV) { --- busybox-1.19.4/loginutils/su.c +++ busybox-1.19.4/loginutils/su.c @@ -131,7 +131,8 @@ change_identity(pw); setup_environment(opt_shell, ((flags & SU_OPT_l) / SU_OPT_l * SETUP_ENV_CLEARENV) - + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV), + + (!(flags & SU_OPT_mp) * SETUP_ENV_CHANGEENV) + + (!(flags & SU_OPT_l) * SETUP_ENV_NO_CHDIR), pw); IF_SELINUX(set_current_security_context(NULL);)