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()
458 return bprm->argc; in prepare_arg_pages()
460 bprm->envc = count(envp, MAX_ARG_STRINGS); in prepare_arg_pages()
461 if (bprm->envc < 0) in prepare_arg_pages()
462 return bprm->envc; in prepare_arg_pages()
473 limit = min(limit, bprm->rlim_stack.rlim_cur / 4); in prepare_arg_pages()
486 ptr_size = (bprm->argc + bprm->envc) * sizeof(void *); in prepare_arg_pages()
491 bprm->argmin = bprm->p - limit; in prepare_arg_pages()
501 struct linux_binprm *bprm) in copy_strings() argument
523 if (!valid_arg_len(bprm, len)) in copy_strings()
527 pos = bprm->p; in copy_strings()
529 bprm->p -= len; in copy_strings()
531 if (bprm->p < bprm->argmin) in copy_strings()
560 page = get_arg_page(bprm, pos, 1); in copy_strings()
574 flush_arg_page(bprm, kpos, kmapped_page); in copy_strings()
596 struct linux_binprm *bprm) in copy_strings_kernel() argument
605 r = copy_strings(argc, argv, bprm); in copy_strings_kernel()
691 int setup_arg_pages(struct linux_binprm *bprm, in setup_arg_pages() argument
698 struct vm_area_struct *vma = bprm->vma; in setup_arg_pages()
708 stack_base = bprm->rlim_stack.rlim_max; in setup_arg_pages()
722 mm->arg_start = bprm->p - stack_shift; in setup_arg_pages()
723 bprm->p = vma->vm_end - stack_shift; in setup_arg_pages()
734 bprm->p -= stack_shift; in setup_arg_pages()
735 mm->arg_start = bprm->p; in setup_arg_pages()
738 if (bprm->loader) in setup_arg_pages()
739 bprm->loader -= stack_shift; in setup_arg_pages()
740 bprm->exec -= stack_shift; in setup_arg_pages()
781 rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK; in setup_arg_pages()
793 current->mm->start_stack = bprm->p; in setup_arg_pages()
810 int transfer_args_to_stack(struct linux_binprm *bprm, in transfer_args_to_stack() argument
816 stop = bprm->p >> PAGE_SHIFT; in transfer_args_to_stack()
820 unsigned int offset = index == stop ? bprm->p & ~PAGE_MASK : 0; in transfer_args_to_stack()
821 char *src = kmap(bprm->page[index]) + offset; in transfer_args_to_stack()
825 kunmap(bprm->page[index]); in transfer_args_to_stack()
1258 int flush_old_exec(struct linux_binprm * bprm) in flush_old_exec() argument
1275 set_mm_exe_file(bprm->mm, bprm->file); in flush_old_exec()
1280 acct_arg_size(bprm, 0); in flush_old_exec()
1281 retval = exec_mmap(bprm->mm); in flush_old_exec()
1291 bprm->mm = NULL; in flush_old_exec()
1297 current->personality &= ~bprm->per_clear; in flush_old_exec()
1313 void would_dump(struct linux_binprm *bprm, struct file *file) in would_dump() argument
1318 bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP; in would_dump()
1321 user_ns = old = bprm->mm->user_ns; in would_dump()
1327 bprm->mm->user_ns = get_user_ns(user_ns); in would_dump()
1334 void setup_new_exec(struct linux_binprm * bprm) in setup_new_exec() argument
1341 bprm->secureexec |= bprm->cap_elevated; in setup_new_exec()
1343 if (bprm->secureexec) { in setup_new_exec()
1354 if (bprm->rlim_stack.rlim_cur > _STK_LIM) in setup_new_exec()
1355 bprm->rlim_stack.rlim_cur = _STK_LIM; in setup_new_exec()
1358 arch_pick_mmap_layout(current->mm, &bprm->rlim_stack); in setup_new_exec()
1367 if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP || in setup_new_exec()
1376 __set_task_comm(current, kbasename(bprm->filename), true); in setup_new_exec()
1392 void finalize_exec(struct linux_binprm *bprm) in finalize_exec() argument
1396 current->signal->rlim[RLIMIT_STACK] = bprm->rlim_stack; in finalize_exec()
1407 static int prepare_bprm_creds(struct linux_binprm *bprm) in prepare_bprm_creds() argument
1412 bprm->cred = prepare_exec_creds(); in prepare_bprm_creds()
1413 if (likely(bprm->cred)) in prepare_bprm_creds()
1420 static void free_bprm(struct linux_binprm *bprm) in free_bprm() argument
1422 free_arg_pages(bprm); in free_bprm()
1423 if (bprm->cred) { in free_bprm()
1425 abort_creds(bprm->cred); in free_bprm()
1427 if (bprm->file) { in free_bprm()
1428 allow_write_access(bprm->file); in free_bprm()
1429 fput(bprm->file); in free_bprm()
1432 if (bprm->interp != bprm->filename) in free_bprm()
1433 kfree(bprm->interp); in free_bprm()
1434 kfree(bprm); in free_bprm()
1437 int bprm_change_interp(const char *interp, struct linux_binprm *bprm) in bprm_change_interp() argument
1440 if (bprm->interp != bprm->filename) in bprm_change_interp()
1441 kfree(bprm->interp); in bprm_change_interp()
1442 bprm->interp = kstrdup(interp, GFP_KERNEL); in bprm_change_interp()
1443 if (!bprm->interp) in bprm_change_interp()
1452 void install_exec_creds(struct linux_binprm *bprm) in install_exec_creds() argument
1454 security_bprm_committing_creds(bprm); in install_exec_creds()
1456 commit_creds(bprm->cred); in install_exec_creds()
1457 bprm->cred = NULL; in install_exec_creds()
1472 security_bprm_committed_creds(bprm); in install_exec_creds()
1482 static void check_unsafe_exec(struct linux_binprm *bprm) in check_unsafe_exec() argument
1488 bprm->unsafe |= LSM_UNSAFE_PTRACE; in check_unsafe_exec()
1495 bprm->unsafe |= LSM_UNSAFE_NO_NEW_PRIVS; in check_unsafe_exec()
1508 bprm->unsafe |= LSM_UNSAFE_SHARE; in check_unsafe_exec()
1514 static void bprm_fill_uid(struct linux_binprm *bprm) in bprm_fill_uid() argument
1527 bprm->cred->euid = current_euid(); in bprm_fill_uid()
1528 bprm->cred->egid = current_egid(); in bprm_fill_uid()
1530 if (!mnt_may_suid(bprm->file->f_path.mnt)) in bprm_fill_uid()
1536 inode = bprm->file->f_path.dentry->d_inode; in bprm_fill_uid()
1551 if (!kuid_has_mapping(bprm->cred->user_ns, uid) || in bprm_fill_uid()
1552 !kgid_has_mapping(bprm->cred->user_ns, gid)) in bprm_fill_uid()
1556 bprm->per_clear |= PER_CLEAR_ON_SETID; in bprm_fill_uid()
1557 bprm->cred->euid = uid; in bprm_fill_uid()
1561 bprm->per_clear |= PER_CLEAR_ON_SETID; in bprm_fill_uid()
1562 bprm->cred->egid = gid; in bprm_fill_uid()
1572 int prepare_binprm(struct linux_binprm *bprm) in prepare_binprm() argument
1577 bprm_fill_uid(bprm); in prepare_binprm()
1580 retval = security_bprm_set_creds(bprm); in prepare_binprm()
1583 bprm->called_set_creds = 1; in prepare_binprm()
1585 memset(bprm->buf, 0, BINPRM_BUF_SIZE); in prepare_binprm()
1586 return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos); in prepare_binprm()
1596 int remove_arg_zero(struct linux_binprm *bprm) in remove_arg_zero() argument
1603 if (!bprm->argc) in remove_arg_zero()
1607 offset = bprm->p & ~PAGE_MASK; in remove_arg_zero()
1608 page = get_arg_page(bprm, bprm->p, 0); in remove_arg_zero()
1616 offset++, bprm->p++) in remove_arg_zero()
1623 bprm->p++; in remove_arg_zero()
1624 bprm->argc--; in remove_arg_zero()
1636 int search_binary_handler(struct linux_binprm *bprm) in search_binary_handler() argument
1643 if (bprm->recursion_depth > 5) in search_binary_handler()
1646 retval = security_bprm_check(bprm); in search_binary_handler()
1658 bprm->recursion_depth++; in search_binary_handler()
1659 retval = fmt->load_binary(bprm); in search_binary_handler()
1660 bprm->recursion_depth--; in search_binary_handler()
1664 if (retval < 0 && !bprm->mm) { in search_binary_handler()
1670 if (retval != -ENOEXEC || !bprm->file) { in search_binary_handler()
1678 if (printable(bprm->buf[0]) && printable(bprm->buf[1]) && in search_binary_handler()
1679 printable(bprm->buf[2]) && printable(bprm->buf[3])) in search_binary_handler()
1681 if (request_module("binfmt-%04x", *(ushort *)(bprm->buf + 2)) < 0) in search_binary_handler()
1691 static int exec_binprm(struct linux_binprm *bprm) in exec_binprm() argument
1702 ret = search_binary_handler(bprm); in exec_binprm()
1704 audit_bprm(bprm); in exec_binprm()
1705 trace_sched_process_exec(current, old_pid, bprm); in exec_binprm()
1722 struct linux_binprm *bprm; in __do_execve_file() local
1750 bprm = kzalloc(sizeof(*bprm), GFP_KERNEL); in __do_execve_file()
1751 if (!bprm) in __do_execve_file()
1754 retval = prepare_bprm_creds(bprm); in __do_execve_file()
1758 check_unsafe_exec(bprm); in __do_execve_file()
1769 bprm->file = file; in __do_execve_file()
1771 bprm->filename = "none"; in __do_execve_file()
1773 bprm->filename = filename->name; in __do_execve_file()
1790 bprm->interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE; in __do_execve_file()
1791 bprm->filename = pathbuf; in __do_execve_file()
1793 bprm->interp = bprm->filename; in __do_execve_file()
1795 retval = bprm_mm_init(bprm); in __do_execve_file()
1799 retval = prepare_arg_pages(bprm, argv, envp); in __do_execve_file()
1803 retval = prepare_binprm(bprm); in __do_execve_file()
1807 retval = copy_strings_kernel(1, &bprm->filename, bprm); in __do_execve_file()
1811 bprm->exec = bprm->p; in __do_execve_file()
1812 retval = copy_strings(bprm->envc, envp, bprm); in __do_execve_file()
1816 retval = copy_strings(bprm->argc, argv, bprm); in __do_execve_file()
1820 would_dump(bprm, bprm->file); in __do_execve_file()
1822 retval = exec_binprm(bprm); in __do_execve_file()
1832 free_bprm(bprm); in __do_execve_file()
1841 if (bprm->mm) { in __do_execve_file()
1842 acct_arg_size(bprm, 0); in __do_execve_file()
1843 mmput(bprm->mm); in __do_execve_file()
1851 free_bprm(bprm); in __do_execve_file()