realpath /proc/pid/cwd

prevent cross mount namespace
This commit is contained in:
vvb2060 2021-10-26 22:01:01 +08:00 committed by John Wu
parent 6c5b261804
commit b2f152e641

View File

@ -314,7 +314,9 @@ void su_daemon_handler(int client, const sock_cred *cred) {
umask(022);
char path[32];
snprintf(path, sizeof(path), "/proc/%d/cwd", ctx.pid);
chdir(path);
char cwd[PATH_MAX];
if (realpath(path, cwd))
chdir(cwd);
snprintf(path, sizeof(path), "/proc/%d/environ", ctx.pid);
char buf[4096] = { 0 };
int fd = xopen(path, O_RDONLY);