hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/include/linux/sched/signal.h
....@@ -8,6 +8,10 @@
88 #include <linux/sched/jobctl.h>
99 #include <linux/sched/task.h>
1010 #include <linux/cred.h>
11
+#include <linux/refcount.h>
12
+#include <linux/posix-timers.h>
13
+#include <linux/mm_types.h>
14
+#include <asm/ptrace.h>
1115 #include <linux/android_kabi.h>
1216
1317 /*
....@@ -15,10 +19,10 @@
1519 */
1620
1721 struct sighand_struct {
18
- atomic_t count;
19
- struct k_sigaction action[_NSIG];
2022 spinlock_t siglock;
23
+ refcount_t count;
2124 wait_queue_head_t signalfd_wqh;
25
+ struct k_sigaction action[_NSIG];
2226 };
2327
2428 /*
....@@ -56,18 +60,12 @@
5660 /**
5761 * struct thread_group_cputimer - thread group interval timer counts
5862 * @cputime_atomic: atomic thread group interval timers.
59
- * @running: true when there are timers running and
60
- * @cputime_atomic receives updates.
61
- * @checking_timer: true when a thread in the group is in the
62
- * process of checking for thread group timers.
6363 *
6464 * This structure contains the version of task_cputime, above, that is
6565 * used for thread group CPU timer calculations.
6666 */
6767 struct thread_group_cputimer {
6868 struct task_cputime_atomic cputime_atomic;
69
- bool running;
70
- bool checking_timer;
7169 };
7270
7371 struct multiprocess_signals {
....@@ -83,7 +81,7 @@
8381 * the locking of signal_struct.
8482 */
8583 struct signal_struct {
86
- atomic_t sigcnt;
84
+ refcount_t sigcnt;
8785 atomic_t live;
8886 int nr_threads;
8987 struct list_head thread_head;
....@@ -148,12 +146,9 @@
148146 */
149147 struct thread_group_cputimer cputimer;
150148
151
- /* Earliest-expiration cache. */
152
- struct task_cputime cputime_expires;
153
-
154
- struct list_head cpu_timers[3];
155
-
156149 #endif
150
+ /* Empty if CONFIG_POSIX_TIMERS=n */
151
+ struct posix_cputimers posix_cputimers;
157152
158153 /* PID/PID hash table linkage. */
159154 struct pid *pids[PIDTYPE_MAX];
....@@ -232,7 +227,16 @@
232227
233228 struct mutex cred_guard_mutex; /* guard against foreign influences on
234229 * credential calculations
235
- * (notably. ptrace) */
230
+ * (notably. ptrace)
231
+ * Deprecated do not use in new code.
232
+ * Use exec_update_lock instead.
233
+ */
234
+ struct rw_semaphore exec_update_lock; /* Held while task_struct is
235
+ * being updated during exec,
236
+ * and may have inconsistent
237
+ * permissions.
238
+ */
239
+
236240 ANDROID_KABI_RESERVE(1);
237241 ANDROID_KABI_RESERVE(2);
238242 ANDROID_KABI_RESERVE(3);
....@@ -275,17 +279,18 @@
275279 extern void flush_signals(struct task_struct *);
276280 extern void ignore_signals(struct task_struct *);
277281 extern void flush_signal_handlers(struct task_struct *, int force_default);
278
-extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
282
+extern int dequeue_signal(struct task_struct *task,
283
+ sigset_t *mask, kernel_siginfo_t *info);
279284
280
-static inline int kernel_dequeue_signal(siginfo_t *info)
285
+static inline int kernel_dequeue_signal(void)
281286 {
282
- struct task_struct *tsk = current;
283
- siginfo_t __info;
287
+ struct task_struct *task = current;
288
+ kernel_siginfo_t __info;
284289 int ret;
285290
286
- spin_lock_irq(&tsk->sighand->siglock);
287
- ret = dequeue_signal(tsk, &tsk->blocked, info ?: &__info);
288
- spin_unlock_irq(&tsk->sighand->siglock);
291
+ spin_lock_irq(&task->sighand->siglock);
292
+ ret = dequeue_signal(task, &task->blocked, &__info);
293
+ spin_unlock_irq(&task->sighand->siglock);
289294
290295 return ret;
291296 }
....@@ -310,16 +315,19 @@
310315 # define ___ARCH_SI_IA64(_a1, _a2, _a3)
311316 #endif
312317
313
-int force_sig_fault(int sig, int code, void __user *addr
318
+int force_sig_fault_to_task(int sig, int code, void __user *addr
314319 ___ARCH_SI_TRAPNO(int trapno)
315320 ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
316321 , struct task_struct *t);
322
+int force_sig_fault(int sig, int code, void __user *addr
323
+ ___ARCH_SI_TRAPNO(int trapno)
324
+ ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr));
317325 int send_sig_fault(int sig, int code, void __user *addr
318326 ___ARCH_SI_TRAPNO(int trapno)
319327 ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
320328 , struct task_struct *t);
321329
322
-int force_sig_mceerr(int code, void __user *, short, struct task_struct *);
330
+int force_sig_mceerr(int code, void __user *, short);
323331 int send_sig_mceerr(int code, void __user *, short, struct task_struct *);
324332
325333 int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper);
....@@ -327,18 +335,18 @@
327335
328336 int force_sig_ptrace_errno_trap(int errno, void __user *addr);
329337
330
-extern int send_sig_info(int, struct siginfo *, struct task_struct *);
331
-extern void force_sigsegv(int sig, struct task_struct *p);
332
-extern int force_sig_info(int, struct siginfo *, struct task_struct *);
333
-extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
334
-extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
335
-extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *,
338
+extern int send_sig_info(int, struct kernel_siginfo *, struct task_struct *);
339
+extern void force_sigsegv(int sig);
340
+extern int force_sig_info(struct kernel_siginfo *);
341
+extern int __kill_pgrp_info(int sig, struct kernel_siginfo *info, struct pid *pgrp);
342
+extern int kill_pid_info(int sig, struct kernel_siginfo *info, struct pid *pid);
343
+extern int kill_pid_usb_asyncio(int sig, int errno, sigval_t addr, struct pid *,
336344 const struct cred *);
337345 extern int kill_pgrp(struct pid *pid, int sig, int priv);
338346 extern int kill_pid(struct pid *pid, int sig, int priv);
339347 extern __must_check bool do_notify_parent(struct task_struct *, int);
340348 extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
341
-extern void force_sig(int, struct task_struct *);
349
+extern void force_sig(int);
342350 extern int send_sig(int, struct task_struct *, int);
343351 extern int zap_other_threads(struct task_struct *p);
344352 extern struct sigqueue *sigqueue_alloc(void);
....@@ -352,9 +360,21 @@
352360 return -ERESTARTNOINTR;
353361 }
354362
355
-static inline int signal_pending(struct task_struct *p)
363
+static inline int task_sigpending(struct task_struct *p)
356364 {
357365 return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
366
+}
367
+
368
+static inline int signal_pending(struct task_struct *p)
369
+{
370
+ /*
371
+ * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
372
+ * behavior in terms of ensuring that we break out of wait loops
373
+ * so that notify signal callbacks can be processed.
374
+ */
375
+ if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
376
+ return 1;
377
+ return task_sigpending(p);
358378 }
359379
360380 static inline int __fatal_signal_pending(struct task_struct *p)
....@@ -364,7 +384,7 @@
364384
365385 static inline int fatal_signal_pending(struct task_struct *p)
366386 {
367
- return signal_pending(p) && __fatal_signal_pending(p);
387
+ return task_sigpending(p) && __fatal_signal_pending(p);
368388 }
369389
370390 static inline int signal_pending_state(long state, struct task_struct *p)
....@@ -375,6 +395,20 @@
375395 return 0;
376396
377397 return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
398
+}
399
+
400
+/*
401
+ * This should only be used in fault handlers to decide whether we
402
+ * should stop the current fault routine to handle the signals
403
+ * instead, especially with the case where we've got interrupted with
404
+ * a VM_FAULT_RETRY.
405
+ */
406
+static inline bool fault_signal_pending(vm_fault_t fault_flags,
407
+ struct pt_regs *regs)
408
+{
409
+ return unlikely((fault_flags & VM_FAULT_RETRY) &&
410
+ (fatal_signal_pending(current) ||
411
+ (user_mode(regs) && signal_pending(current))));
378412 }
379413
380414 /*
....@@ -420,21 +454,20 @@
420454 static inline void set_restore_sigmask(void)
421455 {
422456 set_thread_flag(TIF_RESTORE_SIGMASK);
423
- WARN_ON(!test_thread_flag(TIF_SIGPENDING));
424457 }
425458
426
-static inline void clear_tsk_restore_sigmask(struct task_struct *tsk)
459
+static inline void clear_tsk_restore_sigmask(struct task_struct *task)
427460 {
428
- clear_tsk_thread_flag(tsk, TIF_RESTORE_SIGMASK);
461
+ clear_tsk_thread_flag(task, TIF_RESTORE_SIGMASK);
429462 }
430463
431464 static inline void clear_restore_sigmask(void)
432465 {
433466 clear_thread_flag(TIF_RESTORE_SIGMASK);
434467 }
435
-static inline bool test_tsk_restore_sigmask(struct task_struct *tsk)
468
+static inline bool test_tsk_restore_sigmask(struct task_struct *task)
436469 {
437
- return test_tsk_thread_flag(tsk, TIF_RESTORE_SIGMASK);
470
+ return test_tsk_thread_flag(task, TIF_RESTORE_SIGMASK);
438471 }
439472 static inline bool test_restore_sigmask(void)
440473 {
....@@ -451,11 +484,10 @@
451484 static inline void set_restore_sigmask(void)
452485 {
453486 current->restore_sigmask = true;
454
- WARN_ON(!test_thread_flag(TIF_SIGPENDING));
455487 }
456
-static inline void clear_tsk_restore_sigmask(struct task_struct *tsk)
488
+static inline void clear_tsk_restore_sigmask(struct task_struct *task)
457489 {
458
- tsk->restore_sigmask = false;
490
+ task->restore_sigmask = false;
459491 }
460492 static inline void clear_restore_sigmask(void)
461493 {
....@@ -465,9 +497,9 @@
465497 {
466498 return current->restore_sigmask;
467499 }
468
-static inline bool test_tsk_restore_sigmask(struct task_struct *tsk)
500
+static inline bool test_tsk_restore_sigmask(struct task_struct *task)
469501 {
470
- return tsk->restore_sigmask;
502
+ return task->restore_sigmask;
471503 }
472504 static inline bool test_and_clear_restore_sigmask(void)
473505 {
....@@ -484,6 +516,16 @@
484516 __set_current_blocked(&current->saved_sigmask);
485517 }
486518
519
+extern int set_user_sigmask(const sigset_t __user *umask, size_t sigsetsize);
520
+
521
+static inline void restore_saved_sigmask_unless(bool interrupted)
522
+{
523
+ if (interrupted)
524
+ WARN_ON(!signal_pending(current));
525
+ else
526
+ restore_saved_sigmask();
527
+}
528
+
487529 static inline sigset_t *sigmask_to_save(void)
488530 {
489531 sigset_t *res = &current->blocked;
....@@ -498,9 +540,19 @@
498540 }
499541
500542 /* These can be the second arg to send_sig_info/send_group_sig_info. */
501
-#define SEND_SIG_NOINFO ((struct siginfo *) 0)
502
-#define SEND_SIG_PRIV ((struct siginfo *) 1)
503
-#define SEND_SIG_FORCED ((struct siginfo *) 2)
543
+#define SEND_SIG_NOINFO ((struct kernel_siginfo *) 0)
544
+#define SEND_SIG_PRIV ((struct kernel_siginfo *) 1)
545
+
546
+static inline int __on_sig_stack(unsigned long sp)
547
+{
548
+#ifdef CONFIG_STACK_GROWSUP
549
+ return sp >= current->sas_ss_sp &&
550
+ sp - current->sas_ss_sp < current->sas_ss_size;
551
+#else
552
+ return sp > current->sas_ss_sp &&
553
+ sp - current->sas_ss_sp <= current->sas_ss_size;
554
+#endif
555
+}
504556
505557 /*
506558 * True if we are on the alternate signal stack.
....@@ -519,13 +571,7 @@
519571 if (current->sas_ss_flags & SS_AUTODISARM)
520572 return 0;
521573
522
-#ifdef CONFIG_STACK_GROWSUP
523
- return sp >= current->sas_ss_sp &&
524
- sp - current->sas_ss_sp < current->sas_ss_size;
525
-#else
526
- return sp > current->sas_ss_sp &&
527
- sp - current->sas_ss_sp <= current->sas_ss_size;
528
-#endif
574
+ return __on_sig_stack(sp);
529575 }
530576
531577 static inline int sas_ss_flags(unsigned long sp)
....@@ -622,25 +668,14 @@
622668 return task->signal->pids[PIDTYPE_SID];
623669 }
624670
625
-static inline int get_nr_threads(struct task_struct *tsk)
671
+static inline int get_nr_threads(struct task_struct *task)
626672 {
627
- return tsk->signal->nr_threads;
673
+ return task->signal->nr_threads;
628674 }
629675
630676 static inline bool thread_group_leader(struct task_struct *p)
631677 {
632678 return p->exit_signal >= 0;
633
-}
634
-
635
-/* Do to the insanities of de_thread it is possible for a process
636
- * to have the pid of the thread group leader without actually being
637
- * the thread group leader. For iteration through the pids in proc
638
- * all we care about is that we have a task with the appropriate
639
- * pid, we don't actually care if we have the right task.
640
- */
641
-static inline bool has_group_leader_pid(struct task_struct *p)
642
-{
643
- return task_pid(p) == task_tgid(p);
644679 }
645680
646681 static inline
....@@ -663,35 +698,37 @@
663698 #define delay_group_leader(p) \
664699 (thread_group_leader(p) && !thread_group_empty(p))
665700
666
-extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
701
+extern bool thread_group_exited(struct pid *pid);
702
+
703
+extern struct sighand_struct *__lock_task_sighand(struct task_struct *task,
667704 unsigned long *flags);
668705
669
-static inline struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
706
+static inline struct sighand_struct *lock_task_sighand(struct task_struct *task,
670707 unsigned long *flags)
671708 {
672709 struct sighand_struct *ret;
673710
674
- ret = __lock_task_sighand(tsk, flags);
675
- (void)__cond_lock(&tsk->sighand->siglock, ret);
711
+ ret = __lock_task_sighand(task, flags);
712
+ (void)__cond_lock(&task->sighand->siglock, ret);
676713 return ret;
677714 }
678715
679
-static inline void unlock_task_sighand(struct task_struct *tsk,
716
+static inline void unlock_task_sighand(struct task_struct *task,
680717 unsigned long *flags)
681718 {
682
- spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
719
+ spin_unlock_irqrestore(&task->sighand->siglock, *flags);
683720 }
684721
685
-static inline unsigned long task_rlimit(const struct task_struct *tsk,
722
+static inline unsigned long task_rlimit(const struct task_struct *task,
686723 unsigned int limit)
687724 {
688
- return READ_ONCE(tsk->signal->rlim[limit].rlim_cur);
725
+ return READ_ONCE(task->signal->rlim[limit].rlim_cur);
689726 }
690727
691
-static inline unsigned long task_rlimit_max(const struct task_struct *tsk,
728
+static inline unsigned long task_rlimit_max(const struct task_struct *task,
692729 unsigned int limit)
693730 {
694
- return READ_ONCE(tsk->signal->rlim[limit].rlim_max);
731
+ return READ_ONCE(task->signal->rlim[limit].rlim_max);
695732 }
696733
697734 static inline unsigned long rlimit(unsigned int limit)