파일이 실행 가능하지 않으면 execLinux 커널 의 syscall이 실패합니다.EACCES
할 수는 있지만 그렇게 할 수 없으므로 sh myprog.sh프로그램을 실행할 ./myprog.sh수 없습니다.
이것은 다음을 통해 확인할 수 있습니다 main.c.
#define _XOPEN_SOURCE 700
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
int main(void) {
char *argv[] = {"myprog", NULL};
char *envp[] = {NULL};
int ret;
ret = execve("myprog.sh", argv, envp);
perror("execve");
printf("%d\n", errno);
printf("%d\n", EACCES);
}
그리고 myprog.sh:
#!/bin/sh
echo worked
myprog.sh실행 파일이 아닌 경우 main실패합니다.
execve: Permission denied
13
13
우분투 17.10에서 테스트되었습니다 gcc -std=c99.
POSIX 7은 다음에서 언급합니다.
다음과 같은 경우 fexecve ()를 제외한 exec 함수는 실패합니다.
[EACCES] 새 프로세스 이미지 파일의 경로 접두사에 나열된 디렉토리에 대한 검색 권한이 거부되었거나 새 프로세스 이미지 파일이 실행 권한을 거부합니다.
자세한 근거는 /security/66550/unix-execute-permission-can-be-e-as-bypassed-is-it-superfluous- 또는 -whats-the에서 확인할 수 있습니다.