1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
| static int do_execveat_common(int fd, struct filename *filename, struct user_arg_ptr argv, struct user_arg_ptr envp, int flags) { char *pathbuf = NULL; struct linux_binprm *bprm; struct file *file; struct files_struct *displaced; int retval;
if (IS_ERR(filename)) { printk("%s, %d, filename error\n", __func__, __LINE__); return PTR_ERR(filename); }
if ((current->flags & PF_NPROC_EXCEEDED) && atomic_read(¤t_user()->processes) > rlimit(RLIMIT_NPROC)) { retval = -EAGAIN; goto out_ret; }
current->flags &= ~PF_NPROC_EXCEEDED;
retval = unshare_files(&displaced); if (retval) goto out_ret;
retval = -ENOMEM; bprm = kzalloc(sizeof(*bprm), GFP_KERNEL); if (!bprm) goto out_files;
retval = prepare_bprm_creds(bprm); if (retval) goto out_free;
check_unsafe_exec(bprm); current->in_execve = 1;
file = do_open_execat(fd, filename, flags); retval = PTR_ERR(file); if (IS_ERR(file)) { printk("%s, %d, file error\n", __func__, __LINE__); goto out_unmark; }
sched_exec();
bprm->file = file; if (fd == AT_FDCWD || filename->name[0] == '/') { bprm->filename = filename->name; } else { if (filename->name[0] == '\0') pathbuf = kasprintf(GFP_TEMPORARY, "/dev/fd/%d", fd); else pathbuf = kasprintf(GFP_TEMPORARY, "/dev/fd/%d/%s", fd, filename->name); if (!pathbuf) { retval = -ENOMEM; goto out_unmark; }
if (close_on_exec(fd, rcu_dereference_raw(current->files->fdt))) bprm->interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE; bprm->filename = pathbuf; }
bprm->interp = bprm->filename;
retval = bprm_mm_init(bprm); if (retval) goto out_unmark;
bprm->argc = count(argv, MAX_ARG_STRINGS); if ((retval = bprm->argc) < 0) goto out;
bprm->envc = count(envp, MAX_ARG_STRINGS); if ((retval = bprm->envc) < 0) goto out;
retval = prepare_binprm(bprm); if (retval < 0) goto out;
retval = copy_strings_kernel(1, &bprm->filename, bprm); if (retval < 0) goto out;
bprm->exec = bprm->p; retval = copy_strings(bprm->envc, envp, bprm); if (retval < 0) goto out;
retval = copy_strings(bprm->argc, argv, bprm); if (retval < 0) goto out;
would_dump(bprm, bprm->file);
retval = exec_binprm(bprm); if (retval < 0) goto out;
current->fs->in_exec = 0; current->in_execve = 0; acct_update_integrals(current); task_numa_free(current); free_bprm(bprm); kfree(pathbuf); putname(filename); if (displaced) put_files_struct(displaced); return retval;
out: if (bprm->mm) { acct_arg_size(bprm, 0); mmput(bprm->mm); }
out_unmark: current->fs->in_exec = 0; current->in_execve = 0;
out_free: free_bprm(bprm); kfree(pathbuf);
out_files: if (displaced) reset_files_struct(displaced); out_ret: putname(filename); return retval; }
|