hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/fork.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/kernel/fork.c
34 *
....@@ -39,10 +40,8 @@
3940 #include <linux/binfmts.h>
4041 #include <linux/mman.h>
4142 #include <linux/mmu_notifier.h>
42
-#include <linux/hmm.h>
4343 #include <linux/fs.h>
4444 #include <linux/mm.h>
45
-#include <linux/kprobes.h>
4645 #include <linux/vmacache.h>
4746 #include <linux/nsproxy.h>
4847 #include <linux/capability.h>
....@@ -80,7 +79,6 @@
8079 #include <linux/blkdev.h>
8180 #include <linux/fs_struct.h>
8281 #include <linux/magic.h>
83
-#include <linux/sched/mm.h>
8482 #include <linux/perf_event.h>
8583 #include <linux/posix-timers.h>
8684 #include <linux/user-return-notifier.h>
....@@ -94,10 +92,12 @@
9492 #include <linux/kcov.h>
9593 #include <linux/livepatch.h>
9694 #include <linux/thread_info.h>
97
-#include <linux/cpufreq_times.h>
95
+#include <linux/stackleak.h>
96
+#include <linux/kasan.h>
9897 #include <linux/scs.h>
98
+#include <linux/io_uring.h>
99
+#include <linux/cpufreq_times.h>
99100
100
-#include <asm/pgtable.h>
101101 #include <asm/pgalloc.h>
102102 #include <linux/uaccess.h>
103103 #include <asm/mmu_context.h>
....@@ -109,6 +109,8 @@
109109 #define CREATE_TRACE_POINTS
110110 #include <trace/events/task.h>
111111
112
+#undef CREATE_TRACE_POINTS
113
+#include <trace/hooks/sched.h>
112114 /*
113115 * Minimum number of threads to boot the kernel
114116 */
....@@ -119,17 +121,29 @@
119121 */
120122 #define MAX_THREADS FUTEX_TID_MASK
121123
124
+EXPORT_TRACEPOINT_SYMBOL_GPL(task_newtask);
125
+
122126 /*
123127 * Protected counters by write_lock_irq(&tasklist_lock)
124128 */
125129 unsigned long total_forks; /* Handle normal Linux uptimes. */
126130 int nr_threads; /* The idle threads do not count.. */
127131
128
-int max_threads; /* tunable limit on nr_threads */
132
+static int max_threads; /* tunable limit on nr_threads */
133
+
134
+#define NAMED_ARRAY_INDEX(x) [x] = __stringify(x)
135
+
136
+static const char * const resident_page_types[] = {
137
+ NAMED_ARRAY_INDEX(MM_FILEPAGES),
138
+ NAMED_ARRAY_INDEX(MM_ANONPAGES),
139
+ NAMED_ARRAY_INDEX(MM_SWAPENTS),
140
+ NAMED_ARRAY_INDEX(MM_SHMEMPAGES),
141
+};
129142
130143 DEFINE_PER_CPU(unsigned long, process_counts) = 0;
131144
132145 __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
146
+EXPORT_SYMBOL_GPL(tasklist_lock);
133147
134148 #ifdef CONFIG_PROVE_RCU
135149 int lockdep_tasklist_lock_is_held(void)
....@@ -217,6 +231,9 @@
217231 if (!s)
218232 continue;
219233
234
+ /* Mark stack accessible for KASAN. */
235
+ kasan_unpoison_range(s->addr, THREAD_SIZE);
236
+
220237 /* Clear stale pointers from reused stack. */
221238 memset(s->addr, 0, THREAD_SIZE);
222239
....@@ -225,9 +242,14 @@
225242 return s->addr;
226243 }
227244
245
+ /*
246
+ * Allocated stacks are cached and later reused by new threads,
247
+ * so memcg accounting is performed manually on assigning/releasing
248
+ * stacks to tasks. Drop __GFP_ACCOUNT.
249
+ */
228250 stack = __vmalloc_node_range(THREAD_SIZE, THREAD_ALIGN,
229251 VMALLOC_START, VMALLOC_END,
230
- THREADINFO_GFP,
252
+ THREADINFO_GFP & ~__GFP_ACCOUNT,
231253 PAGE_KERNEL,
232254 0, node, __builtin_return_address(0));
233255
....@@ -246,7 +268,7 @@
246268 THREAD_SIZE_ORDER);
247269
248270 if (likely(page)) {
249
- tsk->stack = page_address(page);
271
+ tsk->stack = kasan_reset_tag(page_address(page));
250272 return tsk->stack;
251273 }
252274 return NULL;
....@@ -256,8 +278,13 @@
256278 static inline void free_thread_stack(struct task_struct *tsk)
257279 {
258280 #ifdef CONFIG_VMAP_STACK
259
- if (task_stack_vm_area(tsk)) {
281
+ struct vm_struct *vm = task_stack_vm_area(tsk);
282
+
283
+ if (vm) {
260284 int i;
285
+
286
+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
287
+ memcg_kmem_uncharge_page(vm->pages[i], 0);
261288
262289 for (i = 0; i < NR_CACHED_STACKS; i++) {
263290 if (this_cpu_cmpxchg(cached_stacks[i],
....@@ -282,6 +309,7 @@
282309 {
283310 unsigned long *stack;
284311 stack = kmem_cache_alloc_node(thread_stack_cache, THREADINFO_GFP, node);
312
+ stack = kasan_reset_tag(stack);
285313 tsk->stack = stack;
286314 return stack;
287315 }
....@@ -334,8 +362,15 @@
334362 struct vm_area_struct *new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
335363
336364 if (new) {
337
- *new = *orig;
338
- INIT_LIST_HEAD(&new->anon_vma_chain);
365
+ ASSERT_EXCLUSIVE_WRITER(orig->vm_flags);
366
+ ASSERT_EXCLUSIVE_WRITER(orig->vm_file);
367
+ /*
368
+ * orig->shared.rb may be modified concurrently, but the clone
369
+ * will be reinitialized.
370
+ */
371
+ *new = data_race(*orig);
372
+ INIT_VMA(new);
373
+ new->vm_next = new->vm_prev = NULL;
339374 }
340375 return new;
341376 }
....@@ -350,6 +385,22 @@
350385 void *stack = task_stack_page(tsk);
351386 struct vm_struct *vm = task_stack_vm_area(tsk);
352387
388
+
389
+ /* All stack pages are in the same node. */
390
+ if (vm)
391
+ mod_lruvec_page_state(vm->pages[0], NR_KERNEL_STACK_KB,
392
+ account * (THREAD_SIZE / 1024));
393
+ else
394
+ mod_lruvec_slab_state(stack, NR_KERNEL_STACK_KB,
395
+ account * (THREAD_SIZE / 1024));
396
+}
397
+
398
+static int memcg_charge_kernel_stack(struct task_struct *tsk)
399
+{
400
+#ifdef CONFIG_VMAP_STACK
401
+ struct vm_struct *vm = task_stack_vm_area(tsk);
402
+ int ret;
403
+
353404 BUILD_BUG_ON(IS_ENABLED(CONFIG_VMAP_STACK) && PAGE_SIZE % 1024 != 0);
354405
355406 if (vm) {
....@@ -358,27 +409,19 @@
358409 BUG_ON(vm->nr_pages != THREAD_SIZE / PAGE_SIZE);
359410
360411 for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) {
361
- mod_zone_page_state(page_zone(vm->pages[i]),
362
- NR_KERNEL_STACK_KB,
363
- PAGE_SIZE / 1024 * account);
412
+ /*
413
+ * If memcg_kmem_charge_page() fails, page->mem_cgroup
414
+ * pointer is NULL, and memcg_kmem_uncharge_page() in
415
+ * free_thread_stack() will ignore this page.
416
+ */
417
+ ret = memcg_kmem_charge_page(vm->pages[i], GFP_KERNEL,
418
+ 0);
419
+ if (ret)
420
+ return ret;
364421 }
365
-
366
- /* All stack pages belong to the same memcg. */
367
- mod_memcg_page_state(vm->pages[0], MEMCG_KERNEL_STACK_KB,
368
- account * (THREAD_SIZE / 1024));
369
- } else {
370
- /*
371
- * All stack pages are in the same zone and belong to the
372
- * same memcg.
373
- */
374
- struct page *first_page = virt_to_page(stack);
375
-
376
- mod_zone_page_state(page_zone(first_page), NR_KERNEL_STACK_KB,
377
- THREAD_SIZE / 1024 * account);
378
-
379
- mod_memcg_page_state(first_page, MEMCG_KERNEL_STACK_KB,
380
- account * (THREAD_SIZE / 1024));
381422 }
423
+#endif
424
+ return 0;
382425 }
383426
384427 static void release_task_stack(struct task_struct *tsk)
....@@ -397,9 +440,10 @@
397440 #ifdef CONFIG_THREAD_INFO_IN_TASK
398441 void put_task_stack(struct task_struct *tsk)
399442 {
400
- if (atomic_dec_and_test(&tsk->stack_refcount))
443
+ if (refcount_dec_and_test(&tsk->stack_refcount))
401444 release_task_stack(tsk);
402445 }
446
+EXPORT_SYMBOL_GPL(put_task_stack);
403447 #endif
404448
405449 void free_task(struct task_struct *tsk)
....@@ -407,6 +451,7 @@
407451 cpufreq_task_times_exit(tsk);
408452 scs_release(tsk);
409453
454
+ trace_android_vh_free_task(tsk);
410455 #ifndef CONFIG_THREAD_INFO_IN_TASK
411456 /*
412457 * The task is finally done with both the stack and thread_info,
....@@ -418,11 +463,10 @@
418463 * If the task had a separate stack allocation, it should be gone
419464 * by now.
420465 */
421
- WARN_ON_ONCE(atomic_read(&tsk->stack_refcount) != 0);
466
+ WARN_ON_ONCE(refcount_read(&tsk->stack_refcount) != 0);
422467 #endif
423468 rt_mutex_debug_task_free(tsk);
424469 ftrace_graph_exit_task(tsk);
425
- put_seccomp_filter(tsk);
426470 arch_release_task_struct(tsk);
427471 if (tsk->flags & PF_KTHREAD)
428472 free_kthread_struct(tsk);
....@@ -434,14 +478,14 @@
434478 static __latent_entropy int dup_mmap(struct mm_struct *mm,
435479 struct mm_struct *oldmm)
436480 {
437
- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
481
+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev, *last = NULL;
438482 struct rb_node **rb_link, *rb_parent;
439483 int retval;
440484 unsigned long charge;
441485 LIST_HEAD(uf);
442486
443487 uprobe_start_dup_mmap();
444
- if (down_write_killable(&oldmm->mmap_sem)) {
488
+ if (mmap_write_lock_killable(oldmm)) {
445489 retval = -EINTR;
446490 goto fail_uprobe_end;
447491 }
....@@ -450,7 +494,7 @@
450494 /*
451495 * Not linked in yet - no deadlock potential:
452496 */
453
- down_write_nested(&mm->mmap_sem, SINGLE_DEPTH_NESTING);
497
+ mmap_write_lock_nested(mm, SINGLE_DEPTH_NESTING);
454498
455499 /* No ordering required: file already has been exposed. */
456500 RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm));
....@@ -505,14 +549,15 @@
505549 if (retval)
506550 goto fail_nomem_anon_vma_fork;
507551 if (tmp->vm_flags & VM_WIPEONFORK) {
508
- /* VM_WIPEONFORK gets a clean slate in the child. */
552
+ /*
553
+ * VM_WIPEONFORK gets a clean slate in the child.
554
+ * Don't prepare anon_vma until fault since we don't
555
+ * copy page for current vma.
556
+ */
509557 tmp->anon_vma = NULL;
510
- if (anon_vma_prepare(tmp))
511
- goto fail_nomem_anon_vma_fork;
512558 } else if (anon_vma_fork(tmp, mpnt))
513559 goto fail_nomem_anon_vma_fork;
514560 tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
515
- tmp->vm_next = tmp->vm_prev = NULL;
516561 file = tmp->vm_file;
517562 if (file) {
518563 struct inode *inode = file_inode(file);
....@@ -520,10 +565,10 @@
520565
521566 get_file(file);
522567 if (tmp->vm_flags & VM_DENYWRITE)
523
- atomic_dec(&inode->i_writecount);
568
+ put_write_access(inode);
524569 i_mmap_lock_write(mapping);
525570 if (tmp->vm_flags & VM_SHARED)
526
- atomic_inc(&mapping->i_mmap_writable);
571
+ mapping_allow_writable(mapping);
527572 flush_dcache_mmap_lock(mapping);
528573 /* insert tmp into the share list, just after mpnt */
529574 vma_interval_tree_insert_after(tmp, mpnt,
....@@ -553,8 +598,18 @@
553598 rb_parent = &tmp->vm_rb;
554599
555600 mm->map_count++;
556
- if (!(tmp->vm_flags & VM_WIPEONFORK))
557
- retval = copy_page_range(mm, oldmm, mpnt);
601
+ if (!(tmp->vm_flags & VM_WIPEONFORK)) {
602
+ if (IS_ENABLED(CONFIG_SPECULATIVE_PAGE_FAULT)) {
603
+ /*
604
+ * Mark this VMA as changing to prevent the
605
+ * speculative page fault hanlder to process
606
+ * it until the TLB are flushed below.
607
+ */
608
+ last = mpnt;
609
+ vm_write_begin(mpnt);
610
+ }
611
+ retval = copy_page_range(tmp, mpnt);
612
+ }
558613
559614 if (tmp->vm_ops && tmp->vm_ops->open)
560615 tmp->vm_ops->open(tmp);
....@@ -565,9 +620,25 @@
565620 /* a new mm has just been created */
566621 retval = arch_dup_mmap(oldmm, mm);
567622 out:
568
- up_write(&mm->mmap_sem);
623
+ mmap_write_unlock(mm);
569624 flush_tlb_mm(oldmm);
570
- up_write(&oldmm->mmap_sem);
625
+
626
+ if (IS_ENABLED(CONFIG_SPECULATIVE_PAGE_FAULT)) {
627
+ /*
628
+ * Since the TLB has been flush, we can safely unmark the
629
+ * copied VMAs and allows the speculative page fault handler to
630
+ * process them again.
631
+ * Walk back the VMA list from the last marked VMA.
632
+ */
633
+ for (; last; last = last->vm_prev) {
634
+ if (last->vm_flags & VM_DONTCOPY)
635
+ continue;
636
+ if (!(last->vm_flags & VM_WIPEONFORK))
637
+ vm_write_end(last);
638
+ }
639
+ }
640
+
641
+ mmap_write_unlock(oldmm);
571642 dup_userfaultfd_complete(&uf);
572643 fail_uprobe_end:
573644 uprobe_end_dup_mmap();
....@@ -597,9 +668,9 @@
597668 #else
598669 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
599670 {
600
- down_write(&oldmm->mmap_sem);
671
+ mmap_write_lock(oldmm);
601672 RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm));
602
- up_write(&oldmm->mmap_sem);
673
+ mmap_write_unlock(oldmm);
603674 return 0;
604675 }
605676 #define mm_alloc_pgd(mm) (0)
....@@ -610,12 +681,15 @@
610681 {
611682 int i;
612683
684
+ BUILD_BUG_ON_MSG(ARRAY_SIZE(resident_page_types) != NR_MM_COUNTERS,
685
+ "Please make sure 'struct resident_page_types[]' is updated as well");
686
+
613687 for (i = 0; i < NR_MM_COUNTERS; i++) {
614688 long x = atomic_long_read(&mm->rss_stat.count[i]);
615689
616690 if (unlikely(x))
617
- printk(KERN_ALERT "BUG: Bad rss-counter state "
618
- "mm:%p idx:%d val:%ld\n", mm, i, x);
691
+ pr_alert("BUG: Bad rss-counter state mm:%p type:%s val:%ld\n",
692
+ mm, resident_page_types[i], x);
619693 }
620694
621695 if (mm_pgtables_bytes(mm))
....@@ -642,26 +716,12 @@
642716 WARN_ON_ONCE(mm == current->active_mm);
643717 mm_free_pgd(mm);
644718 destroy_context(mm);
645
- hmm_mm_destroy(mm);
646
- mmu_notifier_mm_destroy(mm);
719
+ mmu_notifier_subscriptions_destroy(mm);
647720 check_mm(mm);
648721 put_user_ns(mm->user_ns);
649722 free_mm(mm);
650723 }
651724 EXPORT_SYMBOL_GPL(__mmdrop);
652
-
653
-#ifdef CONFIG_PREEMPT_RT_BASE
654
-/*
655
- * RCU callback for delayed mm drop. Not strictly rcu, but we don't
656
- * want another facility to make this work.
657
- */
658
-void __mmdrop_delayed(struct rcu_head *rhp)
659
-{
660
- struct mm_struct *mm = container_of(rhp, struct mm_struct, delayed_drop);
661
-
662
- __mmdrop(mm);
663
-}
664
-#endif
665725
666726 static void mmdrop_async_fn(struct work_struct *work)
667727 {
....@@ -694,27 +754,17 @@
694754
695755 static inline void put_signal_struct(struct signal_struct *sig)
696756 {
697
- if (atomic_dec_and_test(&sig->sigcnt))
757
+ if (refcount_dec_and_test(&sig->sigcnt))
698758 free_signal_struct(sig);
699759 }
700
-#ifdef CONFIG_PREEMPT_RT_BASE
701
-static
702
-#endif
760
+
703761 void __put_task_struct(struct task_struct *tsk)
704762 {
705763 WARN_ON(!tsk->exit_state);
706
- WARN_ON(atomic_read(&tsk->usage));
764
+ WARN_ON(refcount_read(&tsk->usage));
707765 WARN_ON(tsk == current);
708766
709
- /*
710
- * Remove function-return probe instances associated with this
711
- * task and put them back on the free list.
712
- */
713
- kprobe_flush_task(tsk);
714
-
715
- /* Task is done with its stack. */
716
- put_task_stack(tsk);
717
-
767
+ io_uring_free(tsk);
718768 cgroup_free(tsk);
719769 task_numa_free(tsk, true);
720770 security_task_free(tsk);
....@@ -725,18 +775,7 @@
725775 if (!profile_handoff_task(tsk))
726776 free_task(tsk);
727777 }
728
-#ifndef CONFIG_PREEMPT_RT_BASE
729778 EXPORT_SYMBOL_GPL(__put_task_struct);
730
-#else
731
-void __put_task_struct_cb(struct rcu_head *rhp)
732
-{
733
- struct task_struct *tsk = container_of(rhp, struct task_struct, put_rcu);
734
-
735
- __put_task_struct(tsk);
736
-
737
-}
738
-EXPORT_SYMBOL_GPL(__put_task_struct_cb);
739
-#endif
740779
741780 void __init __weak arch_task_cache_init(void) { }
742781
....@@ -746,15 +785,16 @@
746785 static void set_max_threads(unsigned int max_threads_suggested)
747786 {
748787 u64 threads;
788
+ unsigned long nr_pages = totalram_pages();
749789
750790 /*
751791 * The number of threads shall be limited such that the thread
752792 * structures may only consume a small part of the available memory.
753793 */
754
- if (fls64(totalram_pages) + fls64(PAGE_SIZE) > 64)
794
+ if (fls64(nr_pages) + fls64(PAGE_SIZE) > 64)
755795 threads = MAX_THREADS;
756796 else
757
- threads = div64_u64((u64) totalram_pages * (u64) PAGE_SIZE,
797
+ threads = div64_u64((u64) nr_pages * (u64) PAGE_SIZE,
758798 (u64) THREAD_SIZE * 8UL);
759799
760800 if (threads > max_threads_suggested)
....@@ -768,6 +808,7 @@
768808 int arch_task_struct_size __read_mostly;
769809 #endif
770810
811
+#ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR
771812 static void task_struct_whitelist(unsigned long *offset, unsigned long *size)
772813 {
773814 /* Fetch thread_struct whitelist for the architecture. */
....@@ -782,6 +823,7 @@
782823 else
783824 *offset += offsetof(struct task_struct, thread);
784825 }
826
+#endif /* CONFIG_ARCH_TASK_STRUCT_ALLOCATOR */
785827
786828 void __init fork_init(void)
787829 {
....@@ -823,6 +865,7 @@
823865 scs_init();
824866
825867 lockdep_init_task(&init_task);
868
+ uprobes_init();
826869 }
827870
828871 int __weak arch_dup_task_struct(struct task_struct *dst,
....@@ -844,7 +887,7 @@
844887 {
845888 struct task_struct *tsk;
846889 unsigned long *stack;
847
- struct vm_struct *stack_vm_area;
890
+ struct vm_struct *stack_vm_area __maybe_unused;
848891 int err;
849892
850893 if (node == NUMA_NO_NODE)
....@@ -856,6 +899,9 @@
856899 stack = alloc_thread_stack_node(tsk, node);
857900 if (!stack)
858901 goto free_tsk;
902
+
903
+ if (memcg_charge_kernel_stack(tsk))
904
+ goto free_stack;
859905
860906 stack_vm_area = task_stack_vm_area(tsk);
861907
....@@ -871,7 +917,7 @@
871917 tsk->stack_vm_area = stack_vm_area;
872918 #endif
873919 #ifdef CONFIG_THREAD_INFO_IN_TASK
874
- atomic_set(&tsk->stack_refcount, 1);
920
+ refcount_set(&tsk->stack_refcount, 1);
875921 #endif
876922
877923 if (err)
....@@ -903,17 +949,19 @@
903949 tsk->cpus_ptr = &tsk->cpus_mask;
904950
905951 /*
906
- * One for us, one for whoever does the "release_task()" (usually
907
- * parent)
952
+ * One for the user space visible state that goes away when reaped.
953
+ * One for the scheduler.
908954 */
909
- atomic_set(&tsk->usage, 2);
955
+ refcount_set(&tsk->rcu_users, 2);
956
+ /* One for the rcu users */
957
+ refcount_set(&tsk->usage, 1);
910958 #ifdef CONFIG_BLK_DEV_IO_TRACE
911959 tsk->btrace_seq = 0;
912960 #endif
913961 tsk->splice_pipe = NULL;
914962 tsk->task_frag.page = NULL;
915963 tsk->wake_q.next = NULL;
916
- tsk->wake_q_sleeper.next = NULL;
964
+ tsk->pf_io_worker = NULL;
917965
918966 account_kernel_stack(tsk, 1);
919967
....@@ -931,6 +979,11 @@
931979 #ifdef CONFIG_MEMCG
932980 tsk->active_memcg = NULL;
933981 #endif
982
+
983
+ android_init_vendor_data(tsk, 1);
984
+ android_init_oem_data(tsk, 1);
985
+
986
+ trace_android_vh_dup_task_struct(tsk, orig);
934987 return tsk;
935988
936989 free_stack:
....@@ -980,6 +1033,13 @@
9801033 #endif
9811034 }
9821035
1036
+static void mm_init_pasid(struct mm_struct *mm)
1037
+{
1038
+#ifdef CONFIG_IOMMU_SUPPORT
1039
+ mm->pasid = INIT_PASID;
1040
+#endif
1041
+}
1042
+
9831043 static void mm_init_uprobes_state(struct mm_struct *mm)
9841044 {
9851045 #ifdef CONFIG_UPROBES
....@@ -993,24 +1053,30 @@
9931053 mm->mmap = NULL;
9941054 mm->mm_rb = RB_ROOT;
9951055 mm->vmacache_seqnum = 0;
1056
+#ifdef CONFIG_SPECULATIVE_PAGE_FAULT
1057
+ rwlock_init(&mm->mm_rb_lock);
1058
+#endif
9961059 atomic_set(&mm->mm_users, 1);
9971060 atomic_set(&mm->mm_count, 1);
998
- init_rwsem(&mm->mmap_sem);
1061
+ seqcount_init(&mm->write_protect_seq);
1062
+ mmap_init_lock(mm);
9991063 INIT_LIST_HEAD(&mm->mmlist);
10001064 mm->core_state = NULL;
10011065 mm_pgtables_bytes_init(mm);
10021066 mm->map_count = 0;
10031067 mm->locked_vm = 0;
1004
- mm->pinned_vm = 0;
1068
+ atomic_set(&mm->has_pinned, 0);
1069
+ atomic64_set(&mm->pinned_vm, 0);
10051070 memset(&mm->rss_stat, 0, sizeof(mm->rss_stat));
10061071 spin_lock_init(&mm->page_table_lock);
10071072 spin_lock_init(&mm->arg_lock);
10081073 mm_init_cpumask(mm);
10091074 mm_init_aio(mm);
10101075 mm_init_owner(mm, p);
1076
+ mm_init_pasid(mm);
10111077 RCU_INIT_POINTER(mm->exe_file, NULL);
1012
- mmu_notifier_mm_init(mm);
1013
- hmm_mm_init(mm);
1078
+ if (!mmu_notifier_subscriptions_init(mm))
1079
+ goto fail_nopgd;
10141080 init_tlb_flush_pending(mm);
10151081 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
10161082 mm->pmd_huge_pte = NULL;
....@@ -1085,8 +1151,10 @@
10851151 {
10861152 might_sleep();
10871153
1088
- if (atomic_dec_and_test(&mm->mm_users))
1154
+ if (atomic_dec_and_test(&mm->mm_users)) {
1155
+ trace_android_vh_mmput(NULL);
10891156 __mmput(mm);
1157
+ }
10901158 }
10911159 EXPORT_SYMBOL_GPL(mmput);
10921160
....@@ -1106,6 +1174,7 @@
11061174 schedule_work(&mm->async_put_work);
11071175 }
11081176 }
1177
+EXPORT_SYMBOL_GPL(mmput_async);
11091178 #endif
11101179
11111180 /**
....@@ -1210,7 +1279,7 @@
12101279 struct mm_struct *mm;
12111280 int err;
12121281
1213
- err = mutex_lock_killable(&task->signal->cred_guard_mutex);
1282
+ err = down_read_killable(&task->signal->exec_update_lock);
12141283 if (err)
12151284 return ERR_PTR(err);
12161285
....@@ -1220,7 +1289,7 @@
12201289 mmput(mm);
12211290 mm = ERR_PTR(-EACCES);
12221291 }
1223
- mutex_unlock(&task->signal->cred_guard_mutex);
1292
+ up_read(&task->signal->exec_update_lock);
12241293
12251294 return mm;
12261295 }
....@@ -1318,13 +1387,20 @@
13181387 mm_release(tsk, mm);
13191388 }
13201389
1321
-/*
1322
- * Allocate a new mm structure and copy contents from the
1323
- * mm structure of the passed in task structure.
1390
+/**
1391
+ * dup_mm() - duplicates an existing mm structure
1392
+ * @tsk: the task_struct with which the new mm will be associated.
1393
+ * @oldmm: the mm to duplicate.
1394
+ *
1395
+ * Allocates a new mm structure and duplicates the provided @oldmm structure
1396
+ * content into it.
1397
+ *
1398
+ * Return: the duplicated mm or NULL on failure.
13241399 */
1325
-static struct mm_struct *dup_mm(struct task_struct *tsk)
1400
+static struct mm_struct *dup_mm(struct task_struct *tsk,
1401
+ struct mm_struct *oldmm)
13261402 {
1327
- struct mm_struct *mm, *oldmm = current->mm;
1403
+ struct mm_struct *mm;
13281404 int err;
13291405
13301406 mm = allocate_mm();
....@@ -1392,7 +1468,7 @@
13921468 }
13931469
13941470 retval = -ENOMEM;
1395
- mm = dup_mm(tsk);
1471
+ mm = dup_mm(tsk, current->mm);
13961472 if (!mm)
13971473 goto fail_nomem;
13981474
....@@ -1442,7 +1518,7 @@
14421518 goto out;
14431519 }
14441520
1445
- newf = dup_fd(oldf, &error);
1521
+ newf = dup_fd(oldf, NR_OPEN_MAX, &error);
14461522 if (!newf)
14471523 goto out;
14481524
....@@ -1483,24 +1559,29 @@
14831559 struct sighand_struct *sig;
14841560
14851561 if (clone_flags & CLONE_SIGHAND) {
1486
- atomic_inc(&current->sighand->count);
1562
+ refcount_inc(&current->sighand->count);
14871563 return 0;
14881564 }
14891565 sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
1490
- rcu_assign_pointer(tsk->sighand, sig);
1566
+ RCU_INIT_POINTER(tsk->sighand, sig);
14911567 if (!sig)
14921568 return -ENOMEM;
14931569
1494
- atomic_set(&sig->count, 1);
1570
+ refcount_set(&sig->count, 1);
14951571 spin_lock_irq(&current->sighand->siglock);
14961572 memcpy(sig->action, current->sighand->action, sizeof(sig->action));
14971573 spin_unlock_irq(&current->sighand->siglock);
1574
+
1575
+ /* Reset all signal handler not set to SIG_IGN to SIG_DFL. */
1576
+ if (clone_flags & CLONE_CLEAR_SIGHAND)
1577
+ flush_signal_handlers(tsk, 0);
1578
+
14981579 return 0;
14991580 }
15001581
15011582 void __cleanup_sighand(struct sighand_struct *sighand)
15021583 {
1503
- if (atomic_dec_and_test(&sighand->count)) {
1584
+ if (refcount_dec_and_test(&sighand->count)) {
15041585 signalfd_cleanup(sighand);
15051586 /*
15061587 * sighand_cachep is SLAB_TYPESAFE_BY_RCU so we can free it
....@@ -1510,28 +1591,17 @@
15101591 }
15111592 }
15121593
1513
-#ifdef CONFIG_POSIX_TIMERS
15141594 /*
15151595 * Initialize POSIX timer handling for a thread group.
15161596 */
15171597 static void posix_cpu_timers_init_group(struct signal_struct *sig)
15181598 {
1599
+ struct posix_cputimers *pct = &sig->posix_cputimers;
15191600 unsigned long cpu_limit;
15201601
15211602 cpu_limit = READ_ONCE(sig->rlim[RLIMIT_CPU].rlim_cur);
1522
- if (cpu_limit != RLIM_INFINITY) {
1523
- sig->cputime_expires.prof_exp = cpu_limit * NSEC_PER_SEC;
1524
- sig->cputimer.running = true;
1525
- }
1526
-
1527
- /* The timer lists. */
1528
- INIT_LIST_HEAD(&sig->cpu_timers[0]);
1529
- INIT_LIST_HEAD(&sig->cpu_timers[1]);
1530
- INIT_LIST_HEAD(&sig->cpu_timers[2]);
1603
+ posix_cputimers_group_init(pct, cpu_limit);
15311604 }
1532
-#else
1533
-static inline void posix_cpu_timers_init_group(struct signal_struct *sig) { }
1534
-#endif
15351605
15361606 static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
15371607 {
....@@ -1547,7 +1617,7 @@
15471617
15481618 sig->nr_threads = 1;
15491619 atomic_set(&sig->live, 1);
1550
- atomic_set(&sig->sigcnt, 1);
1620
+ refcount_set(&sig->sigcnt, 1);
15511621
15521622 /* list_add(thread_node, thread_head) without INIT_LIST_HEAD() */
15531623 sig->thread_head = (struct list_head)LIST_HEAD_INIT(tsk->thread_node);
....@@ -1579,6 +1649,7 @@
15791649 sig->oom_score_adj_min = current->signal->oom_score_adj_min;
15801650
15811651 mutex_init(&sig->cred_guard_mutex);
1652
+ init_rwsem(&sig->exec_update_lock);
15821653
15831654 return 0;
15841655 }
....@@ -1633,26 +1704,6 @@
16331704 #endif
16341705 }
16351706
1636
-#ifdef CONFIG_POSIX_TIMERS
1637
-/*
1638
- * Initialize POSIX timer handling for a single task.
1639
- */
1640
-static void posix_cpu_timers_init(struct task_struct *tsk)
1641
-{
1642
-#ifdef CONFIG_PREEMPT_RT_BASE
1643
- tsk->posix_timer_list = NULL;
1644
-#endif
1645
- tsk->cputime_expires.prof_exp = 0;
1646
- tsk->cputime_expires.virt_exp = 0;
1647
- tsk->cputime_expires.sched_exp = 0;
1648
- INIT_LIST_HEAD(&tsk->cpu_timers[0]);
1649
- INIT_LIST_HEAD(&tsk->cpu_timers[1]);
1650
- INIT_LIST_HEAD(&tsk->cpu_timers[2]);
1651
-}
1652
-#else
1653
-static inline void posix_cpu_timers_init(struct task_struct *tsk) { }
1654
-#endif
1655
-
16561707 static inline void init_task_pid_links(struct task_struct *task)
16571708 {
16581709 enum pid_type type;
....@@ -1684,7 +1735,125 @@
16841735 INIT_LIST_HEAD(&p->rcu_tasks_holdout_list);
16851736 p->rcu_tasks_idle_cpu = -1;
16861737 #endif /* #ifdef CONFIG_TASKS_RCU */
1738
+#ifdef CONFIG_TASKS_TRACE_RCU
1739
+ p->trc_reader_nesting = 0;
1740
+ p->trc_reader_special.s = 0;
1741
+ INIT_LIST_HEAD(&p->trc_holdout_list);
1742
+#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */
16871743 }
1744
+
1745
+struct pid *pidfd_pid(const struct file *file)
1746
+{
1747
+ if (file->f_op == &pidfd_fops)
1748
+ return file->private_data;
1749
+
1750
+ return ERR_PTR(-EBADF);
1751
+}
1752
+
1753
+static int pidfd_release(struct inode *inode, struct file *file)
1754
+{
1755
+ struct pid *pid = file->private_data;
1756
+
1757
+ file->private_data = NULL;
1758
+ put_pid(pid);
1759
+ return 0;
1760
+}
1761
+
1762
+#ifdef CONFIG_PROC_FS
1763
+/**
1764
+ * pidfd_show_fdinfo - print information about a pidfd
1765
+ * @m: proc fdinfo file
1766
+ * @f: file referencing a pidfd
1767
+ *
1768
+ * Pid:
1769
+ * This function will print the pid that a given pidfd refers to in the
1770
+ * pid namespace of the procfs instance.
1771
+ * If the pid namespace of the process is not a descendant of the pid
1772
+ * namespace of the procfs instance 0 will be shown as its pid. This is
1773
+ * similar to calling getppid() on a process whose parent is outside of
1774
+ * its pid namespace.
1775
+ *
1776
+ * NSpid:
1777
+ * If pid namespaces are supported then this function will also print
1778
+ * the pid of a given pidfd refers to for all descendant pid namespaces
1779
+ * starting from the current pid namespace of the instance, i.e. the
1780
+ * Pid field and the first entry in the NSpid field will be identical.
1781
+ * If the pid namespace of the process is not a descendant of the pid
1782
+ * namespace of the procfs instance 0 will be shown as its first NSpid
1783
+ * entry and no others will be shown.
1784
+ * Note that this differs from the Pid and NSpid fields in
1785
+ * /proc/<pid>/status where Pid and NSpid are always shown relative to
1786
+ * the pid namespace of the procfs instance. The difference becomes
1787
+ * obvious when sending around a pidfd between pid namespaces from a
1788
+ * different branch of the tree, i.e. where no ancestoral relation is
1789
+ * present between the pid namespaces:
1790
+ * - create two new pid namespaces ns1 and ns2 in the initial pid
1791
+ * namespace (also take care to create new mount namespaces in the
1792
+ * new pid namespace and mount procfs)
1793
+ * - create a process with a pidfd in ns1
1794
+ * - send pidfd from ns1 to ns2
1795
+ * - read /proc/self/fdinfo/<pidfd> and observe that both Pid and NSpid
1796
+ * have exactly one entry, which is 0
1797
+ */
1798
+static void pidfd_show_fdinfo(struct seq_file *m, struct file *f)
1799
+{
1800
+ struct pid *pid = f->private_data;
1801
+ struct pid_namespace *ns;
1802
+ pid_t nr = -1;
1803
+
1804
+ if (likely(pid_has_task(pid, PIDTYPE_PID))) {
1805
+ ns = proc_pid_ns(file_inode(m->file)->i_sb);
1806
+ nr = pid_nr_ns(pid, ns);
1807
+ }
1808
+
1809
+ seq_put_decimal_ll(m, "Pid:\t", nr);
1810
+
1811
+#ifdef CONFIG_PID_NS
1812
+ seq_put_decimal_ll(m, "\nNSpid:\t", nr);
1813
+ if (nr > 0) {
1814
+ int i;
1815
+
1816
+ /* If nr is non-zero it means that 'pid' is valid and that
1817
+ * ns, i.e. the pid namespace associated with the procfs
1818
+ * instance, is in the pid namespace hierarchy of pid.
1819
+ * Start at one below the already printed level.
1820
+ */
1821
+ for (i = ns->level + 1; i <= pid->level; i++)
1822
+ seq_put_decimal_ll(m, "\t", pid->numbers[i].nr);
1823
+ }
1824
+#endif
1825
+ seq_putc(m, '\n');
1826
+}
1827
+#endif
1828
+
1829
+/*
1830
+ * Poll support for process exit notification.
1831
+ */
1832
+static __poll_t pidfd_poll(struct file *file, struct poll_table_struct *pts)
1833
+{
1834
+ struct pid *pid = file->private_data;
1835
+ __poll_t poll_flags = 0;
1836
+
1837
+ poll_wait(file, &pid->wait_pidfd, pts);
1838
+
1839
+ /*
1840
+ * Inform pollers only when the whole thread group exits.
1841
+ * If the thread group leader exits before all other threads in the
1842
+ * group, then poll(2) should block, similar to the wait(2) family.
1843
+ */
1844
+ if (thread_group_exited(pid))
1845
+ poll_flags = EPOLLIN | EPOLLRDNORM;
1846
+
1847
+ return poll_flags;
1848
+}
1849
+
1850
+const struct file_operations pidfd_fops = {
1851
+ .release = pidfd_release,
1852
+ .poll = pidfd_poll,
1853
+#ifdef CONFIG_PROC_FS
1854
+ .show_fdinfo = pidfd_show_fdinfo,
1855
+#endif
1856
+};
16881857
16891858 static void __delayed_free_task(struct rcu_head *rhp)
16901859 {
....@@ -1699,84 +1868,6 @@
16991868 call_rcu(&tsk->rcu, __delayed_free_task);
17001869 else
17011870 free_task(tsk);
1702
-}
1703
-
1704
-static int pidfd_release(struct inode *inode, struct file *file)
1705
-{
1706
- struct pid *pid = file->private_data;
1707
-
1708
- file->private_data = NULL;
1709
- put_pid(pid);
1710
- return 0;
1711
-}
1712
-
1713
-#ifdef CONFIG_PROC_FS
1714
-static void pidfd_show_fdinfo(struct seq_file *m, struct file *f)
1715
-{
1716
- struct pid_namespace *ns = proc_pid_ns(file_inode(m->file));
1717
- struct pid *pid = f->private_data;
1718
-
1719
- seq_put_decimal_ull(m, "Pid:\t", pid_nr_ns(pid, ns));
1720
- seq_putc(m, '\n');
1721
-}
1722
-#endif
1723
-
1724
-/*
1725
- * Poll support for process exit notification.
1726
- */
1727
-static __poll_t pidfd_poll(struct file *file, struct poll_table_struct *pts)
1728
-{
1729
- struct task_struct *task;
1730
- struct pid *pid = file->private_data;
1731
- __poll_t poll_flags = 0;
1732
-
1733
- poll_wait(file, &pid->wait_pidfd, pts);
1734
-
1735
- rcu_read_lock();
1736
- task = pid_task(pid, PIDTYPE_PID);
1737
- /*
1738
- * Inform pollers only when the whole thread group exits.
1739
- * If the thread group leader exits before all other threads in the
1740
- * group, then poll(2) should block, similar to the wait(2) family.
1741
- */
1742
- if (!task || (task->exit_state && thread_group_empty(task)))
1743
- poll_flags = EPOLLIN | EPOLLRDNORM;
1744
- rcu_read_unlock();
1745
-
1746
- return poll_flags;
1747
-}
1748
-
1749
-const struct file_operations pidfd_fops = {
1750
- .release = pidfd_release,
1751
- .poll = pidfd_poll,
1752
-#ifdef CONFIG_PROC_FS
1753
- .show_fdinfo = pidfd_show_fdinfo,
1754
-#endif
1755
-};
1756
-
1757
-/**
1758
- * pidfd_create() - Create a new pid file descriptor.
1759
- *
1760
- * @pid: struct pid that the pidfd will reference
1761
- *
1762
- * This creates a new pid file descriptor with the O_CLOEXEC flag set.
1763
- *
1764
- * Note, that this function can only be called after the fd table has
1765
- * been unshared to avoid leaking the pidfd to the new process.
1766
- *
1767
- * Return: On success, a cloexec pidfd is returned.
1768
- * On error, a negative errno number will be returned.
1769
- */
1770
-static int pidfd_create(struct pid *pid)
1771
-{
1772
- int fd;
1773
-
1774
- fd = anon_inode_getfd("[pidfd]", &pidfd_fops, get_pid(pid),
1775
- O_RDWR | O_CLOEXEC);
1776
- if (fd < 0)
1777
- put_pid(pid);
1778
-
1779
- return fd;
17801871 }
17811872
17821873 static void copy_oom_score_adj(u64 clone_flags, struct task_struct *tsk)
....@@ -1807,19 +1898,17 @@
18071898 * flags). The actual kick-off is left to the caller.
18081899 */
18091900 static __latent_entropy struct task_struct *copy_process(
1810
- unsigned long clone_flags,
1811
- unsigned long stack_start,
1812
- unsigned long stack_size,
1813
- int __user *parent_tidptr,
1814
- int __user *child_tidptr,
18151901 struct pid *pid,
18161902 int trace,
1817
- unsigned long tls,
1818
- int node)
1903
+ int node,
1904
+ struct kernel_clone_args *args)
18191905 {
18201906 int pidfd = -1, retval;
18211907 struct task_struct *p;
18221908 struct multiprocess_signals delayed;
1909
+ struct file *pidfile = NULL;
1910
+ u64 clone_flags = args->flags;
1911
+ struct nsproxy *nsp = current->nsproxy;
18231912
18241913 /*
18251914 * Don't allow sharing the root directory with processes in a different
....@@ -1862,21 +1951,26 @@
18621951 */
18631952 if (clone_flags & CLONE_THREAD) {
18641953 if ((clone_flags & (CLONE_NEWUSER | CLONE_NEWPID)) ||
1865
- (task_active_pid_ns(current) !=
1866
- current->nsproxy->pid_ns_for_children))
1954
+ (task_active_pid_ns(current) != nsp->pid_ns_for_children))
1955
+ return ERR_PTR(-EINVAL);
1956
+ }
1957
+
1958
+ /*
1959
+ * If the new process will be in a different time namespace
1960
+ * do not allow it to share VM or a thread group with the forking task.
1961
+ */
1962
+ if (clone_flags & (CLONE_THREAD | CLONE_VM)) {
1963
+ if (nsp->time_ns != nsp->time_ns_for_children)
18671964 return ERR_PTR(-EINVAL);
18681965 }
18691966
18701967 if (clone_flags & CLONE_PIDFD) {
18711968 /*
1872
- * - CLONE_PARENT_SETTID is useless for pidfds and also
1873
- * parent_tidptr is used to return pidfds.
18741969 * - CLONE_DETACHED is blocked so that we can potentially
18751970 * reuse it later for CLONE_PIDFD.
18761971 * - CLONE_THREAD is blocked until someone really needs it.
18771972 */
1878
- if (clone_flags &
1879
- (CLONE_DETACHED | CLONE_PARENT_SETTID | CLONE_THREAD))
1973
+ if (clone_flags & (CLONE_DETACHED | CLONE_THREAD))
18801974 return ERR_PTR(-EINVAL);
18811975 }
18821976
....@@ -1895,13 +1989,21 @@
18951989 recalc_sigpending();
18961990 spin_unlock_irq(&current->sighand->siglock);
18971991 retval = -ERESTARTNOINTR;
1898
- if (signal_pending(current))
1992
+ if (task_sigpending(current))
18991993 goto fork_out;
19001994
19011995 retval = -ENOMEM;
19021996 p = dup_task_struct(current, node);
19031997 if (!p)
19041998 goto fork_out;
1999
+ if (args->io_thread) {
2000
+ /*
2001
+ * Mark us an IO worker, and block any signal that isn't
2002
+ * fatal or STOP
2003
+ */
2004
+ p->flags |= PF_IO_WORKER;
2005
+ siginitsetinv(&p->blocked, sigmask(SIGKILL)|sigmask(SIGSTOP));
2006
+ }
19052007
19062008 cpufreq_task_times_init(p);
19072009
....@@ -1911,18 +2013,18 @@
19112013 * p->set_child_tid which is (ab)used as a kthread's data pointer for
19122014 * kernel threads (PF_KTHREAD).
19132015 */
1914
- p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
2016
+ p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? args->child_tid : NULL;
19152017 /*
19162018 * Clear TID on mm_release()?
19172019 */
1918
- p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr : NULL;
2020
+ p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? args->child_tid : NULL;
19192021
19202022 ftrace_graph_init_task(p);
19212023
19222024 rt_mutex_init_task(p);
19232025
2026
+ lockdep_assert_irqs_enabled();
19242027 #ifdef CONFIG_PROVE_LOCKING
1925
- DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
19262028 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
19272029 #endif
19282030 retval = -EAGAIN;
....@@ -1944,7 +2046,7 @@
19442046 * to stop root fork bombs.
19452047 */
19462048 retval = -EAGAIN;
1947
- if (nr_threads >= max_threads)
2049
+ if (data_race(nr_threads >= max_threads))
19482050 goto bad_fork_cleanup_count;
19492051
19502052 delayacct_tsk_init(p); /* Must remain after dup_task_struct() */
....@@ -1957,7 +2059,6 @@
19572059 spin_lock_init(&p->alloc_lock);
19582060
19592061 init_sigpending(&p->pending);
1960
- p->sigqueue_cache = NULL;
19612062
19622063 p->utime = p->stime = p->gtime = 0;
19632064 #ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME
....@@ -1969,6 +2070,10 @@
19692070 seqcount_init(&p->vtime.seqcount);
19702071 p->vtime.starttime = 0;
19712072 p->vtime.state = VTIME_INACTIVE;
2073
+#endif
2074
+
2075
+#ifdef CONFIG_IO_URING
2076
+ p->io_uring = NULL;
19722077 #endif
19732078
19742079 #if defined(SPLIT_RSS_COUNTING)
....@@ -1984,7 +2089,7 @@
19842089 task_io_accounting_init(&p->ioac);
19852090 acct_clear_integrals(p);
19862091
1987
- posix_cpu_timers_init(p);
2092
+ posix_cputimers_init(&p->posix_cputimers);
19882093
19892094 p->io_context = NULL;
19902095 audit_set_context(p, NULL);
....@@ -2000,30 +2105,19 @@
20002105 #ifdef CONFIG_CPUSETS
20012106 p->cpuset_mem_spread_rotor = NUMA_NO_NODE;
20022107 p->cpuset_slab_spread_rotor = NUMA_NO_NODE;
2003
- seqcount_init(&p->mems_allowed_seq);
2108
+ seqcount_spinlock_init(&p->mems_allowed_seq, &p->alloc_lock);
20042109 #endif
20052110 #ifdef CONFIG_TRACE_IRQFLAGS
2006
- p->irq_events = 0;
2007
- p->hardirqs_enabled = 0;
2008
- p->hardirq_enable_ip = 0;
2009
- p->hardirq_enable_event = 0;
2010
- p->hardirq_disable_ip = _THIS_IP_;
2011
- p->hardirq_disable_event = 0;
2012
- p->softirqs_enabled = 1;
2013
- p->softirq_enable_ip = _THIS_IP_;
2014
- p->softirq_enable_event = 0;
2015
- p->softirq_disable_ip = 0;
2016
- p->softirq_disable_event = 0;
2017
- p->hardirq_context = 0;
2018
- p->softirq_context = 0;
2111
+ memset(&p->irqtrace, 0, sizeof(p->irqtrace));
2112
+ p->irqtrace.hardirq_disable_ip = _THIS_IP_;
2113
+ p->irqtrace.softirq_enable_ip = _THIS_IP_;
2114
+ p->softirqs_enabled = 1;
2115
+ p->softirq_context = 0;
20192116 #endif
20202117
20212118 p->pagefault_disabled = 0;
20222119
20232120 #ifdef CONFIG_LOCKDEP
2024
- p->lockdep_depth = 0; /* no locks held yet */
2025
- p->curr_chain_key = 0;
2026
- p->lockdep_recursion = 0;
20272121 lockdep_init_task(p);
20282122 #endif
20292123
....@@ -2075,12 +2169,15 @@
20752169 retval = copy_io(clone_flags, p);
20762170 if (retval)
20772171 goto bad_fork_cleanup_namespaces;
2078
- retval = copy_thread_tls(clone_flags, stack_start, stack_size, p, tls);
2172
+ retval = copy_thread(clone_flags, args->stack, args->stack_size, p, args->tls);
20792173 if (retval)
20802174 goto bad_fork_cleanup_io;
20812175
2176
+ stackleak_task_init(p);
2177
+
20822178 if (pid != &init_struct_pid) {
2083
- pid = alloc_pid(p->nsproxy->pid_ns_for_children);
2179
+ pid = alloc_pid(p->nsproxy->pid_ns_for_children, args->set_tid,
2180
+ args->set_tid_size);
20842181 if (IS_ERR(pid)) {
20852182 retval = PTR_ERR(pid);
20862183 goto bad_fork_cleanup_thread;
....@@ -2093,12 +2190,22 @@
20932190 * if the fd table isn't shared).
20942191 */
20952192 if (clone_flags & CLONE_PIDFD) {
2096
- retval = pidfd_create(pid);
2193
+ retval = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
20972194 if (retval < 0)
20982195 goto bad_fork_free_pid;
20992196
21002197 pidfd = retval;
2101
- retval = put_user(pidfd, parent_tidptr);
2198
+
2199
+ pidfile = anon_inode_getfile("[pidfd]", &pidfd_fops, pid,
2200
+ O_RDWR | O_CLOEXEC);
2201
+ if (IS_ERR(pidfile)) {
2202
+ put_unused_fd(pidfd);
2203
+ retval = PTR_ERR(pidfile);
2204
+ goto bad_fork_free_pid;
2205
+ }
2206
+ get_pid(pid); /* held by pidfile now */
2207
+
2208
+ retval = put_user(pidfd, args->pidfd);
21022209 if (retval)
21032210 goto bad_fork_put_pidfd;
21042211 }
....@@ -2123,7 +2230,7 @@
21232230 #ifdef TIF_SYSCALL_EMU
21242231 clear_tsk_thread_flag(p, TIF_SYSCALL_EMU);
21252232 #endif
2126
- clear_all_latency_tracing(p);
2233
+ clear_tsk_latency_tracing(p);
21272234
21282235 /* ok, now we should be set up.. */
21292236 p->pid = pid_nr(pid);
....@@ -2142,17 +2249,28 @@
21422249 p->pdeath_signal = 0;
21432250 INIT_LIST_HEAD(&p->thread_group);
21442251 p->task_works = NULL;
2252
+ clear_posix_cputimers_work(p);
21452253
2146
- cgroup_threadgroup_change_begin(current);
21472254 /*
21482255 * Ensure that the cgroup subsystem policies allow the new process to be
2149
- * forked. It should be noted the the new process's css_set can be changed
2256
+ * forked. It should be noted that the new process's css_set can be changed
21502257 * between here and cgroup_post_fork() if an organisation operation is in
21512258 * progress.
21522259 */
2153
- retval = cgroup_can_fork(p);
2260
+ retval = cgroup_can_fork(p, args);
21542261 if (retval)
2155
- goto bad_fork_cgroup_threadgroup_change_end;
2262
+ goto bad_fork_put_pidfd;
2263
+
2264
+ /*
2265
+ * Now that the cgroups are pinned, re-clone the parent cgroup and put
2266
+ * the new task on the correct runqueue. All this *before* the task
2267
+ * becomes visible.
2268
+ *
2269
+ * This isn't part of ->can_fork() because while the re-cloning is
2270
+ * cgroup specific, it unconditionally needs to place the task on a
2271
+ * runqueue.
2272
+ */
2273
+ sched_cgroup_fork(p, args);
21562274
21572275 /*
21582276 * From this point on we must avoid any synchronous user-space
....@@ -2163,7 +2281,7 @@
21632281 */
21642282
21652283 p->start_time = ktime_get_ns();
2166
- p->real_start_time = ktime_get_boot_ns();
2284
+ p->start_boottime = ktime_get_boottime_ns();
21672285
21682286 /*
21692287 * Make it visible to the rest of the system, but dont wake it up yet.
....@@ -2182,7 +2300,7 @@
21822300 } else {
21832301 p->real_parent = current;
21842302 p->parent_exec_id = current->self_exec_id;
2185
- p->exit_signal = (clone_flags & CSIGNAL);
2303
+ p->exit_signal = args->exit_signal;
21862304 }
21872305
21882306 klp_copy_process(p);
....@@ -2208,7 +2326,6 @@
22082326 retval = -EINTR;
22092327 goto bad_fork_cancel_cgroup;
22102328 }
2211
-
22122329
22132330 init_task_pid_links(p);
22142331 if (likely(p->pid)) {
....@@ -2242,7 +2359,7 @@
22422359 } else {
22432360 current->signal->nr_threads++;
22442361 atomic_inc(&current->signal->live);
2245
- atomic_inc(&current->signal->sigcnt);
2362
+ refcount_inc(&current->signal->sigcnt);
22462363 task_join_group_stop(p);
22472364 list_add_tail_rcu(&p->thread_group,
22482365 &p->group_leader->thread_group);
....@@ -2258,9 +2375,12 @@
22582375 syscall_tracepoint_update(p);
22592376 write_unlock_irq(&tasklist_lock);
22602377
2378
+ if (pidfile)
2379
+ fd_install(pidfd, pidfile);
2380
+
22612381 proc_fork_connector(p);
2262
- cgroup_post_fork(p);
2263
- cgroup_threadgroup_change_end(current);
2382
+ sched_post_fork(p);
2383
+ cgroup_post_fork(p, args);
22642384 perf_event_fork(p);
22652385
22662386 trace_task_newtask(p, clone_flags);
....@@ -2273,12 +2393,12 @@
22732393 bad_fork_cancel_cgroup:
22742394 spin_unlock(&current->sighand->siglock);
22752395 write_unlock_irq(&tasklist_lock);
2276
- cgroup_cancel_fork(p);
2277
-bad_fork_cgroup_threadgroup_change_end:
2278
- cgroup_threadgroup_change_end(current);
2396
+ cgroup_cancel_fork(p, args);
22792397 bad_fork_put_pidfd:
2280
- if (clone_flags & CLONE_PIDFD)
2281
- ksys_close(pidfd);
2398
+ if (clone_flags & CLONE_PIDFD) {
2399
+ fput(pidfile);
2400
+ put_unused_fd(pidfd);
2401
+ }
22822402 bad_fork_free_pid:
22832403 if (pid != &init_struct_pid)
22842404 free_pid(pid);
....@@ -2342,11 +2462,14 @@
23422462 }
23432463 }
23442464
2345
-struct task_struct *fork_idle(int cpu)
2465
+struct task_struct * __init fork_idle(int cpu)
23462466 {
23472467 struct task_struct *task;
2348
- task = copy_process(CLONE_VM, 0, 0, NULL, NULL, &init_struct_pid, 0, 0,
2349
- cpu_to_node(cpu));
2468
+ struct kernel_clone_args args = {
2469
+ .flags = CLONE_VM,
2470
+ };
2471
+
2472
+ task = copy_process(&init_struct_pid, 0, cpu_to_node(cpu), &args);
23502473 if (!IS_ERR(task)) {
23512474 init_idle_pids(task);
23522475 init_idle(task, cpu);
....@@ -2355,24 +2478,63 @@
23552478 return task;
23562479 }
23572480
2481
+struct mm_struct *copy_init_mm(void)
2482
+{
2483
+ return dup_mm(NULL, &init_mm);
2484
+}
2485
+
2486
+/*
2487
+ * This is like kernel_clone(), but shaved down and tailored to just
2488
+ * creating io_uring workers. It returns a created task, or an error pointer.
2489
+ * The returned task is inactive, and the caller must fire it up through
2490
+ * wake_up_new_task(p). All signals are blocked in the created task.
2491
+ */
2492
+struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node)
2493
+{
2494
+ unsigned long flags = CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|
2495
+ CLONE_IO;
2496
+ struct kernel_clone_args args = {
2497
+ .flags = ((lower_32_bits(flags) | CLONE_VM |
2498
+ CLONE_UNTRACED) & ~CSIGNAL),
2499
+ .exit_signal = (lower_32_bits(flags) & CSIGNAL),
2500
+ .stack = (unsigned long)fn,
2501
+ .stack_size = (unsigned long)arg,
2502
+ .io_thread = 1,
2503
+ };
2504
+
2505
+ return copy_process(NULL, 0, node, &args);
2506
+}
2507
+
23582508 /*
23592509 * Ok, this is the main fork-routine.
23602510 *
23612511 * It copies the process, and if successful kick-starts
23622512 * it and waits for it to finish using the VM if required.
2513
+ *
2514
+ * args->exit_signal is expected to be checked for sanity by the caller.
23632515 */
2364
-long _do_fork(unsigned long clone_flags,
2365
- unsigned long stack_start,
2366
- unsigned long stack_size,
2367
- int __user *parent_tidptr,
2368
- int __user *child_tidptr,
2369
- unsigned long tls)
2516
+pid_t kernel_clone(struct kernel_clone_args *args)
23702517 {
2518
+ u64 clone_flags = args->flags;
23712519 struct completion vfork;
23722520 struct pid *pid;
23732521 struct task_struct *p;
23742522 int trace = 0;
2375
- long nr;
2523
+ pid_t nr;
2524
+
2525
+ /*
2526
+ * For legacy clone() calls, CLONE_PIDFD uses the parent_tid argument
2527
+ * to return the pidfd. Hence, CLONE_PIDFD and CLONE_PARENT_SETTID are
2528
+ * mutually exclusive. With clone3() CLONE_PIDFD has grown a separate
2529
+ * field in struct clone_args and it still doesn't make sense to have
2530
+ * them both point at the same memory location. Performing this check
2531
+ * here has the advantage that we don't need to have a separate helper
2532
+ * to check for legacy clone().
2533
+ */
2534
+ if ((args->flags & CLONE_PIDFD) &&
2535
+ (args->flags & CLONE_PARENT_SETTID) &&
2536
+ (args->pidfd == args->parent_tid))
2537
+ return -EINVAL;
23762538
23772539 /*
23782540 * Determine whether and which event to report to ptracer. When
....@@ -2383,7 +2545,7 @@
23832545 if (!(clone_flags & CLONE_UNTRACED)) {
23842546 if (clone_flags & CLONE_VFORK)
23852547 trace = PTRACE_EVENT_VFORK;
2386
- else if ((clone_flags & CSIGNAL) != SIGCHLD)
2548
+ else if (args->exit_signal != SIGCHLD)
23872549 trace = PTRACE_EVENT_CLONE;
23882550 else
23892551 trace = PTRACE_EVENT_FORK;
....@@ -2392,8 +2554,7 @@
23922554 trace = 0;
23932555 }
23942556
2395
- p = copy_process(clone_flags, stack_start, stack_size, parent_tidptr,
2396
- child_tidptr, NULL, trace, tls, NUMA_NO_NODE);
2557
+ p = copy_process(NULL, trace, NUMA_NO_NODE, args);
23972558 add_latent_entropy();
23982559
23992560 if (IS_ERR(p))
....@@ -2411,7 +2572,7 @@
24112572 nr = pid_vnr(pid);
24122573
24132574 if (clone_flags & CLONE_PARENT_SETTID)
2414
- put_user(nr, parent_tidptr);
2575
+ put_user(nr, args->parent_tid);
24152576
24162577 if (clone_flags & CLONE_VFORK) {
24172578 p->vfork_done = &vfork;
....@@ -2434,34 +2595,31 @@
24342595 return nr;
24352596 }
24362597
2437
-#ifndef CONFIG_HAVE_COPY_THREAD_TLS
2438
-/* For compatibility with architectures that call do_fork directly rather than
2439
- * using the syscall entry points below. */
2440
-long do_fork(unsigned long clone_flags,
2441
- unsigned long stack_start,
2442
- unsigned long stack_size,
2443
- int __user *parent_tidptr,
2444
- int __user *child_tidptr)
2445
-{
2446
- return _do_fork(clone_flags, stack_start, stack_size,
2447
- parent_tidptr, child_tidptr, 0);
2448
-}
2449
-#endif
2450
-
24512598 /*
24522599 * Create a kernel thread.
24532600 */
24542601 pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
24552602 {
2456
- return _do_fork(flags|CLONE_VM|CLONE_UNTRACED, (unsigned long)fn,
2457
- (unsigned long)arg, NULL, NULL, 0);
2603
+ struct kernel_clone_args args = {
2604
+ .flags = ((lower_32_bits(flags) | CLONE_VM |
2605
+ CLONE_UNTRACED) & ~CSIGNAL),
2606
+ .exit_signal = (lower_32_bits(flags) & CSIGNAL),
2607
+ .stack = (unsigned long)fn,
2608
+ .stack_size = (unsigned long)arg,
2609
+ };
2610
+
2611
+ return kernel_clone(&args);
24582612 }
24592613
24602614 #ifdef __ARCH_WANT_SYS_FORK
24612615 SYSCALL_DEFINE0(fork)
24622616 {
24632617 #ifdef CONFIG_MMU
2464
- return _do_fork(SIGCHLD, 0, 0, NULL, NULL, 0);
2618
+ struct kernel_clone_args args = {
2619
+ .exit_signal = SIGCHLD,
2620
+ };
2621
+
2622
+ return kernel_clone(&args);
24652623 #else
24662624 /* can not support in nommu mode */
24672625 return -EINVAL;
....@@ -2472,8 +2630,12 @@
24722630 #ifdef __ARCH_WANT_SYS_VFORK
24732631 SYSCALL_DEFINE0(vfork)
24742632 {
2475
- return _do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
2476
- 0, NULL, NULL, 0);
2633
+ struct kernel_clone_args args = {
2634
+ .flags = CLONE_VFORK | CLONE_VM,
2635
+ .exit_signal = SIGCHLD,
2636
+ };
2637
+
2638
+ return kernel_clone(&args);
24772639 }
24782640 #endif
24792641
....@@ -2501,7 +2663,175 @@
25012663 unsigned long, tls)
25022664 #endif
25032665 {
2504
- return _do_fork(clone_flags, newsp, 0, parent_tidptr, child_tidptr, tls);
2666
+ struct kernel_clone_args args = {
2667
+ .flags = (lower_32_bits(clone_flags) & ~CSIGNAL),
2668
+ .pidfd = parent_tidptr,
2669
+ .child_tid = child_tidptr,
2670
+ .parent_tid = parent_tidptr,
2671
+ .exit_signal = (lower_32_bits(clone_flags) & CSIGNAL),
2672
+ .stack = newsp,
2673
+ .tls = tls,
2674
+ };
2675
+
2676
+ return kernel_clone(&args);
2677
+}
2678
+#endif
2679
+
2680
+#ifdef __ARCH_WANT_SYS_CLONE3
2681
+
2682
+noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,
2683
+ struct clone_args __user *uargs,
2684
+ size_t usize)
2685
+{
2686
+ int err;
2687
+ struct clone_args args;
2688
+ pid_t *kset_tid = kargs->set_tid;
2689
+
2690
+ BUILD_BUG_ON(offsetofend(struct clone_args, tls) !=
2691
+ CLONE_ARGS_SIZE_VER0);
2692
+ BUILD_BUG_ON(offsetofend(struct clone_args, set_tid_size) !=
2693
+ CLONE_ARGS_SIZE_VER1);
2694
+ BUILD_BUG_ON(offsetofend(struct clone_args, cgroup) !=
2695
+ CLONE_ARGS_SIZE_VER2);
2696
+ BUILD_BUG_ON(sizeof(struct clone_args) != CLONE_ARGS_SIZE_VER2);
2697
+
2698
+ if (unlikely(usize > PAGE_SIZE))
2699
+ return -E2BIG;
2700
+ if (unlikely(usize < CLONE_ARGS_SIZE_VER0))
2701
+ return -EINVAL;
2702
+
2703
+ err = copy_struct_from_user(&args, sizeof(args), uargs, usize);
2704
+ if (err)
2705
+ return err;
2706
+
2707
+ if (unlikely(args.set_tid_size > MAX_PID_NS_LEVEL))
2708
+ return -EINVAL;
2709
+
2710
+ if (unlikely(!args.set_tid && args.set_tid_size > 0))
2711
+ return -EINVAL;
2712
+
2713
+ if (unlikely(args.set_tid && args.set_tid_size == 0))
2714
+ return -EINVAL;
2715
+
2716
+ /*
2717
+ * Verify that higher 32bits of exit_signal are unset and that
2718
+ * it is a valid signal
2719
+ */
2720
+ if (unlikely((args.exit_signal & ~((u64)CSIGNAL)) ||
2721
+ !valid_signal(args.exit_signal)))
2722
+ return -EINVAL;
2723
+
2724
+ if ((args.flags & CLONE_INTO_CGROUP) &&
2725
+ (args.cgroup > INT_MAX || usize < CLONE_ARGS_SIZE_VER2))
2726
+ return -EINVAL;
2727
+
2728
+ *kargs = (struct kernel_clone_args){
2729
+ .flags = args.flags,
2730
+ .pidfd = u64_to_user_ptr(args.pidfd),
2731
+ .child_tid = u64_to_user_ptr(args.child_tid),
2732
+ .parent_tid = u64_to_user_ptr(args.parent_tid),
2733
+ .exit_signal = args.exit_signal,
2734
+ .stack = args.stack,
2735
+ .stack_size = args.stack_size,
2736
+ .tls = args.tls,
2737
+ .set_tid_size = args.set_tid_size,
2738
+ .cgroup = args.cgroup,
2739
+ };
2740
+
2741
+ if (args.set_tid &&
2742
+ copy_from_user(kset_tid, u64_to_user_ptr(args.set_tid),
2743
+ (kargs->set_tid_size * sizeof(pid_t))))
2744
+ return -EFAULT;
2745
+
2746
+ kargs->set_tid = kset_tid;
2747
+
2748
+ return 0;
2749
+}
2750
+
2751
+/**
2752
+ * clone3_stack_valid - check and prepare stack
2753
+ * @kargs: kernel clone args
2754
+ *
2755
+ * Verify that the stack arguments userspace gave us are sane.
2756
+ * In addition, set the stack direction for userspace since it's easy for us to
2757
+ * determine.
2758
+ */
2759
+static inline bool clone3_stack_valid(struct kernel_clone_args *kargs)
2760
+{
2761
+ if (kargs->stack == 0) {
2762
+ if (kargs->stack_size > 0)
2763
+ return false;
2764
+ } else {
2765
+ if (kargs->stack_size == 0)
2766
+ return false;
2767
+
2768
+ if (!access_ok((void __user *)kargs->stack, kargs->stack_size))
2769
+ return false;
2770
+
2771
+#if !defined(CONFIG_STACK_GROWSUP) && !defined(CONFIG_IA64)
2772
+ kargs->stack += kargs->stack_size;
2773
+#endif
2774
+ }
2775
+
2776
+ return true;
2777
+}
2778
+
2779
+static bool clone3_args_valid(struct kernel_clone_args *kargs)
2780
+{
2781
+ /* Verify that no unknown flags are passed along. */
2782
+ if (kargs->flags &
2783
+ ~(CLONE_LEGACY_FLAGS | CLONE_CLEAR_SIGHAND | CLONE_INTO_CGROUP))
2784
+ return false;
2785
+
2786
+ /*
2787
+ * - make the CLONE_DETACHED bit reuseable for clone3
2788
+ * - make the CSIGNAL bits reuseable for clone3
2789
+ */
2790
+ if (kargs->flags & (CLONE_DETACHED | CSIGNAL))
2791
+ return false;
2792
+
2793
+ if ((kargs->flags & (CLONE_SIGHAND | CLONE_CLEAR_SIGHAND)) ==
2794
+ (CLONE_SIGHAND | CLONE_CLEAR_SIGHAND))
2795
+ return false;
2796
+
2797
+ if ((kargs->flags & (CLONE_THREAD | CLONE_PARENT)) &&
2798
+ kargs->exit_signal)
2799
+ return false;
2800
+
2801
+ if (!clone3_stack_valid(kargs))
2802
+ return false;
2803
+
2804
+ return true;
2805
+}
2806
+
2807
+/**
2808
+ * clone3 - create a new process with specific properties
2809
+ * @uargs: argument structure
2810
+ * @size: size of @uargs
2811
+ *
2812
+ * clone3() is the extensible successor to clone()/clone2().
2813
+ * It takes a struct as argument that is versioned by its size.
2814
+ *
2815
+ * Return: On success, a positive PID for the child process.
2816
+ * On error, a negative errno number.
2817
+ */
2818
+SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)
2819
+{
2820
+ int err;
2821
+
2822
+ struct kernel_clone_args kargs;
2823
+ pid_t set_tid[MAX_PID_NS_LEVEL];
2824
+
2825
+ kargs.set_tid = set_tid;
2826
+
2827
+ err = copy_clone_args_from_user(&kargs, uargs, size);
2828
+ if (err)
2829
+ return err;
2830
+
2831
+ if (!clone3_args_valid(&kargs))
2832
+ return -EINVAL;
2833
+
2834
+ return kernel_clone(&kargs);
25052835 }
25062836 #endif
25072837
....@@ -2596,7 +2926,8 @@
25962926 if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND|
25972927 CLONE_VM|CLONE_FILES|CLONE_SYSVSEM|
25982928 CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET|
2599
- CLONE_NEWUSER|CLONE_NEWPID|CLONE_NEWCGROUP))
2929
+ CLONE_NEWUSER|CLONE_NEWPID|CLONE_NEWCGROUP|
2930
+ CLONE_NEWTIME))
26002931 return -EINVAL;
26012932 /*
26022933 * Not implemented, but pretend it works if there is nothing
....@@ -2609,7 +2940,7 @@
26092940 return -EINVAL;
26102941 }
26112942 if (unshare_flags & (CLONE_SIGHAND | CLONE_VM)) {
2612
- if (atomic_read(&current->sighand->count) > 1)
2943
+ if (refcount_read(&current->sighand->count) > 1)
26132944 return -EINVAL;
26142945 }
26152946 if (unshare_flags & CLONE_VM) {
....@@ -2644,14 +2975,15 @@
26442975 /*
26452976 * Unshare file descriptor table if it is being shared
26462977 */
2647
-static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
2978
+int unshare_fd(unsigned long unshare_flags, unsigned int max_fds,
2979
+ struct files_struct **new_fdp)
26482980 {
26492981 struct files_struct *fd = current->files;
26502982 int error = 0;
26512983
26522984 if ((unshare_flags & CLONE_FILES) &&
26532985 (fd && atomic_read(&fd->count) > 1)) {
2654
- *new_fdp = dup_fd(fd, &error);
2986
+ *new_fdp = dup_fd(fd, max_fds, &error);
26552987 if (!*new_fdp)
26562988 return error;
26572989 }
....@@ -2662,7 +2994,7 @@
26622994 /*
26632995 * unshare allows a process to 'unshare' part of the process
26642996 * context which was originally shared using clone. copy_*
2665
- * functions used by do_fork() cannot be used here directly
2997
+ * functions used by kernel_clone() cannot be used here directly
26662998 * because they modify an inactive task_struct that is being
26672999 * constructed. Here we are modifying the current, active,
26683000 * task_struct.
....@@ -2711,7 +3043,7 @@
27113043 err = unshare_fs(unshare_flags, &new_fs);
27123044 if (err)
27133045 goto bad_unshare_out;
2714
- err = unshare_fd(unshare_flags, &new_fd);
3046
+ err = unshare_fd(unshare_flags, NR_OPEN_MAX, &new_fd);
27153047 if (err)
27163048 goto bad_unshare_cleanup_fs;
27173049 err = unshare_userns(unshare_flags, &new_cred);
....@@ -2800,7 +3132,7 @@
28003132 struct files_struct *copy = NULL;
28013133 int error;
28023134
2803
- error = unshare_fd(CLONE_FILES, &copy);
3135
+ error = unshare_fd(CLONE_FILES, NR_OPEN_MAX, &copy);
28043136 if (error || !copy) {
28053137 *displaced = NULL;
28063138 return error;
....@@ -2813,7 +3145,7 @@
28133145 }
28143146
28153147 int sysctl_max_threads(struct ctl_table *table, int write,
2816
- void __user *buffer, size_t *lenp, loff_t *ppos)
3148
+ void *buffer, size_t *lenp, loff_t *ppos)
28173149 {
28183150 struct ctl_table t;
28193151 int ret;