^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2014 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Selftests for execveat(2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef _GNU_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define _GNU_SOURCE /* to get O_PATH, AT_EMPTY_PATH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sys/sendfile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <sys/syscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sys/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "../kselftest.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static char longpath[2 * PATH_MAX] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static char *envp[] = { "IN_TEST=yes", NULL, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static char *argv[] = { "execveat", "99", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int execveat_(int fd, const char *path, char **argv, char **envp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #ifdef __NR_execveat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return syscall(__NR_execveat, fd, path, argv, envp, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) errno = ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define check_execveat_fail(fd, path, flags, errno) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) _check_execveat_fail(fd, path, flags, errno, #errno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int _check_execveat_fail(int fd, const char *path, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int expected_errno, const char *errno_str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) printf("Check failure of execveat(%d, '%s', %d) with %s... ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) fd, path?:"(null)", flags, errno_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) rc = execveat_(fd, path, argv, envp, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (rc > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) printf("[FAIL] (unexpected success from execveat(2))\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (errno != expected_errno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) printf("[FAIL] (expected errno %d (%s) not %d (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) expected_errno, strerror(expected_errno),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) errno, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) printf("[OK]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int check_execveat_invoked_rc(int fd, const char *path, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int expected_rc, int expected_rc2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) pid_t child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int pathlen = path ? strlen(path) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (pathlen > 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) printf("Check success of execveat(%d, '%.20s...%s', %d)... ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) fd, path, (path + pathlen - 20), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) printf("Check success of execveat(%d, '%s', %d)... ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) fd, path?:"(null)", flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) child = fork();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (child < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) printf("[FAIL] (fork() failed)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (child == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* Child: do execveat(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) rc = execveat_(fd, path, argv, envp, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) printf("[FAIL]: execveat() failed, rc=%d errno=%d (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) rc, errno, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) exit(1); /* should not reach here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* Parent: wait for & check child's exit status. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) rc = waitpid(child, &status, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (rc != child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) printf("[FAIL] (waitpid(%d,...) returned %d)\n", child, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (!WIFEXITED(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) printf("[FAIL] (child %d did not exit cleanly, status=%08x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) child, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if ((WEXITSTATUS(status) != expected_rc) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) (WEXITSTATUS(status) != expected_rc2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) printf("[FAIL] (child %d exited with %d not %d nor %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) child, WEXITSTATUS(status), expected_rc, expected_rc2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) printf("[OK]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int check_execveat(int fd, const char *path, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return check_execveat_invoked_rc(fd, path, flags, 99, 99);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static char *concat(const char *left, const char *right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) char *result = malloc(strlen(left) + strlen(right) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) strcpy(result, left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) strcat(result, right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int open_or_die(const char *filename, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int fd = open(filename, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) printf("Failed to open '%s'; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) "check prerequisites are available\n", filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void exe_cp(const char *src, const char *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int in_fd = open_or_die(src, O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int out_fd = open(dest, O_RDWR|O_CREAT|O_TRUNC, 0755);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct stat info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) fstat(in_fd, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) sendfile(out_fd, in_fd, NULL, info.st_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) close(in_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) close(out_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define XX_DIR_LEN 200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int check_execveat_pathmax(int root_dfd, const char *src, int is_script)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int ii, count, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) char longname[XX_DIR_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (*longpath == '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* Create a filename close to PATH_MAX in length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) char *cwd = getcwd(NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (!cwd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) printf("Failed to getcwd(), errno=%d (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) errno, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) strcpy(longpath, cwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) strcat(longpath, "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) memset(longname, 'x', XX_DIR_LEN - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) longname[XX_DIR_LEN - 1] = '/';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) longname[XX_DIR_LEN] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) count = (PATH_MAX - 3 - strlen(cwd)) / XX_DIR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) for (ii = 0; ii < count; ii++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) strcat(longpath, longname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) mkdir(longpath, 0755);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) len = (PATH_MAX - 3 - strlen(cwd)) - (count * XX_DIR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) memset(longname, 'y', len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) longname[len] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) strcat(longpath, longname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) free(cwd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) exe_cp(src, longpath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * Execute as a pre-opened file descriptor, which works whether this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * a script or not (because the interpreter sees a filename like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * "/dev/fd/20").
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) fd = open(longpath, O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (fd > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) printf("Invoke copy of '%s' via filename of length %zu:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) src, strlen(longpath));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) fail += check_execveat(fd, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) printf("Failed to open length %zu filename, errno=%d (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) strlen(longpath), errno, strerror(errno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) fail++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * Execute as a long pathname relative to "/". If this is a script,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * the interpreter will launch but fail to open the script because its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * name ("/dev/fd/5/xxx....") is bigger than PATH_MAX.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * The failure code is usually 127 (POSIX: "If a command is not found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * the exit status shall be 127."), but some systems give 126 (POSIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * "If the command name is found, but it is not an executable utility,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * the exit status shall be 126."), so allow either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (is_script)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) fail += check_execveat_invoked_rc(root_dfd, longpath + 1, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 127, 126);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) fail += check_execveat(root_dfd, longpath + 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int run_tests(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int fail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) char *fullname = realpath("execveat", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) char *fullname_script = realpath("script", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) char *fullname_symlink = concat(fullname, ".symlink");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int subdir_dfd = open_or_die("subdir", O_DIRECTORY|O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int subdir_dfd_ephemeral = open_or_die("subdir.ephemeral",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) O_DIRECTORY|O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int dot_dfd = open_or_die(".", O_DIRECTORY|O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int root_dfd = open_or_die("/", O_DIRECTORY|O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int dot_dfd_path = open_or_die(".", O_DIRECTORY|O_RDONLY|O_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int dot_dfd_cloexec = open_or_die(".", O_DIRECTORY|O_RDONLY|O_CLOEXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int fd = open_or_die("execveat", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int fd_path = open_or_die("execveat", O_RDONLY|O_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int fd_symlink = open_or_die("execveat.symlink", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int fd_denatured = open_or_die("execveat.denatured", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int fd_denatured_path = open_or_die("execveat.denatured",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) O_RDONLY|O_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int fd_script = open_or_die("script", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int fd_ephemeral = open_or_die("execveat.ephemeral", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int fd_ephemeral_path = open_or_die("execveat.path.ephemeral",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) O_RDONLY|O_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int fd_script_ephemeral = open_or_die("script.ephemeral", O_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int fd_cloexec = open_or_die("execveat", O_RDONLY|O_CLOEXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int fd_script_cloexec = open_or_die("script", O_RDONLY|O_CLOEXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Check if we have execveat at all, and bail early if not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) execveat_(-1, NULL, NULL, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (errno == ENOSYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ksft_exit_skip(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) "ENOSYS calling execveat - no kernel support?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /* Change file position to confirm it doesn't affect anything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) lseek(fd, 10, SEEK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* Normal executable file: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* dfd + path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) fail += check_execveat(subdir_dfd, "../execveat", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) fail += check_execveat(dot_dfd, "execveat", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) fail += check_execveat(dot_dfd_path, "execveat", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* absolute path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) fail += check_execveat(AT_FDCWD, fullname, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* absolute path with nonsense dfd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) fail += check_execveat(99, fullname, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* fd + no path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) fail += check_execveat(fd, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* O_CLOEXEC fd + no path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) fail += check_execveat(fd_cloexec, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* O_PATH fd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) fail += check_execveat(fd_path, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Mess with executable file that's already open: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* fd + no path to a file that's been renamed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) rename("execveat.ephemeral", "execveat.moved");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) fail += check_execveat(fd_ephemeral, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* fd + no path to a file that's been deleted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) unlink("execveat.moved"); /* remove the file now fd open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) fail += check_execveat(fd_ephemeral, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /* Mess with executable file that's already open with O_PATH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /* fd + no path to a file that's been deleted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) unlink("execveat.path.ephemeral");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) fail += check_execveat(fd_ephemeral_path, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Invalid argument failures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) fail += check_execveat_fail(fd, "", 0, ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) fail += check_execveat_fail(fd, NULL, AT_EMPTY_PATH, EFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* Symlink to executable file: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* dfd + path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) fail += check_execveat(dot_dfd, "execveat.symlink", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) fail += check_execveat(dot_dfd_path, "execveat.symlink", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* absolute path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) fail += check_execveat(AT_FDCWD, fullname_symlink, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /* fd + no path, even with AT_SYMLINK_NOFOLLOW (already followed) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) fail += check_execveat(fd_symlink, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) fail += check_execveat(fd_symlink, "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) AT_EMPTY_PATH|AT_SYMLINK_NOFOLLOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* Symlink fails when AT_SYMLINK_NOFOLLOW set: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* dfd + path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) fail += check_execveat_fail(dot_dfd, "execveat.symlink",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) AT_SYMLINK_NOFOLLOW, ELOOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) fail += check_execveat_fail(dot_dfd_path, "execveat.symlink",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) AT_SYMLINK_NOFOLLOW, ELOOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* absolute path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) fail += check_execveat_fail(AT_FDCWD, fullname_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) AT_SYMLINK_NOFOLLOW, ELOOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* Non-regular file failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) fail += check_execveat_fail(dot_dfd, "pipe", 0, EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) unlink("pipe");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /* Shell script wrapping executable file: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /* dfd + path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) fail += check_execveat(subdir_dfd, "../script", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) fail += check_execveat(dot_dfd, "script", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) fail += check_execveat(dot_dfd_path, "script", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /* absolute path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) fail += check_execveat(AT_FDCWD, fullname_script, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* fd + no path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) fail += check_execveat(fd_script, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) fail += check_execveat(fd_script, "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) AT_EMPTY_PATH|AT_SYMLINK_NOFOLLOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* O_CLOEXEC fd fails for a script (as script file inaccessible) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) fail += check_execveat_fail(fd_script_cloexec, "", AT_EMPTY_PATH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) fail += check_execveat_fail(dot_dfd_cloexec, "script", 0, ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* Mess with script file that's already open: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* fd + no path to a file that's been renamed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) rename("script.ephemeral", "script.moved");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) fail += check_execveat(fd_script_ephemeral, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* fd + no path to a file that's been deleted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) unlink("script.moved"); /* remove the file while fd open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) fail += check_execveat(fd_script_ephemeral, "", AT_EMPTY_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* Rename a subdirectory in the path: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) rename("subdir.ephemeral", "subdir.moved");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) fail += check_execveat(subdir_dfd_ephemeral, "../script", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) fail += check_execveat(subdir_dfd_ephemeral, "script", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* Remove the subdir and its contents */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) unlink("subdir.moved/script");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) unlink("subdir.moved");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* Shell loads via deleted subdir OK because name starts with .. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) fail += check_execveat(subdir_dfd_ephemeral, "../script", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) fail += check_execveat_fail(subdir_dfd_ephemeral, "script", 0, ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /* Flag values other than AT_SYMLINK_NOFOLLOW => EINVAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) fail += check_execveat_fail(dot_dfd, "execveat", 0xFFFF, EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) /* Invalid path => ENOENT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) fail += check_execveat_fail(dot_dfd, "no-such-file", 0, ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) fail += check_execveat_fail(dot_dfd_path, "no-such-file", 0, ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) fail += check_execveat_fail(AT_FDCWD, "no-such-file", 0, ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* Attempt to execute directory => EACCES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) fail += check_execveat_fail(dot_dfd, "", AT_EMPTY_PATH, EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* Attempt to execute non-executable => EACCES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) fail += check_execveat_fail(dot_dfd, "Makefile", 0, EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) fail += check_execveat_fail(fd_denatured, "", AT_EMPTY_PATH, EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) fail += check_execveat_fail(fd_denatured_path, "", AT_EMPTY_PATH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* Attempt to execute nonsense FD => EBADF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) fail += check_execveat_fail(99, "", AT_EMPTY_PATH, EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) fail += check_execveat_fail(99, "execveat", 0, EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /* Attempt to execute relative to non-directory => ENOTDIR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) fail += check_execveat_fail(fd, "execveat", 0, ENOTDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) fail += check_execveat_pathmax(root_dfd, "execveat", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) fail += check_execveat_pathmax(root_dfd, "script", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static void prerequisites(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) const char *script = "#!/bin/sh\nexit $*\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* Create ephemeral copies of files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) exe_cp("execveat", "execveat.ephemeral");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) exe_cp("execveat", "execveat.path.ephemeral");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) exe_cp("script", "script.ephemeral");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) mkdir("subdir.ephemeral", 0755);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) fd = open("subdir.ephemeral/script", O_RDWR|O_CREAT|O_TRUNC, 0755);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) write(fd, script, strlen(script));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) mkfifo("pipe", 0755);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int ii;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) const char *verbose = getenv("VERBOSE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (argc >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* If we are invoked with an argument, don't run tests. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) const char *in_test = getenv("IN_TEST");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (verbose) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) printf(" invoked with:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) for (ii = 0; ii < argc; ii++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) printf(" [%d]='%s'", ii, argv[ii]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) printf("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* Check expected environment transferred. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (!in_test || strcmp(in_test, "yes") != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) printf("[FAIL] (no IN_TEST=yes in env)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /* Use the final argument as an exit code. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) rc = atoi(argv[argc - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) fflush(stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) prerequisites();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) envp[1] = "VERBOSE=1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) rc = run_tests();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (rc > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) printf("%d tests failed\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }