exec.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013
  1. /*
  2. * linux/fs/exec.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * #!-checking implemented by tytso.
  8. */
  9. /*
  10. * Demand-loading implemented 01.12.91 - no need to read anything but
  11. * the header into memory. The inode of the executable is put into
  12. * "current->executable", and page faults do the actual loading. Clean.
  13. *
  14. * Once more I can proudly say that linux stood up to being changed: it
  15. * was less than 2 hours work to get demand-loading completely implemented.
  16. *
  17. * Demand loading changed July 1993 by Eric Youngdale. Use mmap instead,
  18. * current->executable is only used by the procfs. This allows a dispatch
  19. * table to check for several different types of binary formats. We keep
  20. * trying until we recognize the file or we run out of supported binary
  21. * formats.
  22. */
  23. #include <linux/slab.h>
  24. #include <linux/file.h>
  25. #include <linux/fdtable.h>
  26. #include <linux/mm.h>
  27. #include <linux/vmacache.h>
  28. #include <linux/stat.h>
  29. #include <linux/fcntl.h>
  30. #include <linux/swap.h>
  31. #include <linux/string.h>
  32. #include <linux/init.h>
  33. #include <linux/sched/mm.h>
  34. #include <linux/sched/coredump.h>
  35. #include <linux/sched/signal.h>
  36. #include <linux/sched/numa_balancing.h>
  37. #include <linux/sched/task.h>
  38. #include <linux/pagemap.h>
  39. #include <linux/perf_event.h>
  40. #include <linux/highmem.h>
  41. #include <linux/spinlock.h>
  42. #include <linux/key.h>
  43. #include <linux/personality.h>
  44. #include <linux/binfmts.h>
  45. #include <linux/utsname.h>
  46. #include <linux/pid_namespace.h>
  47. #include <linux/module.h>
  48. #include <linux/namei.h>
  49. #include <linux/mount.h>
  50. #include <linux/security.h>
  51. #include <linux/syscalls.h>
  52. #include <linux/tsacct_kern.h>
  53. #include <linux/cn_proc.h>
  54. #include <linux/audit.h>
  55. #include <linux/tracehook.h>
  56. #include <linux/kmod.h>
  57. #include <linux/fsnotify.h>
  58. #include <linux/fs_struct.h>
  59. #include <linux/pipe_fs_i.h>
  60. #include <linux/oom.h>
  61. #include <linux/compat.h>
  62. #include <linux/vmalloc.h>
  63. #include <linux/uaccess.h>
  64. #include <asm/mmu_context.h>
  65. #include <asm/tlb.h>
  66. #include <trace/events/task.h>
  67. #include "internal.h"
  68. #include <trace/events/sched.h>
  69. int suid_dumpable = 0;
  70. static LIST_HEAD(formats);
  71. static DEFINE_RWLOCK(binfmt_lock);
  72. void __register_binfmt(struct linux_binfmt * fmt, int insert)
  73. {
  74. BUG_ON(!fmt);
  75. if (WARN_ON(!fmt->load_binary))
  76. return;
  77. write_lock(&binfmt_lock);
  78. insert ? list_add(&fmt->lh, &formats) :
  79. list_add_tail(&fmt->lh, &formats);
  80. write_unlock(&binfmt_lock);
  81. }
  82. EXPORT_SYMBOL(__register_binfmt);
  83. void unregister_binfmt(struct linux_binfmt * fmt)
  84. {
  85. write_lock(&binfmt_lock);
  86. list_del(&fmt->lh);
  87. write_unlock(&binfmt_lock);
  88. }
  89. EXPORT_SYMBOL(unregister_binfmt);
  90. static inline void put_binfmt(struct linux_binfmt * fmt)
  91. {
  92. module_put(fmt->module);
  93. }
  94. bool path_noexec(const struct path *path)
  95. {
  96. return (path->mnt->mnt_flags & MNT_NOEXEC) ||
  97. (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
  98. }
  99. #ifdef CONFIG_USELIB
  100. /*
  101. * Note that a shared library must be both readable and executable due to
  102. * security reasons.
  103. *
  104. * Also note that we take the address to load from from the file itself.
  105. */
  106. SYSCALL_DEFINE1(uselib, const char __user *, library)
  107. {
  108. struct linux_binfmt *fmt;
  109. struct file *file;
  110. struct filename *tmp = getname(library);
  111. int error = PTR_ERR(tmp);
  112. static const struct open_flags uselib_flags = {
  113. .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
  114. .acc_mode = MAY_READ | MAY_EXEC,
  115. .intent = LOOKUP_OPEN,
  116. .lookup_flags = LOOKUP_FOLLOW,
  117. };
  118. if (IS_ERR(tmp))
  119. goto out;
  120. file = do_filp_open(AT_FDCWD, tmp, &uselib_flags);
  121. putname(tmp);
  122. error = PTR_ERR(file);
  123. if (IS_ERR(file))
  124. goto out;
  125. error = -EINVAL;
  126. if (!S_ISREG(file_inode(file)->i_mode))
  127. goto exit;
  128. error = -EACCES;
  129. if (path_noexec(&file->f_path))
  130. goto exit;
  131. fsnotify_open(file);
  132. error = -ENOEXEC;
  133. read_lock(&binfmt_lock);
  134. list_for_each_entry(fmt, &formats, lh) {
  135. if (!fmt->load_shlib)
  136. continue;
  137. if (!try_module_get(fmt->module))
  138. continue;
  139. read_unlock(&binfmt_lock);
  140. error = fmt->load_shlib(file);
  141. read_lock(&binfmt_lock);
  142. put_binfmt(fmt);
  143. if (error != -ENOEXEC)
  144. break;
  145. }
  146. read_unlock(&binfmt_lock);
  147. exit:
  148. fput(file);
  149. out:
  150. return error;
  151. }
  152. #endif /* #ifdef CONFIG_USELIB */
  153. #ifdef CONFIG_MMU
  154. /*
  155. * The nascent bprm->mm is not visible until exec_mmap() but it can
  156. * use a lot of memory, account these pages in current->mm temporary
  157. * for oom_badness()->get_mm_rss(). Once exec succeeds or fails, we
  158. * change the counter back via acct_arg_size(0).
  159. */
  160. static void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
  161. {
  162. struct mm_struct *mm = current->mm;
  163. long diff = (long)(pages - bprm->vma_pages);
  164. if (!mm || !diff)
  165. return;
  166. bprm->vma_pages = pages;
  167. add_mm_counter(mm, MM_ANONPAGES, diff);
  168. }
  169. static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
  170. int write)
  171. {
  172. struct page *page;
  173. int ret;
  174. unsigned int gup_flags = FOLL_FORCE;
  175. #ifdef CONFIG_STACK_GROWSUP
  176. if (write) {
  177. ret = expand_downwards(bprm->vma, pos);
  178. if (ret < 0)
  179. return NULL;
  180. }
  181. #endif
  182. if (write)
  183. gup_flags |= FOLL_WRITE;
  184. /*
  185. * We are doing an exec(). 'current' is the process
  186. * doing the exec and bprm->mm is the new process's mm.
  187. */
  188. ret = get_user_pages_remote(current, bprm->mm, pos, 1, gup_flags,
  189. &page, NULL, NULL);
  190. if (ret <= 0)
  191. return NULL;
  192. if (write) {
  193. unsigned long size = bprm->vma->vm_end - bprm->vma->vm_start;
  194. unsigned long ptr_size, limit;
  195. /*
  196. * Since the stack will hold pointers to the strings, we
  197. * must account for them as well.
  198. *
  199. * The size calculation is the entire vma while each arg page is
  200. * built, so each time we get here it's calculating how far it
  201. * is currently (rather than each call being just the newly
  202. * added size from the arg page). As a result, we need to
  203. * always add the entire size of the pointers, so that on the
  204. * last call to get_arg_page() we'll actually have the entire
  205. * correct size.
  206. */
  207. ptr_size = (bprm->argc + bprm->envc) * sizeof(void *);
  208. if (ptr_size > ULONG_MAX - size)
  209. goto fail;
  210. size += ptr_size;
  211. acct_arg_size(bprm, size / PAGE_SIZE);
  212. /*
  213. * We've historically supported up to 32 pages (ARG_MAX)
  214. * of argument strings even with small stacks
  215. */
  216. if (size <= ARG_MAX)
  217. return page;
  218. /*
  219. * Limit to 1/4 of the max stack size or 3/4 of _STK_LIM
  220. * (whichever is smaller) for the argv+env strings.
  221. * This ensures that:
  222. * - the remaining binfmt code will not run out of stack space,
  223. * - the program will have a reasonable amount of stack left
  224. * to work from.
  225. */
  226. limit = _STK_LIM / 4 * 3;
  227. limit = min(limit, bprm->rlim_stack.rlim_cur / 4);
  228. if (size > limit)
  229. goto fail;
  230. }
  231. return page;
  232. fail:
  233. put_page(page);
  234. return NULL;
  235. }
  236. static void put_arg_page(struct page *page)
  237. {
  238. put_page(page);
  239. }
  240. static void free_arg_pages(struct linux_binprm *bprm)
  241. {
  242. }
  243. static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos,
  244. struct page *page)
  245. {
  246. flush_cache_page(bprm->vma, pos, page_to_pfn(page));
  247. }
  248. static int __bprm_mm_init(struct linux_binprm *bprm)
  249. {
  250. int err;
  251. struct vm_area_struct *vma = NULL;
  252. struct mm_struct *mm = bprm->mm;
  253. bprm->vma = vma = vm_area_alloc(mm);
  254. if (!vma)
  255. return -ENOMEM;
  256. vma_set_anonymous(vma);
  257. if (down_write_killable(&mm->mmap_sem)) {
  258. err = -EINTR;
  259. goto err_free;
  260. }
  261. /*
  262. * Place the stack at the largest stack address the architecture
  263. * supports. Later, we'll move this to an appropriate place. We don't
  264. * use STACK_TOP because that can depend on attributes which aren't
  265. * configured yet.
  266. */
  267. BUILD_BUG_ON(VM_STACK_FLAGS & VM_STACK_INCOMPLETE_SETUP);
  268. vma->vm_end = STACK_TOP_MAX;
  269. vma->vm_start = vma->vm_end - PAGE_SIZE;
  270. vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
  271. vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
  272. err = insert_vm_struct(mm, vma);
  273. if (err)
  274. goto err;
  275. mm->stack_vm = mm->total_vm = 1;
  276. arch_bprm_mm_init(mm, vma);
  277. up_write(&mm->mmap_sem);
  278. bprm->p = vma->vm_end - sizeof(void *);
  279. return 0;
  280. err:
  281. up_write(&mm->mmap_sem);
  282. err_free:
  283. bprm->vma = NULL;
  284. vm_area_free(vma);
  285. return err;
  286. }
  287. static bool valid_arg_len(struct linux_binprm *bprm, long len)
  288. {
  289. return len <= MAX_ARG_STRLEN;
  290. }
  291. #else
  292. static inline void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
  293. {
  294. }
  295. static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
  296. int write)
  297. {
  298. struct page *page;
  299. page = bprm->page[pos / PAGE_SIZE];
  300. if (!page && write) {
  301. page = alloc_page(GFP_HIGHUSER|__GFP_ZERO);
  302. if (!page)
  303. return NULL;
  304. bprm->page[pos / PAGE_SIZE] = page;
  305. }
  306. return page;
  307. }
  308. static void put_arg_page(struct page *page)
  309. {
  310. }
  311. static void free_arg_page(struct linux_binprm *bprm, int i)
  312. {
  313. if (bprm->page[i]) {
  314. __free_page(bprm->page[i]);
  315. bprm->page[i] = NULL;
  316. }
  317. }
  318. static void free_arg_pages(struct linux_binprm *bprm)
  319. {
  320. int i;
  321. for (i = 0; i < MAX_ARG_PAGES; i++)
  322. free_arg_page(bprm, i);
  323. }
  324. static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos,
  325. struct page *page)
  326. {
  327. }
  328. static int __bprm_mm_init(struct linux_binprm *bprm)
  329. {
  330. bprm->p = PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *);
  331. return 0;
  332. }
  333. static bool valid_arg_len(struct linux_binprm *bprm, long len)
  334. {
  335. return len <= bprm->p;
  336. }
  337. #endif /* CONFIG_MMU */
  338. /*
  339. * Create a new mm_struct and populate it with a temporary stack
  340. * vm_area_struct. We don't have enough context at this point to set the stack
  341. * flags, permissions, and offset, so we use temporary values. We'll update
  342. * them later in setup_arg_pages().
  343. */
  344. static int bprm_mm_init(struct linux_binprm *bprm)
  345. {
  346. int err;
  347. struct mm_struct *mm = NULL;
  348. bprm->mm = mm = mm_alloc();
  349. err = -ENOMEM;
  350. if (!mm)
  351. goto err;
  352. /* Save current stack limit for all calculations made during exec. */
  353. task_lock(current->group_leader);
  354. bprm->rlim_stack = current->signal->rlim[RLIMIT_STACK];
  355. task_unlock(current->group_leader);
  356. err = __bprm_mm_init(bprm);
  357. if (err)
  358. goto err;
  359. return 0;
  360. err:
  361. if (mm) {
  362. bprm->mm = NULL;
  363. mmdrop(mm);
  364. }
  365. return err;
  366. }
  367. struct user_arg_ptr {
  368. #ifdef CONFIG_COMPAT
  369. bool is_compat;
  370. #endif
  371. union {
  372. const char __user *const __user *native;
  373. #ifdef CONFIG_COMPAT
  374. const compat_uptr_t __user *compat;
  375. #endif
  376. } ptr;
  377. };
  378. static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
  379. {
  380. const char __user *native;
  381. #ifdef CONFIG_COMPAT
  382. if (unlikely(argv.is_compat)) {
  383. compat_uptr_t compat;
  384. if (get_user(compat, argv.ptr.compat + nr))
  385. return ERR_PTR(-EFAULT);
  386. return compat_ptr(compat);
  387. }
  388. #endif
  389. if (get_user(native, argv.ptr.native + nr))
  390. return ERR_PTR(-EFAULT);
  391. return native;
  392. }
  393. /*
  394. * count() counts the number of strings in array ARGV.
  395. */
  396. static int count(struct user_arg_ptr argv, int max)
  397. {
  398. int i = 0;
  399. if (argv.ptr.native != NULL) {
  400. for (;;) {
  401. const char __user *p = get_user_arg_ptr(argv, i);
  402. if (!p)
  403. break;
  404. if (IS_ERR(p))
  405. return -EFAULT;
  406. if (i >= max)
  407. return -E2BIG;
  408. ++i;
  409. if (fatal_signal_pending(current))
  410. return -ERESTARTNOHAND;
  411. cond_resched();
  412. }
  413. }
  414. return i;
  415. }
  416. /*
  417. * 'copy_strings()' copies argument/environment strings from the old
  418. * processes's memory to the new process's stack. The call to get_user_pages()
  419. * ensures the destination page is created and not swapped out.
  420. */
  421. static int copy_strings(int argc, struct user_arg_ptr argv,
  422. struct linux_binprm *bprm)
  423. {
  424. struct page *kmapped_page = NULL;
  425. char *kaddr = NULL;
  426. unsigned long kpos = 0;
  427. int ret;
  428. while (argc-- > 0) {
  429. const char __user *str;
  430. int len;
  431. unsigned long pos;
  432. ret = -EFAULT;
  433. str = get_user_arg_ptr(argv, argc);
  434. if (IS_ERR(str))
  435. goto out;
  436. len = strnlen_user(str, MAX_ARG_STRLEN);
  437. if (!len)
  438. goto out;
  439. ret = -E2BIG;
  440. if (!valid_arg_len(bprm, len))
  441. goto out;
  442. /* We're going to work our way backwords. */
  443. pos = bprm->p;
  444. str += len;
  445. bprm->p -= len;
  446. while (len > 0) {
  447. int offset, bytes_to_copy;
  448. if (fatal_signal_pending(current)) {
  449. ret = -ERESTARTNOHAND;
  450. goto out;
  451. }
  452. cond_resched();
  453. offset = pos % PAGE_SIZE;
  454. if (offset == 0)
  455. offset = PAGE_SIZE;
  456. bytes_to_copy = offset;
  457. if (bytes_to_copy > len)
  458. bytes_to_copy = len;
  459. offset -= bytes_to_copy;
  460. pos -= bytes_to_copy;
  461. str -= bytes_to_copy;
  462. len -= bytes_to_copy;
  463. if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
  464. struct page *page;
  465. page = get_arg_page(bprm, pos, 1);
  466. if (!page) {
  467. ret = -E2BIG;
  468. goto out;
  469. }
  470. if (kmapped_page) {
  471. flush_kernel_dcache_page(kmapped_page);
  472. kunmap(kmapped_page);
  473. put_arg_page(kmapped_page);
  474. }
  475. kmapped_page = page;
  476. kaddr = kmap(kmapped_page);
  477. kpos = pos & PAGE_MASK;
  478. flush_arg_page(bprm, kpos, kmapped_page);
  479. }
  480. if (copy_from_user(kaddr+offset, str, bytes_to_copy)) {
  481. ret = -EFAULT;
  482. goto out;
  483. }
  484. }
  485. }
  486. ret = 0;
  487. out:
  488. if (kmapped_page) {
  489. flush_kernel_dcache_page(kmapped_page);
  490. kunmap(kmapped_page);
  491. put_arg_page(kmapped_page);
  492. }
  493. return ret;
  494. }
  495. /*
  496. * Like copy_strings, but get argv and its values from kernel memory.
  497. */
  498. int copy_strings_kernel(int argc, const char *const *__argv,
  499. struct linux_binprm *bprm)
  500. {
  501. int r;
  502. mm_segment_t oldfs = get_fs();
  503. struct user_arg_ptr argv = {
  504. .ptr.native = (const char __user *const __user *)__argv,
  505. };
  506. set_fs(KERNEL_DS);
  507. r = copy_strings(argc, argv, bprm);
  508. set_fs(oldfs);
  509. return r;
  510. }
  511. EXPORT_SYMBOL(copy_strings_kernel);
  512. #ifdef CONFIG_MMU
  513. /*
  514. * During bprm_mm_init(), we create a temporary stack at STACK_TOP_MAX. Once
  515. * the binfmt code determines where the new stack should reside, we shift it to
  516. * its final location. The process proceeds as follows:
  517. *
  518. * 1) Use shift to calculate the new vma endpoints.
  519. * 2) Extend vma to cover both the old and new ranges. This ensures the
  520. * arguments passed to subsequent functions are consistent.
  521. * 3) Move vma's page tables to the new range.
  522. * 4) Free up any cleared pgd range.
  523. * 5) Shrink the vma to cover only the new range.
  524. */
  525. static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
  526. {
  527. struct mm_struct *mm = vma->vm_mm;
  528. unsigned long old_start = vma->vm_start;
  529. unsigned long old_end = vma->vm_end;
  530. unsigned long length = old_end - old_start;
  531. unsigned long new_start = old_start - shift;
  532. unsigned long new_end = old_end - shift;
  533. struct mmu_gather tlb;
  534. BUG_ON(new_start > new_end);
  535. /*
  536. * ensure there are no vmas between where we want to go
  537. * and where we are
  538. */
  539. if (vma != find_vma(mm, new_start))
  540. return -EFAULT;
  541. /*
  542. * cover the whole range: [new_start, old_end)
  543. */
  544. if (vma_adjust(vma, new_start, old_end, vma->vm_pgoff, NULL))
  545. return -ENOMEM;
  546. /*
  547. * move the page tables downwards, on failure we rely on
  548. * process cleanup to remove whatever mess we made.
  549. */
  550. if (length != move_page_tables(vma, old_start,
  551. vma, new_start, length, false))
  552. return -ENOMEM;
  553. lru_add_drain();
  554. tlb_gather_mmu(&tlb, mm, old_start, old_end);
  555. if (new_end > old_start) {
  556. /*
  557. * when the old and new regions overlap clear from new_end.
  558. */
  559. free_pgd_range(&tlb, new_end, old_end, new_end,
  560. vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
  561. } else {
  562. /*
  563. * otherwise, clean from old_start; this is done to not touch
  564. * the address space in [new_end, old_start) some architectures
  565. * have constraints on va-space that make this illegal (IA64) -
  566. * for the others its just a little faster.
  567. */
  568. free_pgd_range(&tlb, old_start, old_end, new_end,
  569. vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
  570. }
  571. tlb_finish_mmu(&tlb, old_start, old_end);
  572. /*
  573. * Shrink the vma to just the new range. Always succeeds.
  574. */
  575. vma_adjust(vma, new_start, new_end, vma->vm_pgoff, NULL);
  576. return 0;
  577. }
  578. /*
  579. * Finalizes the stack vm_area_struct. The flags and permissions are updated,
  580. * the stack is optionally relocated, and some extra space is added.
  581. */
  582. int setup_arg_pages(struct linux_binprm *bprm,
  583. unsigned long stack_top,
  584. int executable_stack)
  585. {
  586. unsigned long ret;
  587. unsigned long stack_shift;
  588. struct mm_struct *mm = current->mm;
  589. struct vm_area_struct *vma = bprm->vma;
  590. struct vm_area_struct *prev = NULL;
  591. unsigned long vm_flags;
  592. unsigned long stack_base;
  593. unsigned long stack_size;
  594. unsigned long stack_expand;
  595. unsigned long rlim_stack;
  596. #ifdef CONFIG_STACK_GROWSUP
  597. /* Limit stack size */
  598. stack_base = bprm->rlim_stack.rlim_max;
  599. if (stack_base > STACK_SIZE_MAX)
  600. stack_base = STACK_SIZE_MAX;
  601. /* Add space for stack randomization. */
  602. stack_base += (STACK_RND_MASK << PAGE_SHIFT);
  603. /* Make sure we didn't let the argument array grow too large. */
  604. if (vma->vm_end - vma->vm_start > stack_base)
  605. return -ENOMEM;
  606. stack_base = PAGE_ALIGN(stack_top - stack_base);
  607. stack_shift = vma->vm_start - stack_base;
  608. mm->arg_start = bprm->p - stack_shift;
  609. bprm->p = vma->vm_end - stack_shift;
  610. #else
  611. stack_top = arch_align_stack(stack_top);
  612. stack_top = PAGE_ALIGN(stack_top);
  613. if (unlikely(stack_top < mmap_min_addr) ||
  614. unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
  615. return -ENOMEM;
  616. stack_shift = vma->vm_end - stack_top;
  617. bprm->p -= stack_shift;
  618. mm->arg_start = bprm->p;
  619. #endif
  620. if (bprm->loader)
  621. bprm->loader -= stack_shift;
  622. bprm->exec -= stack_shift;
  623. if (down_write_killable(&mm->mmap_sem))
  624. return -EINTR;
  625. vm_flags = VM_STACK_FLAGS;
  626. /*
  627. * Adjust stack execute permissions; explicitly enable for
  628. * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
  629. * (arch default) otherwise.
  630. */
  631. if (unlikely(executable_stack == EXSTACK_ENABLE_X))
  632. vm_flags |= VM_EXEC;
  633. else if (executable_stack == EXSTACK_DISABLE_X)
  634. vm_flags &= ~VM_EXEC;
  635. vm_flags |= mm->def_flags;
  636. vm_flags |= VM_STACK_INCOMPLETE_SETUP;
  637. ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
  638. vm_flags);
  639. if (ret)
  640. goto out_unlock;
  641. BUG_ON(prev != vma);
  642. /* Move stack pages down in memory. */
  643. if (stack_shift) {
  644. ret = shift_arg_pages(vma, stack_shift);
  645. if (ret)
  646. goto out_unlock;
  647. }
  648. /* mprotect_fixup is overkill to remove the temporary stack flags */
  649. vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
  650. stack_expand = 131072UL; /* randomly 32*4k (or 2*64k) pages */
  651. stack_size = vma->vm_end - vma->vm_start;
  652. /*
  653. * Align this down to a page boundary as expand_stack
  654. * will align it up.
  655. */
  656. rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK;
  657. #ifdef CONFIG_STACK_GROWSUP
  658. if (stack_size + stack_expand > rlim_stack)
  659. stack_base = vma->vm_start + rlim_stack;
  660. else
  661. stack_base = vma->vm_end + stack_expand;
  662. #else
  663. if (stack_size + stack_expand > rlim_stack)
  664. stack_base = vma->vm_end - rlim_stack;
  665. else
  666. stack_base = vma->vm_start - stack_expand;
  667. #endif
  668. current->mm->start_stack = bprm->p;
  669. ret = expand_stack(vma, stack_base);
  670. if (ret)
  671. ret = -EFAULT;
  672. out_unlock:
  673. up_write(&mm->mmap_sem);
  674. return ret;
  675. }
  676. EXPORT_SYMBOL(setup_arg_pages);
  677. #else
  678. /*
  679. * Transfer the program arguments and environment from the holding pages
  680. * onto the stack. The provided stack pointer is adjusted accordingly.
  681. */
  682. int transfer_args_to_stack(struct linux_binprm *bprm,
  683. unsigned long *sp_location)
  684. {
  685. unsigned long index, stop, sp;
  686. int ret = 0;
  687. stop = bprm->p >> PAGE_SHIFT;
  688. sp = *sp_location;
  689. for (index = MAX_ARG_PAGES - 1; index >= stop; index--) {
  690. unsigned int offset = index == stop ? bprm->p & ~PAGE_MASK : 0;
  691. char *src = kmap(bprm->page[index]) + offset;
  692. sp -= PAGE_SIZE - offset;
  693. if (copy_to_user((void *) sp, src, PAGE_SIZE - offset) != 0)
  694. ret = -EFAULT;
  695. kunmap(bprm->page[index]);
  696. if (ret)
  697. goto out;
  698. }
  699. *sp_location = sp;
  700. out:
  701. return ret;
  702. }
  703. EXPORT_SYMBOL(transfer_args_to_stack);
  704. #endif /* CONFIG_MMU */
  705. static struct file *do_open_execat(int fd, struct filename *name, int flags)
  706. {
  707. struct file *file;
  708. int err;
  709. struct open_flags open_exec_flags = {
  710. .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
  711. .acc_mode = MAY_EXEC,
  712. .intent = LOOKUP_OPEN,
  713. .lookup_flags = LOOKUP_FOLLOW,
  714. };
  715. if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
  716. return ERR_PTR(-EINVAL);
  717. if (flags & AT_SYMLINK_NOFOLLOW)
  718. open_exec_flags.lookup_flags &= ~LOOKUP_FOLLOW;
  719. if (flags & AT_EMPTY_PATH)
  720. open_exec_flags.lookup_flags |= LOOKUP_EMPTY;
  721. file = do_filp_open(fd, name, &open_exec_flags);
  722. if (IS_ERR(file))
  723. goto out;
  724. err = -EACCES;
  725. if (!S_ISREG(file_inode(file)->i_mode))
  726. goto exit;
  727. if (path_noexec(&file->f_path))
  728. goto exit;
  729. err = deny_write_access(file);
  730. if (err)
  731. goto exit;
  732. if (name->name[0] != '\0')
  733. fsnotify_open(file);
  734. out:
  735. return file;
  736. exit:
  737. fput(file);
  738. return ERR_PTR(err);
  739. }
  740. struct file *open_exec(const char *name)
  741. {
  742. struct filename *filename = getname_kernel(name);
  743. struct file *f = ERR_CAST(filename);
  744. if (!IS_ERR(filename)) {
  745. f = do_open_execat(AT_FDCWD, filename, 0);
  746. putname(filename);
  747. }
  748. return f;
  749. }
  750. EXPORT_SYMBOL(open_exec);
  751. int kernel_read_file(struct file *file, void **buf, loff_t *size,
  752. loff_t max_size, enum kernel_read_file_id id)
  753. {
  754. loff_t i_size, pos;
  755. ssize_t bytes = 0;
  756. int ret;
  757. if (!S_ISREG(file_inode(file)->i_mode) || max_size < 0)
  758. return -EINVAL;
  759. ret = deny_write_access(file);
  760. if (ret)
  761. return ret;
  762. ret = security_kernel_read_file(file, id);
  763. if (ret)
  764. goto out;
  765. i_size = i_size_read(file_inode(file));
  766. if (max_size > 0 && i_size > max_size) {
  767. ret = -EFBIG;
  768. goto out;
  769. }
  770. if (i_size <= 0) {
  771. ret = -EINVAL;
  772. goto out;
  773. }
  774. if (id != READING_FIRMWARE_PREALLOC_BUFFER)
  775. *buf = vmalloc(i_size);
  776. if (!*buf) {
  777. ret = -ENOMEM;
  778. goto out;
  779. }
  780. pos = 0;
  781. while (pos < i_size) {
  782. bytes = kernel_read(file, *buf + pos, i_size - pos, &pos);
  783. if (bytes < 0) {
  784. ret = bytes;
  785. goto out_free;
  786. }
  787. if (bytes == 0)
  788. break;
  789. }
  790. if (pos != i_size) {
  791. ret = -EIO;
  792. goto out_free;
  793. }
  794. ret = security_kernel_post_read_file(file, *buf, i_size, id);
  795. if (!ret)
  796. *size = pos;
  797. out_free:
  798. if (ret < 0) {
  799. if (id != READING_FIRMWARE_PREALLOC_BUFFER) {
  800. vfree(*buf);
  801. *buf = NULL;
  802. }
  803. }
  804. out:
  805. allow_write_access(file);
  806. return ret;
  807. }
  808. EXPORT_SYMBOL_GPL(kernel_read_file);
  809. int kernel_read_file_from_path(const char *path, void **buf, loff_t *size,
  810. loff_t max_size, enum kernel_read_file_id id)
  811. {
  812. struct file *file;
  813. int ret;
  814. if (!path || !*path)
  815. return -EINVAL;
  816. file = filp_open(path, O_RDONLY, 0);
  817. if (IS_ERR(file))
  818. return PTR_ERR(file);
  819. ret = kernel_read_file(file, buf, size, max_size, id);
  820. fput(file);
  821. return ret;
  822. }
  823. EXPORT_SYMBOL_GPL(kernel_read_file_from_path);
  824. int kernel_read_file_from_fd(int fd, void **buf, loff_t *size, loff_t max_size,
  825. enum kernel_read_file_id id)
  826. {
  827. struct fd f = fdget(fd);
  828. int ret = -EBADF;
  829. if (!f.file)
  830. goto out;
  831. ret = kernel_read_file(f.file, buf, size, max_size, id);
  832. out:
  833. fdput(f);
  834. return ret;
  835. }
  836. EXPORT_SYMBOL_GPL(kernel_read_file_from_fd);
  837. ssize_t read_code(struct file *file, unsigned long addr, loff_t pos, size_t len)
  838. {
  839. ssize_t res = vfs_read(file, (void __user *)addr, len, &pos);
  840. if (res > 0)
  841. flush_icache_range(addr, addr + len);
  842. return res;
  843. }
  844. EXPORT_SYMBOL(read_code);
  845. static int exec_mmap(struct mm_struct *mm)
  846. {
  847. struct task_struct *tsk;
  848. struct mm_struct *old_mm, *active_mm;
  849. /* Notify parent that we're no longer interested in the old VM */
  850. tsk = current;
  851. old_mm = current->mm;
  852. exec_mm_release(tsk, old_mm);
  853. if (old_mm) {
  854. sync_mm_rss(old_mm);
  855. /*
  856. * Make sure that if there is a core dump in progress
  857. * for the old mm, we get out and die instead of going
  858. * through with the exec. We must hold mmap_sem around
  859. * checking core_state and changing tsk->mm.
  860. */
  861. down_read(&old_mm->mmap_sem);
  862. if (unlikely(old_mm->core_state)) {
  863. up_read(&old_mm->mmap_sem);
  864. return -EINTR;
  865. }
  866. }
  867. task_lock(tsk);
  868. local_irq_disable();
  869. active_mm = tsk->active_mm;
  870. tsk->active_mm = mm;
  871. tsk->mm = mm;
  872. /*
  873. * This prevents preemption while active_mm is being loaded and
  874. * it and mm are being updated, which could cause problems for
  875. * lazy tlb mm refcounting when these are updated by context
  876. * switches. Not all architectures can handle irqs off over
  877. * activate_mm yet.
  878. */
  879. if (!IS_ENABLED(CONFIG_ARCH_WANT_IRQS_OFF_ACTIVATE_MM))
  880. local_irq_enable();
  881. activate_mm(active_mm, mm);
  882. if (IS_ENABLED(CONFIG_ARCH_WANT_IRQS_OFF_ACTIVATE_MM))
  883. local_irq_enable();
  884. tsk->mm->vmacache_seqnum = 0;
  885. vmacache_flush(tsk);
  886. task_unlock(tsk);
  887. if (old_mm) {
  888. up_read(&old_mm->mmap_sem);
  889. BUG_ON(active_mm != old_mm);
  890. setmax_mm_hiwater_rss(&tsk->signal->maxrss, old_mm);
  891. mm_update_next_owner(old_mm);
  892. mmput(old_mm);
  893. return 0;
  894. }
  895. mmdrop(active_mm);
  896. return 0;
  897. }
  898. /*
  899. * This function makes sure the current process has its own signal table,
  900. * so that flush_signal_handlers can later reset the handlers without
  901. * disturbing other processes. (Other processes might share the signal
  902. * table via the CLONE_SIGHAND option to clone().)
  903. */
  904. static int de_thread(struct task_struct *tsk)
  905. {
  906. struct signal_struct *sig = tsk->signal;
  907. struct sighand_struct *oldsighand = tsk->sighand;
  908. spinlock_t *lock = &oldsighand->siglock;
  909. if (thread_group_empty(tsk))
  910. goto no_thread_group;
  911. /*
  912. * Kill all other threads in the thread group.
  913. */
  914. spin_lock_irq(lock);
  915. if (signal_group_exit(sig)) {
  916. /*
  917. * Another group action in progress, just
  918. * return so that the signal is processed.
  919. */
  920. spin_unlock_irq(lock);
  921. return -EAGAIN;
  922. }
  923. sig->group_exit_task = tsk;
  924. sig->notify_count = zap_other_threads(tsk);
  925. if (!thread_group_leader(tsk))
  926. sig->notify_count--;
  927. while (sig->notify_count) {
  928. __set_current_state(TASK_KILLABLE);
  929. spin_unlock_irq(lock);
  930. schedule();
  931. if (unlikely(__fatal_signal_pending(tsk)))
  932. goto killed;
  933. spin_lock_irq(lock);
  934. }
  935. spin_unlock_irq(lock);
  936. /*
  937. * At this point all other threads have exited, all we have to
  938. * do is to wait for the thread group leader to become inactive,
  939. * and to assume its PID:
  940. */
  941. if (!thread_group_leader(tsk)) {
  942. struct task_struct *leader = tsk->group_leader;
  943. for (;;) {
  944. cgroup_threadgroup_change_begin(tsk);
  945. write_lock_irq(&tasklist_lock);
  946. /*
  947. * Do this under tasklist_lock to ensure that
  948. * exit_notify() can't miss ->group_exit_task
  949. */
  950. sig->notify_count = -1;
  951. if (likely(leader->exit_state))
  952. break;
  953. __set_current_state(TASK_KILLABLE);
  954. write_unlock_irq(&tasklist_lock);
  955. cgroup_threadgroup_change_end(tsk);
  956. schedule();
  957. if (unlikely(__fatal_signal_pending(tsk)))
  958. goto killed;
  959. }
  960. /*
  961. * The only record we have of the real-time age of a
  962. * process, regardless of execs it's done, is start_time.
  963. * All the past CPU time is accumulated in signal_struct
  964. * from sister threads now dead. But in this non-leader
  965. * exec, nothing survives from the original leader thread,
  966. * whose birth marks the true age of this process now.
  967. * When we take on its identity by switching to its PID, we
  968. * also take its birthdate (always earlier than our own).
  969. */
  970. tsk->start_time = leader->start_time;
  971. tsk->real_start_time = leader->real_start_time;
  972. BUG_ON(!same_thread_group(leader, tsk));
  973. BUG_ON(has_group_leader_pid(tsk));
  974. /*
  975. * An exec() starts a new thread group with the
  976. * TGID of the previous thread group. Rehash the
  977. * two threads with a switched PID, and release
  978. * the former thread group leader:
  979. */
  980. /* Become a process group leader with the old leader's pid.
  981. * The old leader becomes a thread of the this thread group.
  982. * Note: The old leader also uses this pid until release_task
  983. * is called. Odd but simple and correct.
  984. */
  985. tsk->pid = leader->pid;
  986. change_pid(tsk, PIDTYPE_PID, task_pid(leader));
  987. transfer_pid(leader, tsk, PIDTYPE_TGID);
  988. transfer_pid(leader, tsk, PIDTYPE_PGID);
  989. transfer_pid(leader, tsk, PIDTYPE_SID);
  990. list_replace_rcu(&leader->tasks, &tsk->tasks);
  991. list_replace_init(&leader->sibling, &tsk->sibling);
  992. tsk->group_leader = tsk;
  993. leader->group_leader = tsk;
  994. tsk->exit_signal = SIGCHLD;
  995. leader->exit_signal = -1;
  996. BUG_ON(leader->exit_state != EXIT_ZOMBIE);
  997. leader->exit_state = EXIT_DEAD;
  998. /*
  999. * We are going to release_task()->ptrace_unlink() silently,
  1000. * the tracer can sleep in do_wait(). EXIT_DEAD guarantees
  1001. * the tracer wont't block again waiting for this thread.
  1002. */
  1003. if (unlikely(leader->ptrace))
  1004. __wake_up_parent(leader, leader->parent);
  1005. write_unlock_irq(&tasklist_lock);
  1006. cgroup_threadgroup_change_end(tsk);
  1007. release_task(leader);
  1008. }
  1009. sig->group_exit_task = NULL;
  1010. sig->notify_count = 0;
  1011. no_thread_group:
  1012. /* we have changed execution domain */
  1013. tsk->exit_signal = SIGCHLD;
  1014. #ifdef CONFIG_POSIX_TIMERS
  1015. exit_itimers(sig);
  1016. flush_itimer_signals();
  1017. #endif
  1018. if (atomic_read(&oldsighand->count) != 1) {
  1019. struct sighand_struct *newsighand;
  1020. /*
  1021. * This ->sighand is shared with the CLONE_SIGHAND
  1022. * but not CLONE_THREAD task, switch to the new one.
  1023. */
  1024. newsighand = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
  1025. if (!newsighand)
  1026. return -ENOMEM;
  1027. atomic_set(&newsighand->count, 1);
  1028. memcpy(newsighand->action, oldsighand->action,
  1029. sizeof(newsighand->action));
  1030. write_lock_irq(&tasklist_lock);
  1031. spin_lock(&oldsighand->siglock);
  1032. rcu_assign_pointer(tsk->sighand, newsighand);
  1033. spin_unlock(&oldsighand->siglock);
  1034. write_unlock_irq(&tasklist_lock);
  1035. __cleanup_sighand(oldsighand);
  1036. }
  1037. BUG_ON(!thread_group_leader(tsk));
  1038. return 0;
  1039. killed:
  1040. /* protects against exit_notify() and __exit_signal() */
  1041. read_lock(&tasklist_lock);
  1042. sig->group_exit_task = NULL;
  1043. sig->notify_count = 0;
  1044. read_unlock(&tasklist_lock);
  1045. return -EAGAIN;
  1046. }
  1047. char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk)
  1048. {
  1049. task_lock(tsk);
  1050. strncpy(buf, tsk->comm, buf_size);
  1051. task_unlock(tsk);
  1052. return buf;
  1053. }
  1054. EXPORT_SYMBOL_GPL(__get_task_comm);
  1055. /*
  1056. * These functions flushes out all traces of the currently running executable
  1057. * so that a new one can be started
  1058. */
  1059. void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec)
  1060. {
  1061. task_lock(tsk);
  1062. trace_task_rename(tsk, buf);
  1063. strlcpy(tsk->comm, buf, sizeof(tsk->comm));
  1064. task_unlock(tsk);
  1065. perf_event_comm(tsk, exec);
  1066. }
  1067. /*
  1068. * Calling this is the point of no return. None of the failures will be
  1069. * seen by userspace since either the process is already taking a fatal
  1070. * signal (via de_thread() or coredump), or will have SEGV raised
  1071. * (after exec_mmap()) by search_binary_handlers (see below).
  1072. */
  1073. int flush_old_exec(struct linux_binprm * bprm)
  1074. {
  1075. int retval;
  1076. /*
  1077. * Make sure we have a private signal table and that
  1078. * we are unassociated from the previous thread group.
  1079. */
  1080. retval = de_thread(current);
  1081. if (retval)
  1082. goto out;
  1083. /*
  1084. * Must be called _before_ exec_mmap() as bprm->mm is
  1085. * not visibile until then. This also enables the update
  1086. * to be lockless.
  1087. */
  1088. set_mm_exe_file(bprm->mm, bprm->file);
  1089. would_dump(bprm, bprm->file);
  1090. /*
  1091. * Release all of the old mmap stuff
  1092. */
  1093. acct_arg_size(bprm, 0);
  1094. retval = exec_mmap(bprm->mm);
  1095. if (retval)
  1096. goto out;
  1097. /*
  1098. * After clearing bprm->mm (to mark that current is using the
  1099. * prepared mm now), we have nothing left of the original
  1100. * process. If anything from here on returns an error, the check
  1101. * in search_binary_handler() will SEGV current.
  1102. */
  1103. bprm->mm = NULL;
  1104. set_fs(USER_DS);
  1105. current->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD |
  1106. PF_NOFREEZE | PF_NO_SETAFFINITY);
  1107. flush_thread();
  1108. current->personality &= ~bprm->per_clear;
  1109. /*
  1110. * We have to apply CLOEXEC before we change whether the process is
  1111. * dumpable (in setup_new_exec) to avoid a race with a process in userspace
  1112. * trying to access the should-be-closed file descriptors of a process
  1113. * undergoing exec(2).
  1114. */
  1115. do_close_on_exec(current->files);
  1116. return 0;
  1117. out:
  1118. return retval;
  1119. }
  1120. EXPORT_SYMBOL(flush_old_exec);
  1121. void would_dump(struct linux_binprm *bprm, struct file *file)
  1122. {
  1123. struct inode *inode = file_inode(file);
  1124. if (inode_permission(inode, MAY_READ) < 0) {
  1125. struct user_namespace *old, *user_ns;
  1126. bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
  1127. /* Ensure mm->user_ns contains the executable */
  1128. user_ns = old = bprm->mm->user_ns;
  1129. while ((user_ns != &init_user_ns) &&
  1130. !privileged_wrt_inode_uidgid(user_ns, inode))
  1131. user_ns = user_ns->parent;
  1132. if (old != user_ns) {
  1133. bprm->mm->user_ns = get_user_ns(user_ns);
  1134. put_user_ns(old);
  1135. }
  1136. }
  1137. }
  1138. EXPORT_SYMBOL(would_dump);
  1139. void setup_new_exec(struct linux_binprm * bprm)
  1140. {
  1141. /*
  1142. * Once here, prepare_binrpm() will not be called any more, so
  1143. * the final state of setuid/setgid/fscaps can be merged into the
  1144. * secureexec flag.
  1145. */
  1146. bprm->secureexec |= bprm->cap_elevated;
  1147. if (bprm->secureexec) {
  1148. /* Make sure parent cannot signal privileged process. */
  1149. current->pdeath_signal = 0;
  1150. /*
  1151. * For secureexec, reset the stack limit to sane default to
  1152. * avoid bad behavior from the prior rlimits. This has to
  1153. * happen before arch_pick_mmap_layout(), which examines
  1154. * RLIMIT_STACK, but after the point of no return to avoid
  1155. * needing to clean up the change on failure.
  1156. */
  1157. if (bprm->rlim_stack.rlim_cur > _STK_LIM)
  1158. bprm->rlim_stack.rlim_cur = _STK_LIM;
  1159. }
  1160. arch_pick_mmap_layout(current->mm, &bprm->rlim_stack);
  1161. current->sas_ss_sp = current->sas_ss_size = 0;
  1162. /*
  1163. * Figure out dumpability. Note that this checking only of current
  1164. * is wrong, but userspace depends on it. This should be testing
  1165. * bprm->secureexec instead.
  1166. */
  1167. if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP ||
  1168. !(uid_eq(current_euid(), current_uid()) &&
  1169. gid_eq(current_egid(), current_gid())))
  1170. set_dumpable(current->mm, suid_dumpable);
  1171. else
  1172. set_dumpable(current->mm, SUID_DUMP_USER);
  1173. arch_setup_new_exec();
  1174. perf_event_exec();
  1175. __set_task_comm(current, kbasename(bprm->filename), true);
  1176. /* Set the new mm task size. We have to do that late because it may
  1177. * depend on TIF_32BIT which is only updated in flush_thread() on
  1178. * some architectures like powerpc
  1179. */
  1180. current->mm->task_size = TASK_SIZE;
  1181. /* An exec changes our domain. We are no longer part of the thread
  1182. group */
  1183. WRITE_ONCE(current->self_exec_id, current->self_exec_id + 1);
  1184. flush_signal_handlers(current, 0);
  1185. }
  1186. EXPORT_SYMBOL(setup_new_exec);
  1187. /* Runs immediately before start_thread() takes over. */
  1188. void finalize_exec(struct linux_binprm *bprm)
  1189. {
  1190. /* Store any stack rlimit changes before starting thread. */
  1191. task_lock(current->group_leader);
  1192. current->signal->rlim[RLIMIT_STACK] = bprm->rlim_stack;
  1193. task_unlock(current->group_leader);
  1194. }
  1195. EXPORT_SYMBOL(finalize_exec);
  1196. /*
  1197. * Prepare credentials and lock ->cred_guard_mutex.
  1198. * install_exec_creds() commits the new creds and drops the lock.
  1199. * Or, if exec fails before, free_bprm() should release ->cred and
  1200. * and unlock.
  1201. */
  1202. int prepare_bprm_creds(struct linux_binprm *bprm)
  1203. {
  1204. if (mutex_lock_interruptible(&current->signal->cred_guard_mutex))
  1205. return -ERESTARTNOINTR;
  1206. bprm->cred = prepare_exec_creds();
  1207. if (likely(bprm->cred))
  1208. return 0;
  1209. mutex_unlock(&current->signal->cred_guard_mutex);
  1210. return -ENOMEM;
  1211. }
  1212. static void free_bprm(struct linux_binprm *bprm)
  1213. {
  1214. free_arg_pages(bprm);
  1215. if (bprm->cred) {
  1216. mutex_unlock(&current->signal->cred_guard_mutex);
  1217. abort_creds(bprm->cred);
  1218. }
  1219. if (bprm->file) {
  1220. allow_write_access(bprm->file);
  1221. fput(bprm->file);
  1222. }
  1223. /* If a binfmt changed the interp, free it. */
  1224. if (bprm->interp != bprm->filename)
  1225. kfree(bprm->interp);
  1226. kfree(bprm);
  1227. }
  1228. int bprm_change_interp(const char *interp, struct linux_binprm *bprm)
  1229. {
  1230. /* If a binfmt changed the interp, free it first. */
  1231. if (bprm->interp != bprm->filename)
  1232. kfree(bprm->interp);
  1233. bprm->interp = kstrdup(interp, GFP_KERNEL);
  1234. if (!bprm->interp)
  1235. return -ENOMEM;
  1236. return 0;
  1237. }
  1238. EXPORT_SYMBOL(bprm_change_interp);
  1239. /*
  1240. * install the new credentials for this executable
  1241. */
  1242. void install_exec_creds(struct linux_binprm *bprm)
  1243. {
  1244. security_bprm_committing_creds(bprm);
  1245. commit_creds(bprm->cred);
  1246. bprm->cred = NULL;
  1247. /*
  1248. * Disable monitoring for regular users
  1249. * when executing setuid binaries. Must
  1250. * wait until new credentials are committed
  1251. * by commit_creds() above
  1252. */
  1253. if (get_dumpable(current->mm) != SUID_DUMP_USER)
  1254. perf_event_exit_task(current);
  1255. /*
  1256. * cred_guard_mutex must be held at least to this point to prevent
  1257. * ptrace_attach() from altering our determination of the task's
  1258. * credentials; any time after this it may be unlocked.
  1259. */
  1260. security_bprm_committed_creds(bprm);
  1261. mutex_unlock(&current->signal->cred_guard_mutex);
  1262. }
  1263. EXPORT_SYMBOL(install_exec_creds);
  1264. /*
  1265. * determine how safe it is to execute the proposed program
  1266. * - the caller must hold ->cred_guard_mutex to protect against
  1267. * PTRACE_ATTACH or seccomp thread-sync
  1268. */
  1269. static void check_unsafe_exec(struct linux_binprm *bprm)
  1270. {
  1271. struct task_struct *p = current, *t;
  1272. unsigned n_fs;
  1273. if (p->ptrace)
  1274. bprm->unsafe |= LSM_UNSAFE_PTRACE;
  1275. /*
  1276. * This isn't strictly necessary, but it makes it harder for LSMs to
  1277. * mess up.
  1278. */
  1279. if (task_no_new_privs(current))
  1280. bprm->unsafe |= LSM_UNSAFE_NO_NEW_PRIVS;
  1281. t = p;
  1282. n_fs = 1;
  1283. spin_lock(&p->fs->lock);
  1284. rcu_read_lock();
  1285. while_each_thread(p, t) {
  1286. if (t->fs == p->fs)
  1287. n_fs++;
  1288. }
  1289. rcu_read_unlock();
  1290. if (p->fs->users > n_fs)
  1291. bprm->unsafe |= LSM_UNSAFE_SHARE;
  1292. else
  1293. p->fs->in_exec = 1;
  1294. spin_unlock(&p->fs->lock);
  1295. }
  1296. static void bprm_fill_uid(struct linux_binprm *bprm)
  1297. {
  1298. struct inode *inode;
  1299. unsigned int mode;
  1300. kuid_t uid;
  1301. kgid_t gid;
  1302. /*
  1303. * Since this can be called multiple times (via prepare_binprm),
  1304. * we must clear any previous work done when setting set[ug]id
  1305. * bits from any earlier bprm->file uses (for example when run
  1306. * first for a setuid script then again for its interpreter).
  1307. */
  1308. bprm->cred->euid = current_euid();
  1309. bprm->cred->egid = current_egid();
  1310. if (!mnt_may_suid(bprm->file->f_path.mnt))
  1311. return;
  1312. if (task_no_new_privs(current))
  1313. return;
  1314. inode = bprm->file->f_path.dentry->d_inode;
  1315. mode = READ_ONCE(inode->i_mode);
  1316. if (!(mode & (S_ISUID|S_ISGID)))
  1317. return;
  1318. /* Be careful if suid/sgid is set */
  1319. inode_lock(inode);
  1320. /* reload atomically mode/uid/gid now that lock held */
  1321. mode = inode->i_mode;
  1322. uid = inode->i_uid;
  1323. gid = inode->i_gid;
  1324. inode_unlock(inode);
  1325. /* We ignore suid/sgid if there are no mappings for them in the ns */
  1326. if (!kuid_has_mapping(bprm->cred->user_ns, uid) ||
  1327. !kgid_has_mapping(bprm->cred->user_ns, gid))
  1328. return;
  1329. if (mode & S_ISUID) {
  1330. bprm->per_clear |= PER_CLEAR_ON_SETID;
  1331. bprm->cred->euid = uid;
  1332. }
  1333. if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
  1334. bprm->per_clear |= PER_CLEAR_ON_SETID;
  1335. bprm->cred->egid = gid;
  1336. }
  1337. }
  1338. /*
  1339. * Fill the binprm structure from the inode.
  1340. * Check permissions, then read the first 128 (BINPRM_BUF_SIZE) bytes
  1341. *
  1342. * This may be called multiple times for binary chains (scripts for example).
  1343. */
  1344. int prepare_binprm(struct linux_binprm *bprm)
  1345. {
  1346. int retval;
  1347. loff_t pos = 0;
  1348. bprm_fill_uid(bprm);
  1349. /* fill in binprm security blob */
  1350. retval = security_bprm_set_creds(bprm);
  1351. if (retval)
  1352. return retval;
  1353. bprm->called_set_creds = 1;
  1354. memset(bprm->buf, 0, BINPRM_BUF_SIZE);
  1355. return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos);
  1356. }
  1357. EXPORT_SYMBOL(prepare_binprm);
  1358. /*
  1359. * Arguments are '\0' separated strings found at the location bprm->p
  1360. * points to; chop off the first by relocating brpm->p to right after
  1361. * the first '\0' encountered.
  1362. */
  1363. int remove_arg_zero(struct linux_binprm *bprm)
  1364. {
  1365. int ret = 0;
  1366. unsigned long offset;
  1367. char *kaddr;
  1368. struct page *page;
  1369. if (!bprm->argc)
  1370. return 0;
  1371. do {
  1372. offset = bprm->p & ~PAGE_MASK;
  1373. page = get_arg_page(bprm, bprm->p, 0);
  1374. if (!page) {
  1375. ret = -EFAULT;
  1376. goto out;
  1377. }
  1378. kaddr = kmap_atomic(page);
  1379. for (; offset < PAGE_SIZE && kaddr[offset];
  1380. offset++, bprm->p++)
  1381. ;
  1382. kunmap_atomic(kaddr);
  1383. put_arg_page(page);
  1384. } while (offset == PAGE_SIZE);
  1385. bprm->p++;
  1386. bprm->argc--;
  1387. ret = 0;
  1388. out:
  1389. return ret;
  1390. }
  1391. EXPORT_SYMBOL(remove_arg_zero);
  1392. #define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
  1393. /*
  1394. * cycle the list of binary formats handler, until one recognizes the image
  1395. */
  1396. int search_binary_handler(struct linux_binprm *bprm)
  1397. {
  1398. bool need_retry = IS_ENABLED(CONFIG_MODULES);
  1399. struct linux_binfmt *fmt;
  1400. int retval;
  1401. /* This allows 4 levels of binfmt rewrites before failing hard. */
  1402. if (bprm->recursion_depth > 5)
  1403. return -ELOOP;
  1404. retval = security_bprm_check(bprm);
  1405. if (retval)
  1406. return retval;
  1407. retval = -ENOENT;
  1408. retry:
  1409. read_lock(&binfmt_lock);
  1410. list_for_each_entry(fmt, &formats, lh) {
  1411. if (!try_module_get(fmt->module))
  1412. continue;
  1413. read_unlock(&binfmt_lock);
  1414. bprm->recursion_depth++;
  1415. retval = fmt->load_binary(bprm);
  1416. read_lock(&binfmt_lock);
  1417. put_binfmt(fmt);
  1418. bprm->recursion_depth--;
  1419. if (retval < 0 && !bprm->mm) {
  1420. /* we got to flush_old_exec() and failed after it */
  1421. read_unlock(&binfmt_lock);
  1422. force_sigsegv(SIGSEGV, current);
  1423. return retval;
  1424. }
  1425. if (retval != -ENOEXEC || !bprm->file) {
  1426. read_unlock(&binfmt_lock);
  1427. return retval;
  1428. }
  1429. }
  1430. read_unlock(&binfmt_lock);
  1431. if (need_retry) {
  1432. if (printable(bprm->buf[0]) && printable(bprm->buf[1]) &&
  1433. printable(bprm->buf[2]) && printable(bprm->buf[3]))
  1434. return retval;
  1435. if (request_module("binfmt-%04x", *(ushort *)(bprm->buf + 2)) < 0)
  1436. return retval;
  1437. need_retry = false;
  1438. goto retry;
  1439. }
  1440. return retval;
  1441. }
  1442. EXPORT_SYMBOL(search_binary_handler);
  1443. static int exec_binprm(struct linux_binprm *bprm)
  1444. {
  1445. pid_t old_pid, old_vpid;
  1446. int ret;
  1447. /* Need to fetch pid before load_binary changes it */
  1448. old_pid = current->pid;
  1449. rcu_read_lock();
  1450. old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
  1451. rcu_read_unlock();
  1452. ret = search_binary_handler(bprm);
  1453. if (ret >= 0) {
  1454. audit_bprm(bprm);
  1455. trace_sched_process_exec(current, old_pid, bprm);
  1456. ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
  1457. proc_exec_connector(current);
  1458. }
  1459. return ret;
  1460. }
  1461. /*
  1462. * sys_execve() executes a new program.
  1463. */
  1464. static int __do_execve_file(int fd, struct filename *filename,
  1465. struct user_arg_ptr argv,
  1466. struct user_arg_ptr envp,
  1467. int flags, struct file *file)
  1468. {
  1469. char *pathbuf = NULL;
  1470. struct linux_binprm *bprm;
  1471. struct files_struct *displaced;
  1472. int retval;
  1473. if (IS_ERR(filename))
  1474. return PTR_ERR(filename);
  1475. /*
  1476. * We move the actual failure in case of RLIMIT_NPROC excess from
  1477. * set*uid() to execve() because too many poorly written programs
  1478. * don't check setuid() return code. Here we additionally recheck
  1479. * whether NPROC limit is still exceeded.
  1480. */
  1481. if ((current->flags & PF_NPROC_EXCEEDED) &&
  1482. atomic_read(&current_user()->processes) > rlimit(RLIMIT_NPROC)) {
  1483. retval = -EAGAIN;
  1484. goto out_ret;
  1485. }
  1486. /* We're below the limit (still or again), so we don't want to make
  1487. * further execve() calls fail. */
  1488. current->flags &= ~PF_NPROC_EXCEEDED;
  1489. retval = unshare_files(&displaced);
  1490. if (retval)
  1491. goto out_ret;
  1492. retval = -ENOMEM;
  1493. bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
  1494. if (!bprm)
  1495. goto out_files;
  1496. retval = prepare_bprm_creds(bprm);
  1497. if (retval)
  1498. goto out_free;
  1499. check_unsafe_exec(bprm);
  1500. current->in_execve = 1;
  1501. if (!file)
  1502. file = do_open_execat(fd, filename, flags);
  1503. retval = PTR_ERR(file);
  1504. if (IS_ERR(file))
  1505. goto out_unmark;
  1506. sched_exec();
  1507. bprm->file = file;
  1508. if (!filename) {
  1509. bprm->filename = "none";
  1510. } else if (fd == AT_FDCWD || filename->name[0] == '/') {
  1511. bprm->filename = filename->name;
  1512. } else {
  1513. if (filename->name[0] == '\0')
  1514. pathbuf = kasprintf(GFP_KERNEL, "/dev/fd/%d", fd);
  1515. else
  1516. pathbuf = kasprintf(GFP_KERNEL, "/dev/fd/%d/%s",
  1517. fd, filename->name);
  1518. if (!pathbuf) {
  1519. retval = -ENOMEM;
  1520. goto out_unmark;
  1521. }
  1522. /*
  1523. * Record that a name derived from an O_CLOEXEC fd will be
  1524. * inaccessible after exec. Relies on having exclusive access to
  1525. * current->files (due to unshare_files above).
  1526. */
  1527. if (close_on_exec(fd, rcu_dereference_raw(current->files->fdt)))
  1528. bprm->interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE;
  1529. bprm->filename = pathbuf;
  1530. }
  1531. bprm->interp = bprm->filename;
  1532. retval = bprm_mm_init(bprm);
  1533. if (retval)
  1534. goto out_unmark;
  1535. bprm->argc = count(argv, MAX_ARG_STRINGS);
  1536. if ((retval = bprm->argc) < 0)
  1537. goto out;
  1538. bprm->envc = count(envp, MAX_ARG_STRINGS);
  1539. if ((retval = bprm->envc) < 0)
  1540. goto out;
  1541. retval = prepare_binprm(bprm);
  1542. if (retval < 0)
  1543. goto out;
  1544. retval = copy_strings_kernel(1, &bprm->filename, bprm);
  1545. if (retval < 0)
  1546. goto out;
  1547. bprm->exec = bprm->p;
  1548. retval = copy_strings(bprm->envc, envp, bprm);
  1549. if (retval < 0)
  1550. goto out;
  1551. retval = copy_strings(bprm->argc, argv, bprm);
  1552. if (retval < 0)
  1553. goto out;
  1554. retval = exec_binprm(bprm);
  1555. if (retval < 0)
  1556. goto out;
  1557. /* execve succeeded */
  1558. current->fs->in_exec = 0;
  1559. current->in_execve = 0;
  1560. membarrier_execve(current);
  1561. rseq_execve(current);
  1562. acct_update_integrals(current);
  1563. task_numa_free(current, false);
  1564. free_bprm(bprm);
  1565. kfree(pathbuf);
  1566. if (filename)
  1567. putname(filename);
  1568. if (displaced)
  1569. put_files_struct(displaced);
  1570. return retval;
  1571. out:
  1572. if (bprm->mm) {
  1573. acct_arg_size(bprm, 0);
  1574. mmput(bprm->mm);
  1575. }
  1576. out_unmark:
  1577. current->fs->in_exec = 0;
  1578. current->in_execve = 0;
  1579. out_free:
  1580. free_bprm(bprm);
  1581. kfree(pathbuf);
  1582. out_files:
  1583. if (displaced)
  1584. reset_files_struct(displaced);
  1585. out_ret:
  1586. if (filename)
  1587. putname(filename);
  1588. return retval;
  1589. }
  1590. static int do_execveat_common(int fd, struct filename *filename,
  1591. struct user_arg_ptr argv,
  1592. struct user_arg_ptr envp,
  1593. int flags)
  1594. {
  1595. return __do_execve_file(fd, filename, argv, envp, flags, NULL);
  1596. }
  1597. int do_execve_file(struct file *file, void *__argv, void *__envp)
  1598. {
  1599. struct user_arg_ptr argv = { .ptr.native = __argv };
  1600. struct user_arg_ptr envp = { .ptr.native = __envp };
  1601. return __do_execve_file(AT_FDCWD, NULL, argv, envp, 0, file);
  1602. }
  1603. int do_execve(struct filename *filename,
  1604. const char __user *const __user *__argv,
  1605. const char __user *const __user *__envp)
  1606. {
  1607. struct user_arg_ptr argv = { .ptr.native = __argv };
  1608. struct user_arg_ptr envp = { .ptr.native = __envp };
  1609. return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
  1610. }
  1611. int do_execveat(int fd, struct filename *filename,
  1612. const char __user *const __user *__argv,
  1613. const char __user *const __user *__envp,
  1614. int flags)
  1615. {
  1616. struct user_arg_ptr argv = { .ptr.native = __argv };
  1617. struct user_arg_ptr envp = { .ptr.native = __envp };
  1618. return do_execveat_common(fd, filename, argv, envp, flags);
  1619. }
  1620. #ifdef CONFIG_COMPAT
  1621. static int compat_do_execve(struct filename *filename,
  1622. const compat_uptr_t __user *__argv,
  1623. const compat_uptr_t __user *__envp)
  1624. {
  1625. struct user_arg_ptr argv = {
  1626. .is_compat = true,
  1627. .ptr.compat = __argv,
  1628. };
  1629. struct user_arg_ptr envp = {
  1630. .is_compat = true,
  1631. .ptr.compat = __envp,
  1632. };
  1633. return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
  1634. }
  1635. static int compat_do_execveat(int fd, struct filename *filename,
  1636. const compat_uptr_t __user *__argv,
  1637. const compat_uptr_t __user *__envp,
  1638. int flags)
  1639. {
  1640. struct user_arg_ptr argv = {
  1641. .is_compat = true,
  1642. .ptr.compat = __argv,
  1643. };
  1644. struct user_arg_ptr envp = {
  1645. .is_compat = true,
  1646. .ptr.compat = __envp,
  1647. };
  1648. return do_execveat_common(fd, filename, argv, envp, flags);
  1649. }
  1650. #endif
  1651. void set_binfmt(struct linux_binfmt *new)
  1652. {
  1653. struct mm_struct *mm = current->mm;
  1654. if (mm->binfmt)
  1655. module_put(mm->binfmt->module);
  1656. mm->binfmt = new;
  1657. if (new)
  1658. __module_get(new->module);
  1659. }
  1660. EXPORT_SYMBOL(set_binfmt);
  1661. /*
  1662. * set_dumpable stores three-value SUID_DUMP_* into mm->flags.
  1663. */
  1664. void set_dumpable(struct mm_struct *mm, int value)
  1665. {
  1666. unsigned long old, new;
  1667. if (WARN_ON((unsigned)value > SUID_DUMP_ROOT))
  1668. return;
  1669. do {
  1670. old = READ_ONCE(mm->flags);
  1671. new = (old & ~MMF_DUMPABLE_MASK) | value;
  1672. } while (cmpxchg(&mm->flags, old, new) != old);
  1673. }
  1674. SYSCALL_DEFINE3(execve,
  1675. const char __user *, filename,
  1676. const char __user *const __user *, argv,
  1677. const char __user *const __user *, envp)
  1678. {
  1679. return do_execve(getname(filename), argv, envp);
  1680. }
  1681. SYSCALL_DEFINE5(execveat,
  1682. int, fd, const char __user *, filename,
  1683. const char __user *const __user *, argv,
  1684. const char __user *const __user *, envp,
  1685. int, flags)
  1686. {
  1687. int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
  1688. return do_execveat(fd,
  1689. getname_flags(filename, lookup_flags, NULL),
  1690. argv, envp, flags);
  1691. }
  1692. #ifdef CONFIG_COMPAT
  1693. COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
  1694. const compat_uptr_t __user *, argv,
  1695. const compat_uptr_t __user *, envp)
  1696. {
  1697. return compat_do_execve(getname(filename), argv, envp);
  1698. }
  1699. COMPAT_SYSCALL_DEFINE5(execveat, int, fd,
  1700. const char __user *, filename,
  1701. const compat_uptr_t __user *, argv,
  1702. const compat_uptr_t __user *, envp,
  1703. int, flags)
  1704. {
  1705. int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
  1706. return compat_do_execveat(fd,
  1707. getname_flags(filename, lookup_flags, NULL),
  1708. argv, envp, flags);
  1709. }
  1710. #endif