• Home
  • Raw
  • Download

Lines Matching refs:bprm

183 static void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)  in acct_arg_size()  argument
186 long diff = (long)(pages - bprm->vma_pages); in acct_arg_size()
191 bprm->vma_pages = pages; in acct_arg_size()
195 static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, in get_arg_page() argument
204 ret = expand_downwards(bprm->vma, pos); in get_arg_page()
217 ret = get_user_pages_remote(current, bprm->mm, pos, 1, gup_flags, in get_arg_page()
223 acct_arg_size(bprm, vma_pages(bprm->vma)); in get_arg_page()
233 static void free_arg_pages(struct linux_binprm *bprm) in free_arg_pages() argument
237 static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos, in flush_arg_page() argument
240 flush_cache_page(bprm->vma, pos, page_to_pfn(page)); in flush_arg_page()
243 static int __bprm_mm_init(struct linux_binprm *bprm) in __bprm_mm_init() argument
247 struct mm_struct *mm = bprm->mm; in __bprm_mm_init()
249 bprm->vma = vma = vm_area_alloc(mm); in __bprm_mm_init()
278 bprm->p = vma->vm_end - sizeof(void *); in __bprm_mm_init()
283 bprm->vma = NULL; in __bprm_mm_init()
288 static bool valid_arg_len(struct linux_binprm *bprm, long len) in valid_arg_len() argument
295 static inline void acct_arg_size(struct linux_binprm *bprm, unsigned long pages) in acct_arg_size() argument
299 static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos, in get_arg_page() argument
304 page = bprm->page[pos / PAGE_SIZE]; in get_arg_page()
309 bprm->page[pos / PAGE_SIZE] = page; in get_arg_page()
319 static void free_arg_page(struct linux_binprm *bprm, int i) in free_arg_page() argument
321 if (bprm->page[i]) { in free_arg_page()
322 __free_page(bprm->page[i]); in free_arg_page()
323 bprm->page[i] = NULL; in free_arg_page()
327 static void free_arg_pages(struct linux_binprm *bprm) in free_arg_pages() argument
332 free_arg_page(bprm, i); in free_arg_pages()
335 static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos, in flush_arg_page() argument
340 static int __bprm_mm_init(struct linux_binprm *bprm) in __bprm_mm_init() argument
342 bprm->p = PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *); in __bprm_mm_init()
346 static bool valid_arg_len(struct linux_binprm *bprm, long len) in valid_arg_len() argument
348 return len <= bprm->p; in valid_arg_len()
359 static int bprm_mm_init(struct linux_binprm *bprm) in bprm_mm_init() argument
364 bprm->mm = mm = mm_alloc(); in bprm_mm_init()
371 bprm->rlim_stack = current->signal->rlim[RLIMIT_STACK]; in bprm_mm_init()
374 err = __bprm_mm_init(bprm); in bprm_mm_init()
382 bprm->mm = NULL; in bprm_mm_init()
451 static int prepare_arg_pages(struct linux_binprm *bprm, in prepare_arg_pages() argument
456 bprm->argc = count(argv, MAX_ARG_STRINGS); in prepare_arg_pages()
457 if (bprm->argc == 0) in prepare_arg_pages()
459 current->comm, bprm->filename); in prepare_arg_pages()
460 if (bprm->argc < 0) in prepare_arg_pages()
461 return bprm->argc; in prepare_arg_pages()
463 bprm->envc = count(envp, MAX_ARG_STRINGS); in prepare_arg_pages()
464 if (bprm->envc < 0) in prepare_arg_pages()
465 return bprm->envc; in prepare_arg_pages()
476 limit = min(limit, bprm->rlim_stack.rlim_cur / 4); in prepare_arg_pages()
495 ptr_size = (max(bprm->argc, 1) + bprm->envc) * sizeof(void *); in prepare_arg_pages()
500 bprm->argmin = bprm->p - limit; in prepare_arg_pages()
510 struct linux_binprm *bprm) in copy_strings() argument
532 if (!valid_arg_len(bprm, len)) in copy_strings()
536 pos = bprm->p; in copy_strings()
538 bprm->p -= len; in copy_strings()
540 if (bprm->p < bprm->argmin) in copy_strings()
569 page = get_arg_page(bprm, pos, 1); in copy_strings()
583 flush_arg_page(bprm, kpos, kmapped_page); in copy_strings()
605 struct linux_binprm *bprm) in copy_strings_kernel() argument
614 r = copy_strings(argc, argv, bprm); in copy_strings_kernel()
700 int setup_arg_pages(struct linux_binprm *bprm, in setup_arg_pages() argument
707 struct vm_area_struct *vma = bprm->vma; in setup_arg_pages()
717 stack_base = bprm->rlim_stack.rlim_max; in setup_arg_pages()
731 mm->arg_start = bprm->p - stack_shift; in setup_arg_pages()
732 bprm->p = vma->vm_end - stack_shift; in setup_arg_pages()
743 bprm->p -= stack_shift; in setup_arg_pages()
744 mm->arg_start = bprm->p; in setup_arg_pages()
747 if (bprm->loader) in setup_arg_pages()
748 bprm->loader -= stack_shift; in setup_arg_pages()
749 bprm->exec -= stack_shift; in setup_arg_pages()
790 rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK; in setup_arg_pages()
802 current->mm->start_stack = bprm->p; in setup_arg_pages()
819 int transfer_args_to_stack(struct linux_binprm *bprm, in transfer_args_to_stack() argument
825 stop = bprm->p >> PAGE_SHIFT; in transfer_args_to_stack()
829 unsigned int offset = index == stop ? bprm->p & ~PAGE_MASK : 0; in transfer_args_to_stack()
830 char *src = kmap(bprm->page[index]) + offset; in transfer_args_to_stack()
834 kunmap(bprm->page[index]); in transfer_args_to_stack()
839 bprm->exec += *sp_location - MAX_ARG_PAGES * PAGE_SIZE; in transfer_args_to_stack()
1281 int flush_old_exec(struct linux_binprm * bprm) in flush_old_exec() argument
1298 set_mm_exe_file(bprm->mm, bprm->file); in flush_old_exec()
1300 would_dump(bprm, bprm->file); in flush_old_exec()
1305 acct_arg_size(bprm, 0); in flush_old_exec()
1306 retval = exec_mmap(bprm->mm); in flush_old_exec()
1316 bprm->mm = NULL; in flush_old_exec()
1322 current->personality &= ~bprm->per_clear; in flush_old_exec()
1338 void would_dump(struct linux_binprm *bprm, struct file *file) in would_dump() argument
1343 bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP; in would_dump()
1346 user_ns = old = bprm->mm->user_ns; in would_dump()
1352 bprm->mm->user_ns = get_user_ns(user_ns); in would_dump()
1359 void setup_new_exec(struct linux_binprm * bprm) in setup_new_exec() argument
1366 bprm->secureexec |= bprm->cap_elevated; in setup_new_exec()
1368 if (bprm->secureexec) { in setup_new_exec()
1379 if (bprm->rlim_stack.rlim_cur > _STK_LIM) in setup_new_exec()
1380 bprm->rlim_stack.rlim_cur = _STK_LIM; in setup_new_exec()
1383 arch_pick_mmap_layout(current->mm, &bprm->rlim_stack); in setup_new_exec()
1392 if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP || in setup_new_exec()
1401 __set_task_comm(current, kbasename(bprm->filename), true); in setup_new_exec()
1417 void finalize_exec(struct linux_binprm *bprm) in finalize_exec() argument
1421 current->signal->rlim[RLIMIT_STACK] = bprm->rlim_stack; in finalize_exec()
1432 static int prepare_bprm_creds(struct linux_binprm *bprm) in prepare_bprm_creds() argument
1437 bprm->cred = prepare_exec_creds(); in prepare_bprm_creds()
1438 if (likely(bprm->cred)) in prepare_bprm_creds()
1445 static void free_bprm(struct linux_binprm *bprm) in free_bprm() argument
1447 free_arg_pages(bprm); in free_bprm()
1448 if (bprm->cred) { in free_bprm()
1450 abort_creds(bprm->cred); in free_bprm()
1452 if (bprm->file) { in free_bprm()
1453 allow_write_access(bprm->file); in free_bprm()
1454 fput(bprm->file); in free_bprm()
1457 if (bprm->interp != bprm->filename) in free_bprm()
1458 kfree(bprm->interp); in free_bprm()
1459 kfree(bprm); in free_bprm()
1462 int bprm_change_interp(const char *interp, struct linux_binprm *bprm) in bprm_change_interp() argument
1465 if (bprm->interp != bprm->filename) in bprm_change_interp()
1466 kfree(bprm->interp); in bprm_change_interp()
1467 bprm->interp = kstrdup(interp, GFP_KERNEL); in bprm_change_interp()
1468 if (!bprm->interp) in bprm_change_interp()
1477 void install_exec_creds(struct linux_binprm *bprm) in install_exec_creds() argument
1479 security_bprm_committing_creds(bprm); in install_exec_creds()
1481 commit_creds(bprm->cred); in install_exec_creds()
1482 bprm->cred = NULL; in install_exec_creds()
1497 security_bprm_committed_creds(bprm); in install_exec_creds()
1507 static void check_unsafe_exec(struct linux_binprm *bprm) in check_unsafe_exec() argument
1513 bprm->unsafe |= LSM_UNSAFE_PTRACE; in check_unsafe_exec()
1520 bprm->unsafe |= LSM_UNSAFE_NO_NEW_PRIVS; in check_unsafe_exec()
1533 bprm->unsafe |= LSM_UNSAFE_SHARE; in check_unsafe_exec()
1539 static void bprm_fill_uid(struct linux_binprm *bprm) in bprm_fill_uid() argument
1552 bprm->cred->euid = current_euid(); in bprm_fill_uid()
1553 bprm->cred->egid = current_egid(); in bprm_fill_uid()
1555 if (!mnt_may_suid(bprm->file->f_path.mnt)) in bprm_fill_uid()
1561 inode = bprm->file->f_path.dentry->d_inode; in bprm_fill_uid()
1576 if (!kuid_has_mapping(bprm->cred->user_ns, uid) || in bprm_fill_uid()
1577 !kgid_has_mapping(bprm->cred->user_ns, gid)) in bprm_fill_uid()
1581 bprm->per_clear |= PER_CLEAR_ON_SETID; in bprm_fill_uid()
1582 bprm->cred->euid = uid; in bprm_fill_uid()
1586 bprm->per_clear |= PER_CLEAR_ON_SETID; in bprm_fill_uid()
1587 bprm->cred->egid = gid; in bprm_fill_uid()
1597 int prepare_binprm(struct linux_binprm *bprm) in prepare_binprm() argument
1602 bprm_fill_uid(bprm); in prepare_binprm()
1605 retval = security_bprm_set_creds(bprm); in prepare_binprm()
1608 bprm->called_set_creds = 1; in prepare_binprm()
1610 memset(bprm->buf, 0, BINPRM_BUF_SIZE); in prepare_binprm()
1611 return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos); in prepare_binprm()
1621 int remove_arg_zero(struct linux_binprm *bprm) in remove_arg_zero() argument
1628 if (!bprm->argc) in remove_arg_zero()
1632 offset = bprm->p & ~PAGE_MASK; in remove_arg_zero()
1633 page = get_arg_page(bprm, bprm->p, 0); in remove_arg_zero()
1641 offset++, bprm->p++) in remove_arg_zero()
1648 bprm->p++; in remove_arg_zero()
1649 bprm->argc--; in remove_arg_zero()
1661 int search_binary_handler(struct linux_binprm *bprm) in search_binary_handler() argument
1668 if (bprm->recursion_depth > 5) in search_binary_handler()
1671 retval = security_bprm_check(bprm); in search_binary_handler()
1683 bprm->recursion_depth++; in search_binary_handler()
1684 retval = fmt->load_binary(bprm); in search_binary_handler()
1685 bprm->recursion_depth--; in search_binary_handler()
1689 if (retval < 0 && !bprm->mm) { in search_binary_handler()
1695 if (retval != -ENOEXEC || !bprm->file) { in search_binary_handler()
1703 if (printable(bprm->buf[0]) && printable(bprm->buf[1]) && in search_binary_handler()
1704 printable(bprm->buf[2]) && printable(bprm->buf[3])) in search_binary_handler()
1706 if (request_module("binfmt-%04x", *(ushort *)(bprm->buf + 2)) < 0) in search_binary_handler()
1716 static int exec_binprm(struct linux_binprm *bprm) in exec_binprm() argument
1727 ret = search_binary_handler(bprm); in exec_binprm()
1729 audit_bprm(bprm); in exec_binprm()
1730 trace_sched_process_exec(current, old_pid, bprm); in exec_binprm()
1747 struct linux_binprm *bprm; in __do_execve_file() local
1775 bprm = kzalloc(sizeof(*bprm), GFP_KERNEL); in __do_execve_file()
1776 if (!bprm) in __do_execve_file()
1779 retval = prepare_bprm_creds(bprm); in __do_execve_file()
1783 check_unsafe_exec(bprm); in __do_execve_file()
1794 bprm->file = file; in __do_execve_file()
1796 bprm->filename = "none"; in __do_execve_file()
1798 bprm->filename = filename->name; in __do_execve_file()
1815 bprm->interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE; in __do_execve_file()
1816 bprm->filename = pathbuf; in __do_execve_file()
1818 bprm->interp = bprm->filename; in __do_execve_file()
1820 retval = bprm_mm_init(bprm); in __do_execve_file()
1824 retval = prepare_arg_pages(bprm, argv, envp); in __do_execve_file()
1828 retval = prepare_binprm(bprm); in __do_execve_file()
1832 retval = copy_strings_kernel(1, &bprm->filename, bprm); in __do_execve_file()
1836 bprm->exec = bprm->p; in __do_execve_file()
1837 retval = copy_strings(bprm->envc, envp, bprm); in __do_execve_file()
1841 retval = copy_strings(bprm->argc, argv, bprm); in __do_execve_file()
1851 if (bprm->argc == 0) { in __do_execve_file()
1853 retval = copy_strings_kernel(1, argv, bprm); in __do_execve_file()
1856 bprm->argc = 1; in __do_execve_file()
1859 retval = exec_binprm(bprm); in __do_execve_file()
1869 free_bprm(bprm); in __do_execve_file()
1878 if (bprm->mm) { in __do_execve_file()
1879 acct_arg_size(bprm, 0); in __do_execve_file()
1880 mmput(bprm->mm); in __do_execve_file()
1888 free_bprm(bprm); in __do_execve_file()