56ac45c10b
For dynamically linked executables, the interpreter is passed a file descriptor of the binary being executed. To this end, VFS opens the target executable, but opening the file fails if it is not readable, even when it is executable. With this patch, when opening the executable, it verifies the X bit rather than the R bit on the file, thus allowing the execution of dynamically linked binaries that are executable but not readable. Add test86 to verify correctness. Change-Id: If3514add6a33b33d52c05a0a627d757bff118d77
51 lines
1,019 B
C
51 lines
1,019 B
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
#include <fcntl.h>
|
|
#include <sys/wait.h>
|
|
|
|
#include "common.h"
|
|
|
|
/*
|
|
* Test for dynamic executables with no read permissions. This test relies on
|
|
* being linked dynamically.
|
|
*/
|
|
int
|
|
main(int argc, char ** argv)
|
|
{
|
|
char *executable, cp_cmd[PATH_MAX + 9];
|
|
int status;
|
|
|
|
if (strcmp(argv[0], "DO CHECK") == 0)
|
|
exit(EXIT_SUCCESS);
|
|
|
|
start(86);
|
|
|
|
/* Make a copy of this binary which is executable-only. */
|
|
executable = argv[0];
|
|
|
|
snprintf(cp_cmd, sizeof(cp_cmd), "cp ../%s .", executable);
|
|
status = system(cp_cmd);
|
|
if (status < 0 || !WIFEXITED(status) ||
|
|
WEXITSTATUS(status) != EXIT_SUCCESS) e(0);
|
|
|
|
if (chmod(executable, S_IXUSR) != 0) e(0);
|
|
|
|
/* Invoke the changed binary in a child process. */
|
|
switch (fork()) {
|
|
case -1:
|
|
e(0);
|
|
case 0:
|
|
execl(executable, "DO CHECK", NULL);
|
|
|
|
exit(EXIT_FAILURE);
|
|
default:
|
|
if (wait(&status) <= 0) e(0);
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status) != EXIT_SUCCESS)
|
|
e(0);
|
|
}
|
|
|
|
quit();
|
|
/* NOTREACHED */
|
|
}
|