4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * #!-checking implemented by tytso.
11 * Demand-loading implemented 01.12.91 - no need to read anything but
12 * the header into memory. The inode of the executable is put into
13 * "current->executable", and page faults do the actual loading. Clean.
15 * Once more I can proudly say that linux stood up to being changed: it
16 * was less than 2 hours work to get demand-loading completely implemented.
18 * Demand loading changed July 1993 by Eric Youngdale. Use mmap instead,
19 * current->executable is only used by the procfs. This allows a dispatch
20 * table to check for several different types of binary formats. We keep
21 * trying until we recognize the file or we run out of supported binary
25 #include <linux/slab.h>
26 #include <linux/file.h>
27 #include <linux/fdtable.h>
29 #include <linux/vmacache.h>
30 #include <linux/stat.h>
31 #include <linux/fcntl.h>
32 #include <linux/swap.h>
33 #include <linux/string.h>
34 #include <linux/init.h>
35 #include <linux/pagemap.h>
36 #include <linux/perf_event.h>
37 #include <linux/highmem.h>
38 #include <linux/spinlock.h>
39 #include <linux/key.h>
40 #include <linux/personality.h>
41 #include <linux/binfmts.h>
42 #include <linux/utsname.h>
43 #include <linux/pid_namespace.h>
44 #include <linux/module.h>
45 #include <linux/namei.h>
46 #include <linux/mount.h>
47 #include <linux/security.h>
48 #include <linux/syscalls.h>
49 #include <linux/tsacct_kern.h>
50 #include <linux/cn_proc.h>
51 #include <linux/audit.h>
52 #include <linux/tracehook.h>
53 #include <linux/kmod.h>
54 #include <linux/fsnotify.h>
55 #include <linux/fs_struct.h>
56 #include <linux/pipe_fs_i.h>
57 #include <linux/oom.h>
58 #include <linux/compat.h>
59 #include <linux/resource.h>
61 #include <asm/uaccess.h>
62 #include <asm/mmu_context.h>
65 #include <trace/events/task.h>
69 #include <trace/events/sched.h>
72 #define rkp_is_nonroot(x) ((x->cred->type)>>1 & 1)
73 #endif /*CONFIG_RKP_KDP*/
75 int suid_dumpable
= 0;
77 static LIST_HEAD(formats
);
78 static DEFINE_RWLOCK(binfmt_lock
);
80 void __register_binfmt(struct linux_binfmt
* fmt
, int insert
)
83 write_lock(&binfmt_lock
);
84 insert
? list_add(&fmt
->lh
, &formats
) :
85 list_add_tail(&fmt
->lh
, &formats
);
86 write_unlock(&binfmt_lock
);
89 EXPORT_SYMBOL(__register_binfmt
);
91 void unregister_binfmt(struct linux_binfmt
* fmt
)
93 write_lock(&binfmt_lock
);
95 write_unlock(&binfmt_lock
);
98 EXPORT_SYMBOL(unregister_binfmt
);
100 static inline void put_binfmt(struct linux_binfmt
* fmt
)
102 module_put(fmt
->module
);
106 * Note that a shared library must be both readable and executable due to
109 * Also note that we take the address to load from from the file itself.
111 SYSCALL_DEFINE1(uselib
, const char __user
*, library
)
114 struct filename
*tmp
= getname(library
);
115 int error
= PTR_ERR(tmp
);
116 static const struct open_flags uselib_flags
= {
117 .open_flag
= O_LARGEFILE
| O_RDONLY
| __FMODE_EXEC
,
118 .acc_mode
= MAY_READ
| MAY_EXEC
| MAY_OPEN
,
119 .intent
= LOOKUP_OPEN
,
120 .lookup_flags
= LOOKUP_FOLLOW
,
126 file
= do_filp_open(AT_FDCWD
, tmp
, &uselib_flags
);
128 error
= PTR_ERR(file
);
133 if (!S_ISREG(file_inode(file
)->i_mode
))
137 if (file
->f_path
.mnt
->mnt_flags
& MNT_NOEXEC
)
144 struct linux_binfmt
* fmt
;
146 read_lock(&binfmt_lock
);
147 list_for_each_entry(fmt
, &formats
, lh
) {
148 if (!fmt
->load_shlib
)
150 if (!try_module_get(fmt
->module
))
152 read_unlock(&binfmt_lock
);
153 error
= fmt
->load_shlib(file
);
154 read_lock(&binfmt_lock
);
156 if (error
!= -ENOEXEC
)
159 read_unlock(&binfmt_lock
);
169 * The nascent bprm->mm is not visible until exec_mmap() but it can
170 * use a lot of memory, account these pages in current->mm temporary
171 * for oom_badness()->get_mm_rss(). Once exec succeeds or fails, we
172 * change the counter back via acct_arg_size(0).
174 static void acct_arg_size(struct linux_binprm
*bprm
, unsigned long pages
)
176 struct mm_struct
*mm
= current
->mm
;
177 long diff
= (long)(pages
- bprm
->vma_pages
);
182 bprm
->vma_pages
= pages
;
183 add_mm_counter(mm
, MM_ANONPAGES
, diff
);
186 static struct page
*get_arg_page(struct linux_binprm
*bprm
, unsigned long pos
,
192 #ifdef CONFIG_STACK_GROWSUP
194 ret
= expand_downwards(bprm
->vma
, pos
);
199 ret
= get_user_pages(current
, bprm
->mm
, pos
,
200 1, write
, 1, &page
, NULL
);
205 unsigned long size
= bprm
->vma
->vm_end
- bprm
->vma
->vm_start
;
206 unsigned long ptr_size
;
210 * Since the stack will hold pointers to the strings, we
211 * must account for them as well.
213 * The size calculation is the entire vma while each arg page is
214 * built, so each time we get here it's calculating how far it
215 * is currently (rather than each call being just the newly
216 * added size from the arg page). As a result, we need to
217 * always add the entire size of the pointers, so that on the
218 * last call to get_arg_page() we'll actually have the entire
221 ptr_size
= (bprm
->argc
+ bprm
->envc
) * sizeof(void *);
222 if (ptr_size
> ULONG_MAX
- size
)
226 acct_arg_size(bprm
, size
/ PAGE_SIZE
);
229 * We've historically supported up to 32 pages (ARG_MAX)
230 * of argument strings even with small stacks
236 * Limit to 1/4-th the stack size for the argv+env strings.
238 * - the remaining binfmt code will not run out of stack space,
239 * - the program will have a reasonable amount of stack left
242 rlim
= current
->signal
->rlim
;
243 if (size
> ACCESS_ONCE(rlim
[RLIMIT_STACK
].rlim_cur
) / 4)
254 static void put_arg_page(struct page
*page
)
259 static void free_arg_page(struct linux_binprm
*bprm
, int i
)
263 static void free_arg_pages(struct linux_binprm
*bprm
)
267 static void flush_arg_page(struct linux_binprm
*bprm
, unsigned long pos
,
270 flush_cache_page(bprm
->vma
, pos
, page_to_pfn(page
));
273 static int __bprm_mm_init(struct linux_binprm
*bprm
)
276 struct vm_area_struct
*vma
= NULL
;
277 struct mm_struct
*mm
= bprm
->mm
;
279 bprm
->vma
= vma
= kmem_cache_zalloc(vm_area_cachep
, GFP_KERNEL
);
283 down_write(&mm
->mmap_sem
);
287 * Place the stack at the largest stack address the architecture
288 * supports. Later, we'll move this to an appropriate place. We don't
289 * use STACK_TOP because that can depend on attributes which aren't
292 BUILD_BUG_ON(VM_STACK_FLAGS
& VM_STACK_INCOMPLETE_SETUP
);
293 vma
->vm_end
= STACK_TOP_MAX
;
294 vma
->vm_start
= vma
->vm_end
- PAGE_SIZE
;
295 vma
->vm_flags
= VM_STACK_FLAGS
| VM_STACK_INCOMPLETE_SETUP
;
296 vma
->vm_page_prot
= vm_get_page_prot(vma
->vm_flags
);
297 INIT_LIST_HEAD(&vma
->anon_vma_chain
);
299 err
= insert_vm_struct(mm
, vma
);
303 mm
->stack_vm
= mm
->total_vm
= 1;
304 up_write(&mm
->mmap_sem
);
305 bprm
->p
= vma
->vm_end
- sizeof(void *);
308 up_write(&mm
->mmap_sem
);
310 kmem_cache_free(vm_area_cachep
, vma
);
314 static bool valid_arg_len(struct linux_binprm
*bprm
, long len
)
316 return len
<= MAX_ARG_STRLEN
;
321 static inline void acct_arg_size(struct linux_binprm
*bprm
, unsigned long pages
)
325 static struct page
*get_arg_page(struct linux_binprm
*bprm
, unsigned long pos
,
330 page
= bprm
->page
[pos
/ PAGE_SIZE
];
331 if (!page
&& write
) {
332 page
= alloc_page(GFP_HIGHUSER
|__GFP_ZERO
);
335 bprm
->page
[pos
/ PAGE_SIZE
] = page
;
341 static void put_arg_page(struct page
*page
)
345 static void free_arg_page(struct linux_binprm
*bprm
, int i
)
348 __free_page(bprm
->page
[i
]);
349 bprm
->page
[i
] = NULL
;
353 static void free_arg_pages(struct linux_binprm
*bprm
)
357 for (i
= 0; i
< MAX_ARG_PAGES
; i
++)
358 free_arg_page(bprm
, i
);
361 static void flush_arg_page(struct linux_binprm
*bprm
, unsigned long pos
,
366 static int __bprm_mm_init(struct linux_binprm
*bprm
)
368 bprm
->p
= PAGE_SIZE
* MAX_ARG_PAGES
- sizeof(void *);
372 static bool valid_arg_len(struct linux_binprm
*bprm
, long len
)
374 return len
<= bprm
->p
;
377 #endif /* CONFIG_MMU */
380 * Create a new mm_struct and populate it with a temporary stack
381 * vm_area_struct. We don't have enough context at this point to set the stack
382 * flags, permissions, and offset, so we use temporary values. We'll update
383 * them later in setup_arg_pages().
385 static int bprm_mm_init(struct linux_binprm
*bprm
)
388 struct mm_struct
*mm
= NULL
;
390 bprm
->mm
= mm
= mm_alloc();
395 err
= init_new_context(current
, mm
);
399 err
= __bprm_mm_init(bprm
);
414 struct user_arg_ptr
{
419 const char __user
*const __user
*native
;
421 const compat_uptr_t __user
*compat
;
426 static const char __user
*get_user_arg_ptr(struct user_arg_ptr argv
, int nr
)
428 const char __user
*native
;
431 if (unlikely(argv
.is_compat
)) {
432 compat_uptr_t compat
;
434 if (get_user(compat
, argv
.ptr
.compat
+ nr
))
435 return ERR_PTR(-EFAULT
);
437 return compat_ptr(compat
);
441 if (get_user(native
, argv
.ptr
.native
+ nr
))
442 return ERR_PTR(-EFAULT
);
448 * count() counts the number of strings in array ARGV.
450 static int count(struct user_arg_ptr argv
, int max
)
454 if (argv
.ptr
.native
!= NULL
) {
456 const char __user
*p
= get_user_arg_ptr(argv
, i
);
468 if (fatal_signal_pending(current
))
469 return -ERESTARTNOHAND
;
477 * 'copy_strings()' copies argument/environment strings from the old
478 * processes's memory to the new process's stack. The call to get_user_pages()
479 * ensures the destination page is created and not swapped out.
481 static int copy_strings(int argc
, struct user_arg_ptr argv
,
482 struct linux_binprm
*bprm
)
484 struct page
*kmapped_page
= NULL
;
486 unsigned long kpos
= 0;
490 const char __user
*str
;
495 str
= get_user_arg_ptr(argv
, argc
);
499 len
= strnlen_user(str
, MAX_ARG_STRLEN
);
504 if (!valid_arg_len(bprm
, len
))
507 /* We're going to work our way backwords. */
513 int offset
, bytes_to_copy
;
515 if (fatal_signal_pending(current
)) {
516 ret
= -ERESTARTNOHAND
;
521 offset
= pos
% PAGE_SIZE
;
525 bytes_to_copy
= offset
;
526 if (bytes_to_copy
> len
)
529 offset
-= bytes_to_copy
;
530 pos
-= bytes_to_copy
;
531 str
-= bytes_to_copy
;
532 len
-= bytes_to_copy
;
534 if (!kmapped_page
|| kpos
!= (pos
& PAGE_MASK
)) {
537 page
= get_arg_page(bprm
, pos
, 1);
544 flush_kernel_dcache_page(kmapped_page
);
545 kunmap(kmapped_page
);
546 put_arg_page(kmapped_page
);
549 kaddr
= kmap(kmapped_page
);
550 kpos
= pos
& PAGE_MASK
;
551 flush_arg_page(bprm
, kpos
, kmapped_page
);
553 if (copy_from_user(kaddr
+offset
, str
, bytes_to_copy
)) {
562 flush_kernel_dcache_page(kmapped_page
);
563 kunmap(kmapped_page
);
564 put_arg_page(kmapped_page
);
570 * Like copy_strings, but get argv and its values from kernel memory.
572 int copy_strings_kernel(int argc
, const char *const *__argv
,
573 struct linux_binprm
*bprm
)
576 mm_segment_t oldfs
= get_fs();
577 struct user_arg_ptr argv
= {
578 .ptr
.native
= (const char __user
*const __user
*)__argv
,
582 r
= copy_strings(argc
, argv
, bprm
);
587 EXPORT_SYMBOL(copy_strings_kernel
);
592 * During bprm_mm_init(), we create a temporary stack at STACK_TOP_MAX. Once
593 * the binfmt code determines where the new stack should reside, we shift it to
594 * its final location. The process proceeds as follows:
596 * 1) Use shift to calculate the new vma endpoints.
597 * 2) Extend vma to cover both the old and new ranges. This ensures the
598 * arguments passed to subsequent functions are consistent.
599 * 3) Move vma's page tables to the new range.
600 * 4) Free up any cleared pgd range.
601 * 5) Shrink the vma to cover only the new range.
603 static int shift_arg_pages(struct vm_area_struct
*vma
, unsigned long shift
)
605 struct mm_struct
*mm
= vma
->vm_mm
;
606 unsigned long old_start
= vma
->vm_start
;
607 unsigned long old_end
= vma
->vm_end
;
608 unsigned long length
= old_end
- old_start
;
609 unsigned long new_start
= old_start
- shift
;
610 unsigned long new_end
= old_end
- shift
;
611 struct mmu_gather tlb
;
613 BUG_ON(new_start
> new_end
);
616 * ensure there are no vmas between where we want to go
619 if (vma
!= find_vma(mm
, new_start
))
623 * cover the whole range: [new_start, old_end)
625 if (vma_adjust(vma
, new_start
, old_end
, vma
->vm_pgoff
, NULL
))
629 * move the page tables downwards, on failure we rely on
630 * process cleanup to remove whatever mess we made.
632 if (length
!= move_page_tables(vma
, old_start
,
633 vma
, new_start
, length
, false))
637 tlb_gather_mmu(&tlb
, mm
, old_start
, old_end
);
638 if (new_end
> old_start
) {
640 * when the old and new regions overlap clear from new_end.
642 free_pgd_range(&tlb
, new_end
, old_end
, new_end
,
643 vma
->vm_next
? vma
->vm_next
->vm_start
: USER_PGTABLES_CEILING
);
646 * otherwise, clean from old_start; this is done to not touch
647 * the address space in [new_end, old_start) some architectures
648 * have constraints on va-space that make this illegal (IA64) -
649 * for the others its just a little faster.
651 free_pgd_range(&tlb
, old_start
, old_end
, new_end
,
652 vma
->vm_next
? vma
->vm_next
->vm_start
: USER_PGTABLES_CEILING
);
654 tlb_finish_mmu(&tlb
, old_start
, old_end
);
657 * Shrink the vma to just the new range. Always succeeds.
659 vma_adjust(vma
, new_start
, new_end
, vma
->vm_pgoff
, NULL
);
665 * Finalizes the stack vm_area_struct. The flags and permissions are updated,
666 * the stack is optionally relocated, and some extra space is added.
668 int setup_arg_pages(struct linux_binprm
*bprm
,
669 unsigned long stack_top
,
670 int executable_stack
)
673 unsigned long stack_shift
;
674 struct mm_struct
*mm
= current
->mm
;
675 struct vm_area_struct
*vma
= bprm
->vma
;
676 struct vm_area_struct
*prev
= NULL
;
677 unsigned long vm_flags
;
678 unsigned long stack_base
;
679 unsigned long stack_size
;
680 unsigned long stack_expand
;
681 unsigned long rlim_stack
;
683 #ifdef CONFIG_STACK_GROWSUP
684 /* Limit stack size */
685 stack_base
= rlimit_max(RLIMIT_STACK
);
686 if (stack_base
> STACK_SIZE_MAX
)
687 stack_base
= STACK_SIZE_MAX
;
689 /* Make sure we didn't let the argument array grow too large. */
690 if (vma
->vm_end
- vma
->vm_start
> stack_base
)
693 stack_base
= PAGE_ALIGN(stack_top
- stack_base
);
695 stack_shift
= vma
->vm_start
- stack_base
;
696 mm
->arg_start
= bprm
->p
- stack_shift
;
697 bprm
->p
= vma
->vm_end
- stack_shift
;
699 stack_top
= arch_align_stack(stack_top
);
700 stack_top
= PAGE_ALIGN(stack_top
);
702 if (unlikely(stack_top
< mmap_min_addr
) ||
703 unlikely(vma
->vm_end
- vma
->vm_start
>= stack_top
- mmap_min_addr
))
706 stack_shift
= vma
->vm_end
- stack_top
;
708 bprm
->p
-= stack_shift
;
709 mm
->arg_start
= bprm
->p
;
713 bprm
->loader
-= stack_shift
;
714 bprm
->exec
-= stack_shift
;
716 down_write(&mm
->mmap_sem
);
717 vm_flags
= VM_STACK_FLAGS
;
720 * Adjust stack execute permissions; explicitly enable for
721 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
722 * (arch default) otherwise.
724 if (unlikely(executable_stack
== EXSTACK_ENABLE_X
))
726 else if (executable_stack
== EXSTACK_DISABLE_X
)
727 vm_flags
&= ~VM_EXEC
;
728 vm_flags
|= mm
->def_flags
;
729 vm_flags
|= VM_STACK_INCOMPLETE_SETUP
;
731 ret
= mprotect_fixup(vma
, &prev
, vma
->vm_start
, vma
->vm_end
,
737 /* Move stack pages down in memory. */
739 ret
= shift_arg_pages(vma
, stack_shift
);
744 /* mprotect_fixup is overkill to remove the temporary stack flags */
745 vma
->vm_flags
&= ~VM_STACK_INCOMPLETE_SETUP
;
748 /* save all the virtual space we're allowed */
749 stack_expand
= ((_STK_LIM
) & (PAGE_MASK
));
751 stack_expand
= 131072UL; /* randomly 32*4k (or 2*64k) pages */
753 stack_size
= vma
->vm_end
- vma
->vm_start
;
755 * Align this down to a page boundary as expand_stack
758 rlim_stack
= rlimit(RLIMIT_STACK
) & PAGE_MASK
;
759 if (stack_size
+ stack_expand
> rlim_stack
)
760 stack_expand
= rlim_stack
- stack_size
;
761 #ifdef CONFIG_STACK_GROWSUP
762 stack_base
= vma
->vm_end
+ stack_expand
;
764 stack_base
= vma
->vm_start
- stack_expand
;
766 current
->mm
->start_stack
= bprm
->p
;
767 ret
= expand_stack(vma
, stack_base
);
772 up_write(&mm
->mmap_sem
);
775 EXPORT_SYMBOL(setup_arg_pages
);
777 #endif /* CONFIG_MMU */
779 struct file
*open_exec(const char *name
)
783 struct filename tmp
= { .name
= name
};
784 static const struct open_flags open_exec_flags
= {
785 .open_flag
= O_LARGEFILE
| O_RDONLY
| __FMODE_EXEC
,
786 .acc_mode
= MAY_EXEC
| MAY_OPEN
,
787 .intent
= LOOKUP_OPEN
,
788 .lookup_flags
= LOOKUP_FOLLOW
,
791 file
= do_filp_open(AT_FDCWD
, &tmp
, &open_exec_flags
);
796 if (!S_ISREG(file_inode(file
)->i_mode
))
799 if (file
->f_path
.mnt
->mnt_flags
& MNT_NOEXEC
)
804 err
= deny_write_access(file
);
815 EXPORT_SYMBOL(open_exec
);
817 int kernel_read(struct file
*file
, loff_t offset
,
818 char *addr
, unsigned long count
)
826 /* The cast to a user pointer is valid due to the set_fs() */
827 result
= vfs_read(file
, (void __user
*)addr
, count
, &pos
);
832 EXPORT_SYMBOL(kernel_read
);
834 ssize_t
read_code(struct file
*file
, unsigned long addr
, loff_t pos
, size_t len
)
836 ssize_t res
= file
->f_op
->read(file
, (void __user
*)addr
, len
, &pos
);
838 flush_icache_range(addr
, addr
+ len
);
841 EXPORT_SYMBOL(read_code
);
843 static int exec_mmap(struct mm_struct
*mm
)
845 struct task_struct
*tsk
;
846 struct mm_struct
*old_mm
, *active_mm
;
848 /* Notify parent that we're no longer interested in the old VM */
850 old_mm
= current
->mm
;
851 mm_release(tsk
, old_mm
);
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.
861 down_read(&old_mm
->mmap_sem
);
862 if (unlikely(old_mm
->core_state
)) {
863 up_read(&old_mm
->mmap_sem
);
868 active_mm
= tsk
->active_mm
;
871 activate_mm(active_mm
, mm
);
872 tsk
->mm
->vmacache_seqnum
= 0;
875 arch_pick_mmap_layout(mm
);
877 up_read(&old_mm
->mmap_sem
);
878 BUG_ON(active_mm
!= old_mm
);
879 setmax_mm_hiwater_rss(&tsk
->signal
->maxrss
, old_mm
);
880 mm_update_next_owner(old_mm
);
889 * This function makes sure the current process has its own signal table,
890 * so that flush_signal_handlers can later reset the handlers without
891 * disturbing other processes. (Other processes might share the signal
892 * table via the CLONE_SIGHAND option to clone().)
894 static int de_thread(struct task_struct
*tsk
)
896 struct signal_struct
*sig
= tsk
->signal
;
897 struct sighand_struct
*oldsighand
= tsk
->sighand
;
898 spinlock_t
*lock
= &oldsighand
->siglock
;
900 if (thread_group_empty(tsk
))
901 goto no_thread_group
;
904 * Kill all other threads in the thread group.
907 if (signal_group_exit(sig
)) {
909 * Another group action in progress, just
910 * return so that the signal is processed.
912 spin_unlock_irq(lock
);
916 sig
->group_exit_task
= tsk
;
917 sig
->notify_count
= zap_other_threads(tsk
);
918 if (!thread_group_leader(tsk
))
921 while (sig
->notify_count
) {
922 __set_current_state(TASK_KILLABLE
);
923 spin_unlock_irq(lock
);
925 if (unlikely(__fatal_signal_pending(tsk
)))
929 spin_unlock_irq(lock
);
932 * At this point all other threads have exited, all we have to
933 * do is to wait for the thread group leader to become inactive,
934 * and to assume its PID:
936 if (!thread_group_leader(tsk
)) {
937 struct task_struct
*leader
= tsk
->group_leader
;
939 sig
->notify_count
= -1; /* for exit_notify() */
941 threadgroup_change_begin(tsk
);
942 write_lock_irq(&tasklist_lock
);
943 if (likely(leader
->exit_state
))
945 __set_current_state(TASK_KILLABLE
);
946 write_unlock_irq(&tasklist_lock
);
947 threadgroup_change_end(tsk
);
949 if (unlikely(__fatal_signal_pending(tsk
)))
954 * The only record we have of the real-time age of a
955 * process, regardless of execs it's done, is start_time.
956 * All the past CPU time is accumulated in signal_struct
957 * from sister threads now dead. But in this non-leader
958 * exec, nothing survives from the original leader thread,
959 * whose birth marks the true age of this process now.
960 * When we take on its identity by switching to its PID, we
961 * also take its birthdate (always earlier than our own).
963 tsk
->start_time
= leader
->start_time
;
965 BUG_ON(!same_thread_group(leader
, tsk
));
966 BUG_ON(has_group_leader_pid(tsk
));
968 * An exec() starts a new thread group with the
969 * TGID of the previous thread group. Rehash the
970 * two threads with a switched PID, and release
971 * the former thread group leader:
974 /* Become a process group leader with the old leader's pid.
975 * The old leader becomes a thread of the this thread group.
976 * Note: The old leader also uses this pid until release_task
977 * is called. Odd but simple and correct.
979 detach_pid(tsk
, PIDTYPE_PID
);
980 tsk
->pid
= leader
->pid
;
981 attach_pid(tsk
, PIDTYPE_PID
, task_pid(leader
));
982 transfer_pid(leader
, tsk
, PIDTYPE_PGID
);
983 transfer_pid(leader
, tsk
, PIDTYPE_SID
);
985 list_replace_rcu(&leader
->tasks
, &tsk
->tasks
);
986 list_replace_init(&leader
->sibling
, &tsk
->sibling
);
988 tsk
->group_leader
= tsk
;
989 leader
->group_leader
= tsk
;
991 tsk
->exit_signal
= SIGCHLD
;
992 leader
->exit_signal
= -1;
994 BUG_ON(leader
->exit_state
!= EXIT_ZOMBIE
);
995 leader
->exit_state
= EXIT_DEAD
;
998 * We are going to release_task()->ptrace_unlink() silently,
999 * the tracer can sleep in do_wait(). EXIT_DEAD guarantees
1000 * the tracer wont't block again waiting for this thread.
1002 if (unlikely(leader
->ptrace
))
1003 __wake_up_parent(leader
, leader
->parent
);
1004 write_unlock_irq(&tasklist_lock
);
1005 threadgroup_change_end(tsk
);
1007 release_task(leader
);
1010 sig
->group_exit_task
= NULL
;
1011 sig
->notify_count
= 0;
1014 /* we have changed execution domain */
1015 tsk
->exit_signal
= SIGCHLD
;
1018 flush_itimer_signals();
1020 if (atomic_read(&oldsighand
->count
) != 1) {
1021 struct sighand_struct
*newsighand
;
1023 * This ->sighand is shared with the CLONE_SIGHAND
1024 * but not CLONE_THREAD task, switch to the new one.
1026 newsighand
= kmem_cache_alloc(sighand_cachep
, GFP_KERNEL
);
1030 atomic_set(&newsighand
->count
, 1);
1031 memcpy(newsighand
->action
, oldsighand
->action
,
1032 sizeof(newsighand
->action
));
1034 write_lock_irq(&tasklist_lock
);
1035 spin_lock(&oldsighand
->siglock
);
1036 rcu_assign_pointer(tsk
->sighand
, newsighand
);
1037 spin_unlock(&oldsighand
->siglock
);
1038 write_unlock_irq(&tasklist_lock
);
1040 __cleanup_sighand(oldsighand
);
1043 BUG_ON(!thread_group_leader(tsk
));
1047 /* protects against exit_notify() and __exit_signal() */
1048 read_lock(&tasklist_lock
);
1049 sig
->group_exit_task
= NULL
;
1050 sig
->notify_count
= 0;
1051 read_unlock(&tasklist_lock
);
1055 char *get_task_comm(char *buf
, struct task_struct
*tsk
)
1057 /* buf must be at least sizeof(tsk->comm) in size */
1059 strncpy(buf
, tsk
->comm
, sizeof(tsk
->comm
));
1063 EXPORT_SYMBOL_GPL(get_task_comm
);
1066 * These functions flushes out all traces of the currently running executable
1067 * so that a new one can be started
1070 void set_task_comm(struct task_struct
*tsk
, char *buf
)
1073 trace_task_rename(tsk
, buf
);
1074 strlcpy(tsk
->comm
, buf
, sizeof(tsk
->comm
));
1076 perf_event_comm(tsk
);
1079 static void filename_to_taskname(char *tcomm
, const char *fn
, unsigned int len
)
1083 /* Copies the binary name from after last slash */
1084 for (i
= 0; (ch
= *(fn
++)) != '\0';) {
1086 i
= 0; /* overwrite what we wrote */
1094 int flush_old_exec(struct linux_binprm
* bprm
)
1099 * Make sure we have a private signal table and that
1100 * we are unassociated from the previous thread group.
1102 retval
= de_thread(current
);
1106 set_mm_exe_file(bprm
->mm
, bprm
->file
);
1108 filename_to_taskname(bprm
->tcomm
, bprm
->filename
, sizeof(bprm
->tcomm
));
1110 * Release all of the old mmap stuff
1112 acct_arg_size(bprm
, 0);
1113 retval
= exec_mmap(bprm
->mm
);
1116 #ifdef CONFIG_RKP_KDP
1117 if(rkp_cred_enable
){
1118 rkp_call(RKP_CMDID(0x43),(unsigned long long)current_cred(), (unsigned long long)bprm
->mm
->pgd
,0,0,0);
1120 #endif /*CONFIG_RKP_KDP*/
1122 bprm
->mm
= NULL
; /* We're using it now */
1126 ~(PF_RANDOMIZE
| PF_FORKNOEXEC
| PF_KTHREAD
| PF_NOFREEZE
);
1128 current
->personality
&= ~bprm
->per_clear
;
1131 * We have to apply CLOEXEC before we change whether the process is
1132 * dumpable (in setup_new_exec) to avoid a race with a process in userspace
1133 * trying to access the should-be-closed file descriptors of a process
1134 * undergoing exec(2).
1136 do_close_on_exec(current
->files
);
1142 EXPORT_SYMBOL(flush_old_exec
);
1144 void would_dump(struct linux_binprm
*bprm
, struct file
*file
)
1146 if (inode_permission2(file
->f_path
.mnt
, file_inode(file
), MAY_READ
) < 0)
1147 bprm
->interp_flags
|= BINPRM_FLAGS_ENFORCE_NONDUMP
;
1149 EXPORT_SYMBOL(would_dump
);
1151 void setup_new_exec(struct linux_binprm
* bprm
)
1153 arch_pick_mmap_layout(current
->mm
);
1155 /* This is the point of no return */
1156 current
->sas_ss_sp
= current
->sas_ss_size
= 0;
1158 if (uid_eq(current_euid(), current_uid()) && gid_eq(current_egid(), current_gid()))
1159 set_dumpable(current
->mm
, SUID_DUMP_USER
);
1161 set_dumpable(current
->mm
, suid_dumpable
);
1163 set_task_comm(current
, bprm
->tcomm
);
1165 /* Set the new mm task size. We have to do that late because it may
1166 * depend on TIF_32BIT which is only updated in flush_thread() on
1167 * some architectures like powerpc
1169 current
->mm
->task_size
= TASK_SIZE
;
1171 /* install the new credentials */
1172 if (!uid_eq(bprm
->cred
->uid
, current_euid()) ||
1173 !gid_eq(bprm
->cred
->gid
, current_egid())) {
1174 current
->pdeath_signal
= 0;
1176 would_dump(bprm
, bprm
->file
);
1177 if (bprm
->interp_flags
& BINPRM_FLAGS_ENFORCE_NONDUMP
)
1178 set_dumpable(current
->mm
, suid_dumpable
);
1181 /* An exec changes our domain. We are no longer part of the thread
1184 current
->self_exec_id
++;
1186 flush_signal_handlers(current
, 0);
1188 EXPORT_SYMBOL(setup_new_exec
);
1191 * Prepare credentials and lock ->cred_guard_mutex.
1192 * install_exec_creds() commits the new creds and drops the lock.
1193 * Or, if exec fails before, free_bprm() should release ->cred and
1196 int prepare_bprm_creds(struct linux_binprm
*bprm
)
1198 if (mutex_lock_interruptible(¤t
->signal
->cred_guard_mutex
))
1199 return -ERESTARTNOINTR
;
1201 bprm
->cred
= prepare_exec_creds();
1202 if (likely(bprm
->cred
))
1205 mutex_unlock(¤t
->signal
->cred_guard_mutex
);
1209 void free_bprm(struct linux_binprm
*bprm
)
1211 free_arg_pages(bprm
);
1213 mutex_unlock(¤t
->signal
->cred_guard_mutex
);
1214 abort_creds(bprm
->cred
);
1216 /* If a binfmt changed the interp, free it. */
1217 if (bprm
->interp
!= bprm
->filename
)
1218 kfree(bprm
->interp
);
1222 int bprm_change_interp(char *interp
, struct linux_binprm
*bprm
)
1224 /* If a binfmt changed the interp, free it first. */
1225 if (bprm
->interp
!= bprm
->filename
)
1226 kfree(bprm
->interp
);
1227 bprm
->interp
= kstrdup(interp
, GFP_KERNEL
);
1232 EXPORT_SYMBOL(bprm_change_interp
);
1235 * install the new credentials for this executable
1237 void install_exec_creds(struct linux_binprm
*bprm
)
1239 security_bprm_committing_creds(bprm
);
1241 commit_creds(bprm
->cred
);
1245 * Disable monitoring for regular users
1246 * when executing setuid binaries. Must
1247 * wait until new credentials are committed
1248 * by commit_creds() above
1250 if (get_dumpable(current
->mm
) != SUID_DUMP_USER
)
1251 perf_event_exit_task(current
);
1253 * cred_guard_mutex must be held at least to this point to prevent
1254 * ptrace_attach() from altering our determination of the task's
1255 * credentials; any time after this it may be unlocked.
1257 security_bprm_committed_creds(bprm
);
1258 mutex_unlock(¤t
->signal
->cred_guard_mutex
);
1260 EXPORT_SYMBOL(install_exec_creds
);
1263 * determine how safe it is to execute the proposed program
1264 * - the caller must hold ->cred_guard_mutex to protect against
1265 * PTRACE_ATTACH or seccomp thread-sync
1267 static int check_unsafe_exec(struct linux_binprm
*bprm
)
1269 struct task_struct
*p
= current
, *t
;
1274 if (p
->ptrace
& PT_PTRACE_CAP
)
1275 bprm
->unsafe
|= LSM_UNSAFE_PTRACE_CAP
;
1277 bprm
->unsafe
|= LSM_UNSAFE_PTRACE
;
1281 * This isn't strictly necessary, but it makes it harder for LSMs to
1284 if (task_no_new_privs(current
))
1285 bprm
->unsafe
|= LSM_UNSAFE_NO_NEW_PRIVS
;
1288 spin_lock(&p
->fs
->lock
);
1290 for (t
= next_thread(p
); t
!= p
; t
= next_thread(t
)) {
1296 if (p
->fs
->users
> n_fs
) {
1297 bprm
->unsafe
|= LSM_UNSAFE_SHARE
;
1300 if (!p
->fs
->in_exec
) {
1305 spin_unlock(&p
->fs
->lock
);
1310 static void bprm_fill_uid(struct linux_binprm
*bprm
)
1312 struct inode
*inode
;
1317 /* clear any previous set[ug]id data from a previous binary */
1318 bprm
->cred
->euid
= current_euid();
1319 bprm
->cred
->egid
= current_egid();
1321 if (bprm
->file
->f_path
.mnt
->mnt_flags
& MNT_NOSUID
)
1324 if (task_no_new_privs(current
))
1327 inode
= file_inode(bprm
->file
);
1328 mode
= ACCESS_ONCE(inode
->i_mode
);
1329 if (!(mode
& (S_ISUID
|S_ISGID
)))
1332 /* Be careful if suid/sgid is set */
1333 mutex_lock(&inode
->i_mutex
);
1335 /* reload atomically mode/uid/gid now that lock held */
1336 mode
= inode
->i_mode
;
1339 mutex_unlock(&inode
->i_mutex
);
1341 /* We ignore suid/sgid if there are no mappings for them in the ns */
1342 if (!kuid_has_mapping(bprm
->cred
->user_ns
, uid
) ||
1343 !kgid_has_mapping(bprm
->cred
->user_ns
, gid
))
1346 if (mode
& S_ISUID
) {
1347 bprm
->per_clear
|= PER_CLEAR_ON_SETID
;
1348 bprm
->cred
->euid
= uid
;
1351 if ((mode
& (S_ISGID
| S_IXGRP
)) == (S_ISGID
| S_IXGRP
)) {
1352 bprm
->per_clear
|= PER_CLEAR_ON_SETID
;
1353 bprm
->cred
->egid
= gid
;
1358 * Fill the binprm structure from the inode.
1359 * Check permissions, then read the first 128 (BINPRM_BUF_SIZE) bytes
1361 * This may be called multiple times for binary chains (scripts for example).
1363 int prepare_binprm(struct linux_binprm
*bprm
)
1367 if (bprm
->file
->f_op
== NULL
)
1370 bprm_fill_uid(bprm
);
1372 /* fill in binprm security blob */
1373 retval
= security_bprm_set_creds(bprm
);
1376 bprm
->cred_prepared
= 1;
1378 memset(bprm
->buf
, 0, BINPRM_BUF_SIZE
);
1379 return kernel_read(bprm
->file
, 0, bprm
->buf
, BINPRM_BUF_SIZE
);
1382 EXPORT_SYMBOL(prepare_binprm
);
1385 * Arguments are '\0' separated strings found at the location bprm->p
1386 * points to; chop off the first by relocating brpm->p to right after
1387 * the first '\0' encountered.
1389 int remove_arg_zero(struct linux_binprm
*bprm
)
1392 unsigned long offset
;
1400 offset
= bprm
->p
& ~PAGE_MASK
;
1401 page
= get_arg_page(bprm
, bprm
->p
, 0);
1406 kaddr
= kmap_atomic(page
);
1408 for (; offset
< PAGE_SIZE
&& kaddr
[offset
];
1409 offset
++, bprm
->p
++)
1412 kunmap_atomic(kaddr
);
1415 if (offset
== PAGE_SIZE
)
1416 free_arg_page(bprm
, (bprm
->p
>> PAGE_SHIFT
) - 1);
1417 } while (offset
== PAGE_SIZE
);
1426 EXPORT_SYMBOL(remove_arg_zero
);
1429 * cycle the list of binary formats handler, until one recognizes the image
1431 int search_binary_handler(struct linux_binprm
*bprm
)
1433 unsigned int depth
= bprm
->recursion_depth
;
1435 struct linux_binfmt
*fmt
;
1436 pid_t old_pid
, old_vpid
;
1438 /* This allows 4 levels of binfmt rewrites before failing hard. */
1442 retval
= security_bprm_check(bprm
);
1446 retval
= audit_bprm(bprm
);
1450 /* Need to fetch pid before load_binary changes it */
1451 old_pid
= current
->pid
;
1453 old_vpid
= task_pid_nr_ns(current
, task_active_pid_ns(current
->parent
));
1457 for (try=0; try<2; try++) {
1458 read_lock(&binfmt_lock
);
1459 list_for_each_entry(fmt
, &formats
, lh
) {
1460 int (*fn
)(struct linux_binprm
*) = fmt
->load_binary
;
1463 if (!try_module_get(fmt
->module
))
1465 read_unlock(&binfmt_lock
);
1466 bprm
->recursion_depth
= depth
+ 1;
1468 bprm
->recursion_depth
= depth
;
1471 trace_sched_process_exec(current
, old_pid
, bprm
);
1472 ptrace_event(PTRACE_EVENT_EXEC
, old_vpid
);
1475 allow_write_access(bprm
->file
);
1479 current
->did_exec
= 1;
1480 proc_exec_connector(current
);
1483 read_lock(&binfmt_lock
);
1485 if (retval
!= -ENOEXEC
|| bprm
->mm
== NULL
)
1488 read_unlock(&binfmt_lock
);
1492 read_unlock(&binfmt_lock
);
1493 #ifdef CONFIG_MODULES
1494 if (retval
!= -ENOEXEC
|| bprm
->mm
== NULL
) {
1497 #define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
1498 if (printable(bprm
->buf
[0]) &&
1499 printable(bprm
->buf
[1]) &&
1500 printable(bprm
->buf
[2]) &&
1501 printable(bprm
->buf
[3]))
1502 break; /* -ENOEXEC */
1504 break; /* -ENOEXEC */
1505 request_module("binfmt-%04x", *(unsigned short *)(&bprm
->buf
[2]));
1514 EXPORT_SYMBOL(search_binary_handler
);
1516 #if defined CONFIG_SEC_RESTRICT_FORK
1517 #if defined CONFIG_SEC_RESTRICT_ROOTING_LOG
1518 #define PRINT_LOG(...) printk(KERN_ERR __VA_ARGS__)
1520 #define PRINT_LOG(...)
1521 #endif // End of CONFIG_SEC_RESTRICT_ROOTING_LOG
1523 #define CHECK_ROOT_UID(x) (x->cred->uid == 0 || x->cred->gid == 0 || \
1524 x->cred->euid == 0 || x->cred->egid == 0 || \
1525 x->cred->suid == 0 || x->cred->sgid == 0)
1527 /* sec_check_execpath
1528 return value : give task's exec path is matched or not
1530 int sec_check_execpath(struct mm_struct
*mm
, char *denypath
)
1532 struct file
*exe_file
;
1533 char *path
, *pathbuf
= NULL
;
1534 unsigned int path_length
= 0, denypath_length
= 0;
1540 if (!(exe_file
= get_mm_exe_file(mm
))) {
1541 PRINT_LOG("Cannot get exe from task->mm.\n");
1545 if (!(pathbuf
= kmalloc(PATH_MAX
, GFP_TEMPORARY
))) {
1546 PRINT_LOG("failed to kmalloc for pathbuf\n");
1550 path
= d_path(&exe_file
->f_path
, pathbuf
, PATH_MAX
);
1552 PRINT_LOG("Error get path..\n");
1556 path_length
= strlen(path
);
1557 denypath_length
= strlen(denypath
);
1559 if (!strncmp(path
, denypath
, (path_length
< denypath_length
) ?
1560 path_length
: denypath_length
)) {
1571 EXPORT_SYMBOL(sec_check_execpath
);
1573 #ifdef CONFIG_RKP_KDP
1574 static int rkp_restrict_fork(void)
1576 struct cred
*shellcred
;
1578 if(rkp_is_nonroot(current
)){
1579 shellcred
= prepare_creds();
1583 shellcred
->uid
= 2000;
1584 shellcred
->gid
= 2000;
1585 shellcred
->euid
= 2000;
1586 shellcred
->egid
= 2000;
1587 commit_creds(shellcred
);
1591 #endif /*CONFIG_RKP_KDP*/
1592 static int sec_restrict_fork(void)
1594 struct cred
*shellcred
;
1596 struct task_struct
*parent_tsk
;
1597 struct mm_struct
*parent_mm
= NULL
;
1598 const struct cred
*parent_cred
;
1600 read_lock(&tasklist_lock
);
1601 parent_tsk
= current
->parent
;
1603 read_unlock(&tasklist_lock
);
1607 get_task_struct(parent_tsk
);
1608 /* holding on to the task struct is enough so just release
1609 * the tasklist lock here */
1610 read_unlock(&tasklist_lock
);
1612 if (current
->pid
== 1 || parent_tsk
->pid
== 1)
1615 /* get current->parent's mm struct to access it's mm
1616 * and to keep it alive */
1617 parent_mm
= get_task_mm(parent_tsk
);
1619 if (current
->mm
== NULL
|| parent_mm
== NULL
)
1622 if (sec_check_execpath(parent_mm
, "/sbin/adbd")) {
1623 shellcred
= prepare_creds();
1629 shellcred
->uid
= 2000;
1630 shellcred
->gid
= 2000;
1631 shellcred
->euid
= 2000;
1632 shellcred
->egid
= 2000;
1633 commit_creds(shellcred
);
1638 if (sec_check_execpath(current
->mm
, "/data/")) {
1643 parent_cred
= get_task_cred(parent_tsk
);
1646 if (!CHECK_ROOT_UID(parent_tsk
))
1650 put_cred(parent_cred
);
1654 put_task_struct(parent_tsk
);
1658 #endif /* End of CONFIG_SEC_RESTRICT_FORK */
1661 * sys_execve() executes a new program.
1663 static int do_execve_common(const char *filename
,
1664 struct user_arg_ptr argv
,
1665 struct user_arg_ptr envp
)
1667 struct linux_binprm
*bprm
;
1669 struct files_struct
*displaced
;
1672 const struct cred
*cred
= current_cred();
1676 * We move the actual failure in case of RLIMIT_NPROC excess from
1677 * set*uid() to execve() because too many poorly written programs
1678 * don't check setuid() return code. Here we additionally recheck
1679 * whether NPROC limit is still exceeded.
1681 if ((current
->flags
& PF_NPROC_EXCEEDED
) &&
1682 atomic_read(&cred
->user
->processes
) > rlimit(RLIMIT_NPROC
)) {
1687 /* We're below the limit (still or again), so we don't want to make
1688 * further execve() calls fail. */
1689 current
->flags
&= ~PF_NPROC_EXCEEDED
;
1691 retval
= unshare_files(&displaced
);
1696 bprm
= kzalloc(sizeof(*bprm
), GFP_KERNEL
);
1700 retval
= prepare_bprm_creds(bprm
);
1704 retval
= check_unsafe_exec(bprm
);
1707 clear_in_exec
= retval
;
1708 current
->in_execve
= 1;
1710 file
= open_exec(filename
);
1711 retval
= PTR_ERR(file
);
1718 bprm
->filename
= filename
;
1719 bprm
->interp
= filename
;
1721 retval
= bprm_mm_init(bprm
);
1725 bprm
->argc
= count(argv
, MAX_ARG_STRINGS
);
1726 if ((retval
= bprm
->argc
) < 0)
1729 bprm
->envc
= count(envp
, MAX_ARG_STRINGS
);
1730 if ((retval
= bprm
->envc
) < 0)
1733 retval
= prepare_binprm(bprm
);
1737 retval
= copy_strings_kernel(1, &bprm
->filename
, bprm
);
1741 bprm
->exec
= bprm
->p
;
1742 retval
= copy_strings(bprm
->envc
, envp
, bprm
);
1746 retval
= copy_strings(bprm
->argc
, argv
, bprm
);
1750 /* search_binary_handler can release file and it may be freed */
1751 is_su
= d_is_su(file
->f_dentry
);
1753 retval
= search_binary_handler(bprm
);
1757 if (is_su
&& capable(CAP_SYS_ADMIN
)) {
1758 current
->flags
|= PF_SU
;
1762 /* execve succeeded */
1763 current
->fs
->in_exec
= 0;
1764 current
->in_execve
= 0;
1765 acct_update_integrals(current
);
1768 put_files_struct(displaced
);
1773 acct_arg_size(bprm
, 0);
1779 allow_write_access(bprm
->file
);
1785 current
->fs
->in_exec
= 0;
1786 current
->in_execve
= 0;
1793 reset_files_struct(displaced
);
1798 int do_execve(const char *filename
,
1799 const char __user
*const __user
*__argv
,
1800 const char __user
*const __user
*__envp
)
1802 struct user_arg_ptr argv
= { .ptr
.native
= __argv
};
1803 struct user_arg_ptr envp
= { .ptr
.native
= __envp
};
1804 return do_execve_common(filename
, argv
, envp
);
1807 #ifdef CONFIG_COMPAT
1808 static int compat_do_execve(const char *filename
,
1809 const compat_uptr_t __user
*__argv
,
1810 const compat_uptr_t __user
*__envp
)
1812 struct user_arg_ptr argv
= {
1814 .ptr
.compat
= __argv
,
1816 struct user_arg_ptr envp
= {
1818 .ptr
.compat
= __envp
,
1820 return do_execve_common(filename
, argv
, envp
);
1824 void set_binfmt(struct linux_binfmt
*new)
1826 struct mm_struct
*mm
= current
->mm
;
1829 module_put(mm
->binfmt
->module
);
1833 __module_get(new->module
);
1836 EXPORT_SYMBOL(set_binfmt
);
1839 * set_dumpable converts traditional three-value dumpable to two flags and
1840 * stores them into mm->flags. It modifies lower two bits of mm->flags, but
1841 * these bits are not changed atomically. So get_dumpable can observe the
1842 * intermediate state. To avoid doing unexpected behavior, get get_dumpable
1843 * return either old dumpable or new one by paying attention to the order of
1844 * modifying the bits.
1846 * dumpable | mm->flags (binary)
1847 * old new | initial interim final
1848 * ---------+-----------------------
1856 * (*) get_dumpable regards interim value of 10 as 11.
1858 void set_dumpable(struct mm_struct
*mm
, int value
)
1861 case SUID_DUMP_DISABLE
:
1862 clear_bit(MMF_DUMPABLE
, &mm
->flags
);
1864 clear_bit(MMF_DUMP_SECURELY
, &mm
->flags
);
1866 case SUID_DUMP_USER
:
1867 set_bit(MMF_DUMPABLE
, &mm
->flags
);
1869 clear_bit(MMF_DUMP_SECURELY
, &mm
->flags
);
1871 case SUID_DUMP_ROOT
:
1872 set_bit(MMF_DUMP_SECURELY
, &mm
->flags
);
1874 set_bit(MMF_DUMPABLE
, &mm
->flags
);
1879 int __get_dumpable(unsigned long mm_flags
)
1883 ret
= mm_flags
& MMF_DUMPABLE_MASK
;
1884 return (ret
> SUID_DUMP_USER
) ? SUID_DUMP_ROOT
: ret
;
1888 * This returns the actual value of the suid_dumpable flag. For things
1889 * that are using this for checking for privilege transitions, it must
1890 * test against SUID_DUMP_USER rather than treating it as a boolean
1893 int get_dumpable(struct mm_struct
*mm
)
1895 return __get_dumpable(mm
->flags
);
1898 SYSCALL_DEFINE3(execve
,
1899 const char __user
*, filename
,
1900 const char __user
*const __user
*, argv
,
1901 const char __user
*const __user
*, envp
)
1903 struct filename
*path
= getname(filename
);
1904 int error
= PTR_ERR(path
);
1905 if (!IS_ERR(path
)) {
1906 #ifdef CONFIG_RKP_KDP
1907 if(rkp_cred_enable
){
1908 rkp_call(RKP_CMDID(0x4b),(u64
)path
->name
,0,0,0,0);
1911 #if defined CONFIG_SEC_RESTRICT_FORK
1912 if(CHECK_ROOT_UID(current
)){
1913 if(sec_restrict_fork()){
1914 PRINT_LOG("Restricted making process. PID = %d(%s) "
1916 current
->pid
, current
->comm
,
1917 current
->parent
->pid
, current
->parent
->comm
);
1921 #ifdef CONFIG_RKP_KDP
1922 if(CHECK_ROOT_UID(current
) && rkp_cred_enable
) {
1923 if(rkp_restrict_fork()){
1924 PRINT_LOG("RKP_KDP Restricted making process. PID = %d(%s) "
1926 current
->pid
, current
->comm
,
1927 current
->parent
->pid
, current
->parent
->comm
);
1932 #endif // End of CONFIG_SEC_RESTRICT_FORK
1933 error
= do_execve(path
->name
, argv
, envp
);
1938 #ifdef CONFIG_COMPAT
1939 asmlinkage
long compat_sys_execve(const char __user
* filename
,
1940 const compat_uptr_t __user
* argv
,
1941 const compat_uptr_t __user
* envp
)
1943 struct filename
*path
= getname(filename
);
1944 int error
= PTR_ERR(path
);
1945 if (!IS_ERR(path
)) {
1946 error
= compat_do_execve(path
->name
, argv
, envp
);