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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'execve-v6.9-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull execve fixes from Kees Cook:

- Fix selftests to conform to the TAP output format (Muhammad Usama
Anjum)

- Fix NOMMU linux_binprm::exec pointer in auxv (Max Filippov)

- Replace deprecated strncpy usage (Justin Stitt)

- Replace another /bin/sh instance in selftests

* tag 'execve-v6.9-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
binfmt: replace deprecated strncpy
exec: Fix NOMMU linux_binprm::exec in transfer_args_to_stack()
selftests/exec: Convert remaining /bin/sh to /bin/bash
selftests/exec: execveat: Improve debug reporting
selftests/exec: recursion-depth: conform test to TAP format output
selftests/exec: load_address: conform test to TAP format output
selftests/exec: binfmt_script: Add the overall result line according to TAP

+62 -56
+1 -1
fs/binfmt_elf_fdpic.c
··· 1359 1359 SET_UID(psinfo->pr_uid, from_kuid_munged(cred->user_ns, cred->uid)); 1360 1360 SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); 1361 1361 rcu_read_unlock(); 1362 - strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname)); 1362 + get_task_comm(psinfo->pr_fname, p); 1363 1363 1364 1364 return 0; 1365 1365 }
+1
fs/exec.c
··· 895 895 goto out; 896 896 } 897 897 898 + bprm->exec += *sp_location - MAX_ARG_PAGES * PAGE_SIZE; 898 899 *sp_location = sp; 899 900 900 901 out:
+2 -2
tools/testing/selftests/exec/Makefile
··· 19 19 20 20 $(OUTPUT)/subdir: 21 21 mkdir -p $@ 22 - $(OUTPUT)/script: 23 - echo '#!/bin/sh' > $@ 22 + $(OUTPUT)/script: Makefile 23 + echo '#!/bin/bash' > $@ 24 24 echo 'exit $$*' >> $@ 25 25 chmod +x $@ 26 26 $(OUTPUT)/execveat.symlink: $(OUTPUT)/execveat
+9 -1
tools/testing/selftests/exec/binfmt_script.py
··· 16 16 NAME_MAX=int(subprocess.check_output(["getconf", "NAME_MAX", "."])) 17 17 18 18 test_num=0 19 + pass_num=0 20 + fail_num=0 19 21 20 22 code='''#!/usr/bin/perl 21 23 print "Executed interpreter! Args:\n"; ··· 44 42 # ... 45 43 def test(name, size, good=True, leading="", root="./", target="/perl", 46 44 fill="A", arg="", newline="\n", hashbang="#!"): 47 - global test_num, tests, NAME_MAX 45 + global test_num, pass_num, fail_num, tests, NAME_MAX 48 46 test_num += 1 49 47 if test_num > tests: 50 48 raise ValueError("more binfmt_script tests than expected! (want %d, expected %d)" ··· 82 80 if good: 83 81 print("ok %d - binfmt_script %s (successful good exec)" 84 82 % (test_num, name)) 83 + pass_num += 1 85 84 else: 86 85 print("not ok %d - binfmt_script %s succeeded when it should have failed" 87 86 % (test_num, name)) 87 + fail_num = 1 88 88 else: 89 89 if good: 90 90 print("not ok %d - binfmt_script %s failed when it should have succeeded (rc:%d)" 91 91 % (test_num, name, proc.returncode)) 92 + fail_num = 1 92 93 else: 93 94 print("ok %d - binfmt_script %s (correctly failed bad exec)" 94 95 % (test_num, name)) 96 + pass_num += 1 95 97 96 98 # Clean up crazy binaries 97 99 os.unlink(script) ··· 171 165 test(name="two-under-trunc-arg", size=int(SIZE/2), arg=" ") 172 166 test(name="two-under-leading", size=int(SIZE/2), leading=" ") 173 167 test(name="two-under-lead-trunc-arg", size=int(SIZE/2), leading=" ", arg=" ") 168 + 169 + print("# Totals: pass:%d fail:%d xfail:0 xpass:0 skip:0 error:0" % (pass_num, fail_num)) 174 170 175 171 if test_num != tests: 176 172 raise ValueError("fewer binfmt_script tests than expected! (ran %d, expected %d"
+7 -5
tools/testing/selftests/exec/execveat.c
··· 98 98 if (child == 0) { 99 99 /* Child: do execveat(). */ 100 100 rc = execveat_(fd, path, argv, envp, flags); 101 - ksft_print_msg("execveat() failed, rc=%d errno=%d (%s)\n", 101 + ksft_print_msg("child execveat() failed, rc=%d errno=%d (%s)\n", 102 102 rc, errno, strerror(errno)); 103 - ksft_test_result_fail("%s\n", test_name); 104 - exit(1); /* should not reach here */ 103 + exit(errno); 105 104 } 106 105 /* Parent: wait for & check child's exit status. */ 107 106 rc = waitpid(child, &status, 0); ··· 225 226 * "If the command name is found, but it is not an executable utility, 226 227 * the exit status shall be 126."), so allow either. 227 228 */ 228 - if (is_script) 229 + if (is_script) { 230 + ksft_print_msg("Invoke script via root_dfd and relative filename\n"); 229 231 fail += check_execveat_invoked_rc(root_dfd, longpath + 1, 0, 230 232 127, 126); 231 - else 233 + } else { 234 + ksft_print_msg("Invoke exec via root_dfd and relative filename\n"); 232 235 fail += check_execveat(root_dfd, longpath + 1, 0); 236 + } 233 237 234 238 return fail; 235 239 }
+16 -20
tools/testing/selftests/exec/load_address.c
··· 5 5 #include <link.h> 6 6 #include <stdio.h> 7 7 #include <stdlib.h> 8 + #include "../kselftest.h" 8 9 9 10 struct Statistics { 10 11 unsigned long long load_address; ··· 42 41 unsigned long long misalign; 43 42 int ret; 44 43 45 - ret = dl_iterate_phdr(ExtractStatistics, &extracted); 46 - if (ret != 1) { 47 - fprintf(stderr, "FAILED\n"); 48 - return 1; 49 - } 44 + ksft_print_header(); 45 + ksft_set_plan(1); 50 46 51 - if (extracted.alignment == 0) { 52 - fprintf(stderr, "No alignment found\n"); 53 - return 1; 54 - } else if (extracted.alignment & (extracted.alignment - 1)) { 55 - fprintf(stderr, "Alignment is not a power of 2\n"); 56 - return 1; 57 - } 47 + ret = dl_iterate_phdr(ExtractStatistics, &extracted); 48 + if (ret != 1) 49 + ksft_exit_fail_msg("FAILED: dl_iterate_phdr\n"); 50 + 51 + if (extracted.alignment == 0) 52 + ksft_exit_fail_msg("FAILED: No alignment found\n"); 53 + else if (extracted.alignment & (extracted.alignment - 1)) 54 + ksft_exit_fail_msg("FAILED: Alignment is not a power of 2\n"); 58 55 59 56 misalign = extracted.load_address & (extracted.alignment - 1); 60 - if (misalign) { 61 - printf("alignment = %llu, load_address = %llu\n", 62 - extracted.alignment, extracted.load_address); 63 - fprintf(stderr, "FAILED\n"); 64 - return 1; 65 - } 57 + if (misalign) 58 + ksft_exit_fail_msg("FAILED: alignment = %llu, load_address = %llu\n", 59 + extracted.alignment, extracted.load_address); 66 60 67 - fprintf(stderr, "PASS\n"); 68 - return 0; 61 + ksft_test_result_pass("Completed\n"); 62 + ksft_finished(); 69 63 }
+26 -27
tools/testing/selftests/exec/recursion-depth.c
··· 23 23 #include <fcntl.h> 24 24 #include <sys/mount.h> 25 25 #include <unistd.h> 26 + #include "../kselftest.h" 26 27 27 28 int main(void) 28 29 { 30 + int fd, rv; 31 + 32 + ksft_print_header(); 33 + ksft_set_plan(1); 34 + 29 35 if (unshare(CLONE_NEWNS) == -1) { 30 36 if (errno == ENOSYS || errno == EPERM) { 31 - fprintf(stderr, "error: unshare, errno %d\n", errno); 32 - return 4; 37 + ksft_test_result_skip("error: unshare, errno %d\n", errno); 38 + ksft_finished(); 33 39 } 34 - fprintf(stderr, "error: unshare, errno %d\n", errno); 35 - return 1; 40 + ksft_exit_fail_msg("error: unshare, errno %d\n", errno); 36 41 } 37 - if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) { 38 - fprintf(stderr, "error: mount '/', errno %d\n", errno); 39 - return 1; 40 - } 42 + 43 + if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1) 44 + ksft_exit_fail_msg("error: mount '/', errno %d\n", errno); 45 + 41 46 /* Require "exec" filesystem. */ 42 - if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1) { 43 - fprintf(stderr, "error: mount ramfs, errno %d\n", errno); 44 - return 1; 45 - } 47 + if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1) 48 + ksft_exit_fail_msg("error: mount ramfs, errno %d\n", errno); 46 49 47 50 #define FILENAME "/tmp/1" 48 51 49 - int fd = creat(FILENAME, 0700); 50 - if (fd == -1) { 51 - fprintf(stderr, "error: creat, errno %d\n", errno); 52 - return 1; 53 - } 52 + fd = creat(FILENAME, 0700); 53 + if (fd == -1) 54 + ksft_exit_fail_msg("error: creat, errno %d\n", errno); 55 + 54 56 #define S "#!" FILENAME "\n" 55 - if (write(fd, S, strlen(S)) != strlen(S)) { 56 - fprintf(stderr, "error: write, errno %d\n", errno); 57 - return 1; 58 - } 57 + if (write(fd, S, strlen(S)) != strlen(S)) 58 + ksft_exit_fail_msg("error: write, errno %d\n", errno); 59 + 59 60 close(fd); 60 61 61 - int rv = execve(FILENAME, NULL, NULL); 62 - if (rv == -1 && errno == ELOOP) { 63 - return 0; 64 - } 65 - fprintf(stderr, "error: execve, rv %d, errno %d\n", rv, errno); 66 - return 1; 62 + rv = execve(FILENAME, NULL, NULL); 63 + ksft_test_result(rv == -1 && errno == ELOOP, 64 + "execve failed as expected (ret %d, errno %d)\n", rv, errno); 65 + ksft_finished(); 67 66 }