Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/exec: Verify execve of non-regular files fail

Add a named pipe as an exec target to make sure that non-regular
files are rejected by execve() with EACCES. This can help verify
commit 73601ea5b7b1 ("fs/open.c: allow opening only regular files
during execve()").

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Kees Cook and committed by
Shuah Khan
61016db1 a5f30467

+10 -1
+1
tools/testing/selftests/exec/.gitignore
··· 9 9 execveat.denatured 10 10 /recursion-depth 11 11 xxxxxxxx* 12 + pipe
+1 -1
tools/testing/selftests/exec/Makefile
··· 4 4 CFLAGS += -D_GNU_SOURCE 5 5 6 6 TEST_GEN_PROGS := execveat 7 - TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir 7 + TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir pipe 8 8 # Makefile is a run-time dependency, since it's accessed by the execveat test 9 9 TEST_FILES := Makefile 10 10
+8
tools/testing/selftests/exec/execveat.c
··· 5 5 * Selftests for execveat(2). 6 6 */ 7 7 8 + #ifndef _GNU_SOURCE 8 9 #define _GNU_SOURCE /* to get O_PATH, AT_EMPTY_PATH */ 10 + #endif 9 11 #include <sys/sendfile.h> 10 12 #include <sys/stat.h> 11 13 #include <sys/syscall.h> ··· 313 311 fail += check_execveat_fail(AT_FDCWD, fullname_symlink, 314 312 AT_SYMLINK_NOFOLLOW, ELOOP); 315 313 314 + /* Non-regular file failure */ 315 + fail += check_execveat_fail(dot_dfd, "pipe", 0, EACCES); 316 + unlink("pipe"); 317 + 316 318 /* Shell script wrapping executable file: */ 317 319 /* dfd + path */ 318 320 fail += check_execveat(subdir_dfd, "../script", 0); ··· 390 384 fd = open("subdir.ephemeral/script", O_RDWR|O_CREAT|O_TRUNC, 0755); 391 385 write(fd, script, strlen(script)); 392 386 close(fd); 387 + 388 + mkfifo("pipe", 0755); 393 389 } 394 390 395 391 int main(int argc, char **argv)