do_fork: Propagate error code returned by mcexec

Refs: #731
Change-Id: I7eb52c1c76103d65d108b18b7beaf8041b51cd03
This commit is contained in:
Tomoki Shirasawa
2018-06-18 16:44:26 +09:00
committed by Dominique Martinet
parent 0758f6254e
commit 1cbe389879
13 changed files with 247 additions and 1 deletions

55
test/issues/731/g310a.c Normal file
View File

@ -0,0 +1,55 @@
/*
* g310a: If superuser try to fork() after seteuid(bin), ...
*/
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void)
{
int error;
struct passwd *pwd;
pid_t pid;
int ws;
if (geteuid()) {
printf("not a superuser\n");
return 2;
}
pwd = getpwnam("bin");
if (!pwd) {
perror("getpwnam");
return 1;
}
error = seteuid(pwd->pw_uid);
if (error) {
perror("seteuid");
return 1;
}
pid = fork();
if (pid == -1) {
perror("fork");
}
if (!pid) {
return 0;
}
pid = waitpid(pid, &ws, 0);
if (pid == -1) {
perror("waitpid");
return 1;
}
if (ws) {
printf("ws: %#x\n", ws);
return 1;
}
printf("done.\n");
return 0;
}