.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/kernel/signal.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
19 | 20 | #include <linux/sched/task.h> |
---|
20 | 21 | #include <linux/sched/task_stack.h> |
---|
21 | 22 | #include <linux/sched/cputime.h> |
---|
| 23 | +#include <linux/sched/rt.h> |
---|
22 | 24 | #include <linux/file.h> |
---|
23 | 25 | #include <linux/fs.h> |
---|
24 | 26 | #include <linux/proc_fs.h> |
---|
.. | .. |
---|
44 | 46 | #include <linux/posix-timers.h> |
---|
45 | 47 | #include <linux/livepatch.h> |
---|
46 | 48 | #include <linux/cgroup.h> |
---|
| 49 | +#include <linux/audit.h> |
---|
| 50 | +#include <linux/oom.h> |
---|
47 | 51 | |
---|
48 | 52 | #define CREATE_TRACE_POINTS |
---|
49 | 53 | #include <trace/events/signal.h> |
---|
.. | .. |
---|
53 | 57 | #include <asm/unistd.h> |
---|
54 | 58 | #include <asm/siginfo.h> |
---|
55 | 59 | #include <asm/cacheflush.h> |
---|
56 | | -#include "audit.h" /* audit_signal_info() */ |
---|
57 | 60 | |
---|
| 61 | +#undef CREATE_TRACE_POINTS |
---|
| 62 | +#include <trace/hooks/signal.h> |
---|
58 | 63 | /* |
---|
59 | 64 | * SLAB caches for signal bits. |
---|
60 | 65 | */ |
---|
.. | .. |
---|
185 | 190 | clear_thread_flag(TIF_SIGPENDING); |
---|
186 | 191 | |
---|
187 | 192 | } |
---|
| 193 | +EXPORT_SYMBOL(recalc_sigpending); |
---|
188 | 194 | |
---|
189 | 195 | void calculate_sigpending(void) |
---|
190 | 196 | { |
---|
.. | .. |
---|
352 | 358 | * @task has %JOBCTL_STOP_PENDING set and is participating in a group stop. |
---|
353 | 359 | * Group stop states are cleared and the group stop count is consumed if |
---|
354 | 360 | * %JOBCTL_STOP_CONSUME was set. If the consumption completes the group |
---|
355 | | - * stop, the appropriate %SIGNAL_* flags are set. |
---|
| 361 | + * stop, the appropriate `SIGNAL_*` flags are set. |
---|
356 | 362 | * |
---|
357 | 363 | * CONTEXT: |
---|
358 | 364 | * Must be called with @task->sighand->siglock held. |
---|
.. | .. |
---|
402 | 408 | task_set_jobctl_pending(task, mask | JOBCTL_STOP_PENDING); |
---|
403 | 409 | } |
---|
404 | 410 | |
---|
| 411 | +static inline struct sigqueue *get_task_cache(struct task_struct *t) |
---|
| 412 | +{ |
---|
| 413 | + struct sigqueue *q = t->sigqueue_cache; |
---|
| 414 | + |
---|
| 415 | + if (cmpxchg(&t->sigqueue_cache, q, NULL) != q) |
---|
| 416 | + return NULL; |
---|
| 417 | + return q; |
---|
| 418 | +} |
---|
| 419 | + |
---|
| 420 | +static inline int put_task_cache(struct task_struct *t, struct sigqueue *q) |
---|
| 421 | +{ |
---|
| 422 | + if (cmpxchg(&t->sigqueue_cache, NULL, q) == NULL) |
---|
| 423 | + return 0; |
---|
| 424 | + return 1; |
---|
| 425 | +} |
---|
| 426 | + |
---|
405 | 427 | /* |
---|
406 | 428 | * allocate a new signal queue record |
---|
407 | 429 | * - this may be called without locks if and only if t == current, otherwise an |
---|
408 | 430 | * appropriate lock must be held to stop the target task from exiting |
---|
409 | 431 | */ |
---|
410 | 432 | static struct sigqueue * |
---|
411 | | -__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit) |
---|
| 433 | +__sigqueue_do_alloc(int sig, struct task_struct *t, gfp_t flags, |
---|
| 434 | + int override_rlimit, int fromslab) |
---|
412 | 435 | { |
---|
413 | 436 | struct sigqueue *q = NULL; |
---|
414 | 437 | struct user_struct *user; |
---|
.. | .. |
---|
430 | 453 | rcu_read_unlock(); |
---|
431 | 454 | |
---|
432 | 455 | if (override_rlimit || likely(sigpending <= task_rlimit(t, RLIMIT_SIGPENDING))) { |
---|
433 | | - q = kmem_cache_alloc(sigqueue_cachep, flags); |
---|
| 456 | + if (!fromslab) |
---|
| 457 | + q = get_task_cache(t); |
---|
| 458 | + if (!q) |
---|
| 459 | + q = kmem_cache_alloc(sigqueue_cachep, flags); |
---|
434 | 460 | } else { |
---|
435 | 461 | print_dropped_signal(sig); |
---|
436 | 462 | } |
---|
.. | .. |
---|
447 | 473 | return q; |
---|
448 | 474 | } |
---|
449 | 475 | |
---|
| 476 | +static struct sigqueue * |
---|
| 477 | +__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, |
---|
| 478 | + int override_rlimit) |
---|
| 479 | +{ |
---|
| 480 | + return __sigqueue_do_alloc(sig, t, flags, override_rlimit, 0); |
---|
| 481 | +} |
---|
| 482 | + |
---|
450 | 483 | static void __sigqueue_free(struct sigqueue *q) |
---|
451 | 484 | { |
---|
452 | 485 | if (q->flags & SIGQUEUE_PREALLOC) |
---|
.. | .. |
---|
454 | 487 | if (atomic_dec_and_test(&q->user->sigpending)) |
---|
455 | 488 | free_uid(q->user); |
---|
456 | 489 | kmem_cache_free(sigqueue_cachep, q); |
---|
| 490 | +} |
---|
| 491 | + |
---|
| 492 | +static void sigqueue_free_current(struct sigqueue *q) |
---|
| 493 | +{ |
---|
| 494 | + struct user_struct *up; |
---|
| 495 | + |
---|
| 496 | + if (q->flags & SIGQUEUE_PREALLOC) |
---|
| 497 | + return; |
---|
| 498 | + |
---|
| 499 | + up = q->user; |
---|
| 500 | + if (rt_prio(current->normal_prio) && !put_task_cache(current, q)) { |
---|
| 501 | + if (atomic_dec_and_test(&up->sigpending)) |
---|
| 502 | + free_uid(up); |
---|
| 503 | + } else |
---|
| 504 | + __sigqueue_free(q); |
---|
457 | 505 | } |
---|
458 | 506 | |
---|
459 | 507 | void flush_sigqueue(struct sigpending *queue) |
---|
.. | .. |
---|
469 | 517 | } |
---|
470 | 518 | |
---|
471 | 519 | /* |
---|
| 520 | + * Called from __exit_signal. Flush tsk->pending and |
---|
| 521 | + * tsk->sigqueue_cache |
---|
| 522 | + */ |
---|
| 523 | +void flush_task_sigqueue(struct task_struct *tsk) |
---|
| 524 | +{ |
---|
| 525 | + struct sigqueue *q; |
---|
| 526 | + |
---|
| 527 | + flush_sigqueue(&tsk->pending); |
---|
| 528 | + |
---|
| 529 | + q = get_task_cache(tsk); |
---|
| 530 | + if (q) |
---|
| 531 | + kmem_cache_free(sigqueue_cachep, q); |
---|
| 532 | +} |
---|
| 533 | + |
---|
| 534 | +/* |
---|
472 | 535 | * Flush all pending signals for this kthread. |
---|
473 | 536 | */ |
---|
474 | 537 | void flush_signals(struct task_struct *t) |
---|
.. | .. |
---|
481 | 544 | flush_sigqueue(&t->signal->shared_pending); |
---|
482 | 545 | spin_unlock_irqrestore(&t->sighand->siglock, flags); |
---|
483 | 546 | } |
---|
| 547 | +EXPORT_SYMBOL(flush_signals); |
---|
484 | 548 | |
---|
485 | 549 | #ifdef CONFIG_POSIX_TIMERS |
---|
486 | 550 | static void __flush_itimer_signals(struct sigpending *pending) |
---|
.. | .. |
---|
562 | 626 | return !tsk->ptrace; |
---|
563 | 627 | } |
---|
564 | 628 | |
---|
565 | | -static void collect_signal(int sig, struct sigpending *list, siginfo_t *info, |
---|
| 629 | +static void collect_signal(int sig, struct sigpending *list, kernel_siginfo_t *info, |
---|
566 | 630 | bool *resched_timer) |
---|
567 | 631 | { |
---|
568 | 632 | struct sigqueue *q, *first = NULL; |
---|
.. | .. |
---|
591 | 655 | (info->si_code == SI_TIMER) && |
---|
592 | 656 | (info->si_sys_private); |
---|
593 | 657 | |
---|
594 | | - __sigqueue_free(first); |
---|
| 658 | + sigqueue_free_current(first); |
---|
595 | 659 | } else { |
---|
596 | 660 | /* |
---|
597 | 661 | * Ok, it wasn't in the queue. This must be |
---|
.. | .. |
---|
608 | 672 | } |
---|
609 | 673 | |
---|
610 | 674 | static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, |
---|
611 | | - siginfo_t *info, bool *resched_timer) |
---|
| 675 | + kernel_siginfo_t *info, bool *resched_timer) |
---|
612 | 676 | { |
---|
613 | 677 | int sig = next_signal(pending, mask); |
---|
614 | 678 | |
---|
.. | .. |
---|
623 | 687 | * |
---|
624 | 688 | * All callers have to hold the siglock. |
---|
625 | 689 | */ |
---|
626 | | -int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) |
---|
| 690 | +int dequeue_signal(struct task_struct *tsk, sigset_t *mask, kernel_siginfo_t *info) |
---|
627 | 691 | { |
---|
628 | 692 | bool resched_timer = false; |
---|
629 | 693 | int signr; |
---|
| 694 | + |
---|
| 695 | + WARN_ON_ONCE(tsk != current); |
---|
630 | 696 | |
---|
631 | 697 | /* We only dequeue private signals from ourselves, we don't let |
---|
632 | 698 | * signalfd steal them |
---|
.. | .. |
---|
699 | 765 | #endif |
---|
700 | 766 | return signr; |
---|
701 | 767 | } |
---|
| 768 | +EXPORT_SYMBOL_GPL(dequeue_signal); |
---|
702 | 769 | |
---|
703 | | -static int dequeue_synchronous_signal(siginfo_t *info) |
---|
| 770 | +static int dequeue_synchronous_signal(kernel_siginfo_t *info) |
---|
704 | 771 | { |
---|
705 | 772 | struct task_struct *tsk = current; |
---|
706 | 773 | struct sigpending *pending = &tsk->pending; |
---|
.. | .. |
---|
716 | 783 | * Return the first synchronous signal in the queue. |
---|
717 | 784 | */ |
---|
718 | 785 | list_for_each_entry(q, &pending->list, list) { |
---|
719 | | - /* Synchronous signals have a postive si_code */ |
---|
| 786 | + /* Synchronous signals have a positive si_code */ |
---|
720 | 787 | if ((q->info.si_code > SI_USER) && |
---|
721 | 788 | (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) { |
---|
722 | 789 | sync = q; |
---|
.. | .. |
---|
791 | 858 | } |
---|
792 | 859 | } |
---|
793 | 860 | |
---|
794 | | -static inline int is_si_special(const struct siginfo *info) |
---|
| 861 | +static inline int is_si_special(const struct kernel_siginfo *info) |
---|
795 | 862 | { |
---|
796 | | - return info <= SEND_SIG_FORCED; |
---|
| 863 | + return info <= SEND_SIG_PRIV; |
---|
797 | 864 | } |
---|
798 | 865 | |
---|
799 | | -static inline bool si_fromuser(const struct siginfo *info) |
---|
| 866 | +static inline bool si_fromuser(const struct kernel_siginfo *info) |
---|
800 | 867 | { |
---|
801 | 868 | return info == SEND_SIG_NOINFO || |
---|
802 | 869 | (!is_si_special(info) && SI_FROMUSER(info)); |
---|
.. | .. |
---|
821 | 888 | * Bad permissions for sending the signal |
---|
822 | 889 | * - the caller must hold the RCU read lock |
---|
823 | 890 | */ |
---|
824 | | -static int check_kill_permission(int sig, struct siginfo *info, |
---|
| 891 | +static int check_kill_permission(int sig, struct kernel_siginfo *info, |
---|
825 | 892 | struct task_struct *t) |
---|
826 | 893 | { |
---|
827 | 894 | struct pid *sid; |
---|
.. | .. |
---|
848 | 915 | */ |
---|
849 | 916 | if (!sid || sid == task_session(current)) |
---|
850 | 917 | break; |
---|
| 918 | + fallthrough; |
---|
851 | 919 | default: |
---|
852 | 920 | return -EPERM; |
---|
853 | 921 | } |
---|
.. | .. |
---|
946 | 1014 | /* |
---|
947 | 1015 | * The first thread which returns from do_signal_stop() |
---|
948 | 1016 | * will take ->siglock, notice SIGNAL_CLD_MASK, and |
---|
949 | | - * notify its parent. See get_signal_to_deliver(). |
---|
| 1017 | + * notify its parent. See get_signal(). |
---|
950 | 1018 | */ |
---|
951 | 1019 | signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED); |
---|
952 | 1020 | signal->group_stop_count = 0; |
---|
.. | .. |
---|
979 | 1047 | if (task_is_stopped_or_traced(p)) |
---|
980 | 1048 | return false; |
---|
981 | 1049 | |
---|
982 | | - return task_curr(p) || !signal_pending(p); |
---|
| 1050 | + return task_curr(p) || !task_sigpending(p); |
---|
983 | 1051 | } |
---|
984 | 1052 | |
---|
985 | 1053 | static void complete_signal(int sig, struct task_struct *p, enum pid_type type) |
---|
.. | .. |
---|
1063 | 1131 | return (sig < SIGRTMIN) && sigismember(&signals->signal, sig); |
---|
1064 | 1132 | } |
---|
1065 | 1133 | |
---|
1066 | | -#ifdef CONFIG_USER_NS |
---|
1067 | | -static inline void userns_fixup_signal_uid(struct siginfo *info, struct task_struct *t) |
---|
1068 | | -{ |
---|
1069 | | - if (current_user_ns() == task_cred_xxx(t, user_ns)) |
---|
1070 | | - return; |
---|
1071 | | - |
---|
1072 | | - if (SI_FROMKERNEL(info)) |
---|
1073 | | - return; |
---|
1074 | | - |
---|
1075 | | - rcu_read_lock(); |
---|
1076 | | - info->si_uid = from_kuid_munged(task_cred_xxx(t, user_ns), |
---|
1077 | | - make_kuid(current_user_ns(), info->si_uid)); |
---|
1078 | | - rcu_read_unlock(); |
---|
1079 | | -} |
---|
1080 | | -#else |
---|
1081 | | -static inline void userns_fixup_signal_uid(struct siginfo *info, struct task_struct *t) |
---|
1082 | | -{ |
---|
1083 | | - return; |
---|
1084 | | -} |
---|
1085 | | -#endif |
---|
1086 | | - |
---|
1087 | | -static int __send_signal(int sig, struct siginfo *info, struct task_struct *t, |
---|
1088 | | - enum pid_type type, int from_ancestor_ns) |
---|
| 1134 | +static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t, |
---|
| 1135 | + enum pid_type type, bool force) |
---|
1089 | 1136 | { |
---|
1090 | 1137 | struct sigpending *pending; |
---|
1091 | 1138 | struct sigqueue *q; |
---|
.. | .. |
---|
1095 | 1142 | assert_spin_locked(&t->sighand->siglock); |
---|
1096 | 1143 | |
---|
1097 | 1144 | result = TRACE_SIGNAL_IGNORED; |
---|
1098 | | - if (!prepare_signal(sig, t, |
---|
1099 | | - from_ancestor_ns || (info == SEND_SIG_PRIV) || (info == SEND_SIG_FORCED))) |
---|
| 1145 | + if (!prepare_signal(sig, t, force)) |
---|
1100 | 1146 | goto ret; |
---|
1101 | 1147 | |
---|
1102 | 1148 | pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; |
---|
.. | .. |
---|
1111 | 1157 | |
---|
1112 | 1158 | result = TRACE_SIGNAL_DELIVERED; |
---|
1113 | 1159 | /* |
---|
1114 | | - * fast-pathed signals for kernel-internal things like SIGSTOP |
---|
1115 | | - * or SIGKILL. |
---|
| 1160 | + * Skip useless siginfo allocation for SIGKILL and kernel threads. |
---|
1116 | 1161 | */ |
---|
1117 | | - if (info == SEND_SIG_FORCED) |
---|
| 1162 | + if ((sig == SIGKILL) || (t->flags & PF_KTHREAD)) |
---|
1118 | 1163 | goto out_set; |
---|
1119 | 1164 | |
---|
1120 | 1165 | /* |
---|
.. | .. |
---|
1142 | 1187 | q->info.si_code = SI_USER; |
---|
1143 | 1188 | q->info.si_pid = task_tgid_nr_ns(current, |
---|
1144 | 1189 | task_active_pid_ns(t)); |
---|
1145 | | - q->info.si_uid = from_kuid_munged(current_user_ns(), current_uid()); |
---|
| 1190 | + rcu_read_lock(); |
---|
| 1191 | + q->info.si_uid = |
---|
| 1192 | + from_kuid_munged(task_cred_xxx(t, user_ns), |
---|
| 1193 | + current_uid()); |
---|
| 1194 | + rcu_read_unlock(); |
---|
1146 | 1195 | break; |
---|
1147 | 1196 | case (unsigned long) SEND_SIG_PRIV: |
---|
1148 | 1197 | clear_siginfo(&q->info); |
---|
.. | .. |
---|
1154 | 1203 | break; |
---|
1155 | 1204 | default: |
---|
1156 | 1205 | copy_siginfo(&q->info, info); |
---|
1157 | | - if (from_ancestor_ns) |
---|
1158 | | - q->info.si_pid = 0; |
---|
1159 | 1206 | break; |
---|
1160 | 1207 | } |
---|
1161 | | - |
---|
1162 | | - userns_fixup_signal_uid(&q->info, t); |
---|
1163 | | - |
---|
1164 | | - } else if (!is_si_special(info)) { |
---|
1165 | | - if (sig >= SIGRTMIN && info->si_code != SI_USER) { |
---|
1166 | | - /* |
---|
1167 | | - * Queue overflow, abort. We may abort if the |
---|
1168 | | - * signal was rt and sent by user using something |
---|
1169 | | - * other than kill(). |
---|
1170 | | - */ |
---|
1171 | | - result = TRACE_SIGNAL_OVERFLOW_FAIL; |
---|
1172 | | - ret = -EAGAIN; |
---|
1173 | | - goto ret; |
---|
1174 | | - } else { |
---|
1175 | | - /* |
---|
1176 | | - * This is a silent loss of information. We still |
---|
1177 | | - * send the signal, but the *info bits are lost. |
---|
1178 | | - */ |
---|
1179 | | - result = TRACE_SIGNAL_LOSE_INFO; |
---|
1180 | | - } |
---|
| 1208 | + } else if (!is_si_special(info) && |
---|
| 1209 | + sig >= SIGRTMIN && info->si_code != SI_USER) { |
---|
| 1210 | + /* |
---|
| 1211 | + * Queue overflow, abort. We may abort if the |
---|
| 1212 | + * signal was rt and sent by user using something |
---|
| 1213 | + * other than kill(). |
---|
| 1214 | + */ |
---|
| 1215 | + result = TRACE_SIGNAL_OVERFLOW_FAIL; |
---|
| 1216 | + ret = -EAGAIN; |
---|
| 1217 | + goto ret; |
---|
| 1218 | + } else { |
---|
| 1219 | + /* |
---|
| 1220 | + * This is a silent loss of information. We still |
---|
| 1221 | + * send the signal, but the *info bits are lost. |
---|
| 1222 | + */ |
---|
| 1223 | + result = TRACE_SIGNAL_LOSE_INFO; |
---|
1181 | 1224 | } |
---|
1182 | 1225 | |
---|
1183 | 1226 | out_set: |
---|
.. | .. |
---|
1204 | 1247 | return ret; |
---|
1205 | 1248 | } |
---|
1206 | 1249 | |
---|
1207 | | -static int send_signal(int sig, struct siginfo *info, struct task_struct *t, |
---|
| 1250 | +static inline bool has_si_pid_and_uid(struct kernel_siginfo *info) |
---|
| 1251 | +{ |
---|
| 1252 | + bool ret = false; |
---|
| 1253 | + switch (siginfo_layout(info->si_signo, info->si_code)) { |
---|
| 1254 | + case SIL_KILL: |
---|
| 1255 | + case SIL_CHLD: |
---|
| 1256 | + case SIL_RT: |
---|
| 1257 | + ret = true; |
---|
| 1258 | + break; |
---|
| 1259 | + case SIL_TIMER: |
---|
| 1260 | + case SIL_POLL: |
---|
| 1261 | + case SIL_FAULT: |
---|
| 1262 | + case SIL_FAULT_MCEERR: |
---|
| 1263 | + case SIL_FAULT_BNDERR: |
---|
| 1264 | + case SIL_FAULT_PKUERR: |
---|
| 1265 | + case SIL_SYS: |
---|
| 1266 | + ret = false; |
---|
| 1267 | + break; |
---|
| 1268 | + } |
---|
| 1269 | + return ret; |
---|
| 1270 | +} |
---|
| 1271 | + |
---|
| 1272 | +static int send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t, |
---|
1208 | 1273 | enum pid_type type) |
---|
1209 | 1274 | { |
---|
1210 | | - int from_ancestor_ns = 0; |
---|
| 1275 | + /* Should SIGKILL or SIGSTOP be received by a pid namespace init? */ |
---|
| 1276 | + bool force = false; |
---|
1211 | 1277 | |
---|
1212 | | -#ifdef CONFIG_PID_NS |
---|
1213 | | - from_ancestor_ns = si_fromuser(info) && |
---|
1214 | | - !task_pid_nr_ns(current, task_active_pid_ns(t)); |
---|
1215 | | -#endif |
---|
| 1278 | + if (info == SEND_SIG_NOINFO) { |
---|
| 1279 | + /* Force if sent from an ancestor pid namespace */ |
---|
| 1280 | + force = !task_pid_nr_ns(current, task_active_pid_ns(t)); |
---|
| 1281 | + } else if (info == SEND_SIG_PRIV) { |
---|
| 1282 | + /* Don't ignore kernel generated signals */ |
---|
| 1283 | + force = true; |
---|
| 1284 | + } else if (has_si_pid_and_uid(info)) { |
---|
| 1285 | + /* SIGKILL and SIGSTOP is special or has ids */ |
---|
| 1286 | + struct user_namespace *t_user_ns; |
---|
1216 | 1287 | |
---|
1217 | | - return __send_signal(sig, info, t, type, from_ancestor_ns); |
---|
| 1288 | + rcu_read_lock(); |
---|
| 1289 | + t_user_ns = task_cred_xxx(t, user_ns); |
---|
| 1290 | + if (current_user_ns() != t_user_ns) { |
---|
| 1291 | + kuid_t uid = make_kuid(current_user_ns(), info->si_uid); |
---|
| 1292 | + info->si_uid = from_kuid_munged(t_user_ns, uid); |
---|
| 1293 | + } |
---|
| 1294 | + rcu_read_unlock(); |
---|
| 1295 | + |
---|
| 1296 | + /* A kernel generated signal? */ |
---|
| 1297 | + force = (info->si_code == SI_KERNEL); |
---|
| 1298 | + |
---|
| 1299 | + /* From an ancestor pid namespace? */ |
---|
| 1300 | + if (!task_pid_nr_ns(current, task_active_pid_ns(t))) { |
---|
| 1301 | + info->si_pid = 0; |
---|
| 1302 | + force = true; |
---|
| 1303 | + } |
---|
| 1304 | + } |
---|
| 1305 | + return __send_signal(sig, info, t, type, force); |
---|
1218 | 1306 | } |
---|
1219 | 1307 | |
---|
1220 | 1308 | static void print_fatal_signal(int signr) |
---|
.. | .. |
---|
1251 | 1339 | __setup("print-fatal-signals=", setup_print_fatal_signals); |
---|
1252 | 1340 | |
---|
1253 | 1341 | int |
---|
1254 | | -__group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
---|
| 1342 | +__group_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p) |
---|
1255 | 1343 | { |
---|
1256 | 1344 | return send_signal(sig, info, p, PIDTYPE_TGID); |
---|
1257 | 1345 | } |
---|
1258 | 1346 | |
---|
1259 | | -static int |
---|
1260 | | -specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t) |
---|
1261 | | -{ |
---|
1262 | | - return send_signal(sig, info, t, PIDTYPE_PID); |
---|
1263 | | -} |
---|
1264 | | - |
---|
1265 | | -int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p, |
---|
| 1347 | +int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p, |
---|
1266 | 1348 | enum pid_type type) |
---|
1267 | 1349 | { |
---|
1268 | 1350 | unsigned long flags; |
---|
1269 | 1351 | int ret = -ESRCH; |
---|
1270 | | - |
---|
| 1352 | + trace_android_vh_do_send_sig_info(sig, current, p); |
---|
1271 | 1353 | if (lock_task_sighand(p, &flags)) { |
---|
1272 | 1354 | ret = send_signal(sig, info, p, type); |
---|
1273 | 1355 | unlock_task_sighand(p, &flags); |
---|
.. | .. |
---|
1287 | 1369 | * We don't want to have recursive SIGSEGV's etc, for example, |
---|
1288 | 1370 | * that is why we also clear SIGNAL_UNKILLABLE. |
---|
1289 | 1371 | */ |
---|
1290 | | -int |
---|
1291 | | -force_sig_info(int sig, struct siginfo *info, struct task_struct *t) |
---|
| 1372 | +static int |
---|
| 1373 | +force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t) |
---|
1292 | 1374 | { |
---|
1293 | 1375 | unsigned long int flags; |
---|
1294 | 1376 | int ret, blocked, ignored; |
---|
1295 | 1377 | struct k_sigaction *action; |
---|
| 1378 | + int sig = info->si_signo; |
---|
1296 | 1379 | |
---|
| 1380 | + /* |
---|
| 1381 | + * On some archs, PREEMPT_RT has to delay sending a signal from a trap |
---|
| 1382 | + * since it can not enable preemption, and the signal code's spin_locks |
---|
| 1383 | + * turn into mutexes. Instead, it must set TIF_NOTIFY_RESUME which will |
---|
| 1384 | + * send the signal on exit of the trap. |
---|
| 1385 | + */ |
---|
| 1386 | +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND |
---|
| 1387 | + if (in_atomic()) { |
---|
| 1388 | + struct task_struct *t = current; |
---|
| 1389 | + |
---|
| 1390 | + if (WARN_ON_ONCE(t->forced_info.si_signo)) |
---|
| 1391 | + return 0; |
---|
| 1392 | + |
---|
| 1393 | + if (is_si_special(info)) { |
---|
| 1394 | + WARN_ON_ONCE(info != SEND_SIG_PRIV); |
---|
| 1395 | + t->forced_info.si_signo = info->si_signo; |
---|
| 1396 | + t->forced_info.si_errno = 0; |
---|
| 1397 | + t->forced_info.si_code = SI_KERNEL; |
---|
| 1398 | + t->forced_info.si_pid = 0; |
---|
| 1399 | + t->forced_info.si_uid = 0; |
---|
| 1400 | + } else { |
---|
| 1401 | + t->forced_info = *info; |
---|
| 1402 | + } |
---|
| 1403 | + |
---|
| 1404 | + set_tsk_thread_flag(t, TIF_NOTIFY_RESUME); |
---|
| 1405 | + return 0; |
---|
| 1406 | + } |
---|
| 1407 | +#endif |
---|
1297 | 1408 | spin_lock_irqsave(&t->sighand->siglock, flags); |
---|
1298 | 1409 | action = &t->sighand->action[sig-1]; |
---|
1299 | 1410 | ignored = action->sa.sa_handler == SIG_IGN; |
---|
.. | .. |
---|
1311 | 1422 | */ |
---|
1312 | 1423 | if (action->sa.sa_handler == SIG_DFL && !t->ptrace) |
---|
1313 | 1424 | t->signal->flags &= ~SIGNAL_UNKILLABLE; |
---|
1314 | | - ret = specific_send_sig_info(sig, info, t); |
---|
| 1425 | + ret = send_signal(sig, info, t, PIDTYPE_PID); |
---|
1315 | 1426 | spin_unlock_irqrestore(&t->sighand->siglock, flags); |
---|
1316 | 1427 | |
---|
1317 | 1428 | return ret; |
---|
| 1429 | +} |
---|
| 1430 | + |
---|
| 1431 | +int force_sig_info(struct kernel_siginfo *info) |
---|
| 1432 | +{ |
---|
| 1433 | + return force_sig_info_to_task(info, current); |
---|
1318 | 1434 | } |
---|
1319 | 1435 | |
---|
1320 | 1436 | /* |
---|
.. | .. |
---|
1364 | 1480 | * must see ->sighand == NULL. |
---|
1365 | 1481 | */ |
---|
1366 | 1482 | spin_lock_irqsave(&sighand->siglock, *flags); |
---|
1367 | | - if (likely(sighand == tsk->sighand)) |
---|
| 1483 | + if (likely(sighand == rcu_access_pointer(tsk->sighand))) |
---|
1368 | 1484 | break; |
---|
1369 | 1485 | spin_unlock_irqrestore(&sighand->siglock, *flags); |
---|
1370 | 1486 | } |
---|
.. | .. |
---|
1376 | 1492 | /* |
---|
1377 | 1493 | * send signal info to all the members of a group |
---|
1378 | 1494 | */ |
---|
1379 | | -int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p, |
---|
1380 | | - enum pid_type type) |
---|
| 1495 | +int group_send_sig_info(int sig, struct kernel_siginfo *info, |
---|
| 1496 | + struct task_struct *p, enum pid_type type) |
---|
1381 | 1497 | { |
---|
1382 | 1498 | int ret; |
---|
1383 | 1499 | |
---|
.. | .. |
---|
1385 | 1501 | ret = check_kill_permission(sig, info, p); |
---|
1386 | 1502 | rcu_read_unlock(); |
---|
1387 | 1503 | |
---|
1388 | | - if (!ret && sig) |
---|
| 1504 | + if (!ret && sig) { |
---|
1389 | 1505 | ret = do_send_sig_info(sig, info, p, type); |
---|
| 1506 | + if (!ret && sig == SIGKILL) { |
---|
| 1507 | + bool reap = false; |
---|
| 1508 | + |
---|
| 1509 | + trace_android_vh_process_killed(current, &reap); |
---|
| 1510 | + trace_android_vh_killed_process(current, p, &reap); |
---|
| 1511 | + if (reap) |
---|
| 1512 | + add_to_oom_reaper(p); |
---|
| 1513 | + } |
---|
| 1514 | + } |
---|
1390 | 1515 | |
---|
1391 | 1516 | return ret; |
---|
1392 | 1517 | } |
---|
.. | .. |
---|
1396 | 1521 | * control characters do (^C, ^Z etc) |
---|
1397 | 1522 | * - the caller must hold at least a readlock on tasklist_lock |
---|
1398 | 1523 | */ |
---|
1399 | | -int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp) |
---|
| 1524 | +int __kill_pgrp_info(int sig, struct kernel_siginfo *info, struct pid *pgrp) |
---|
1400 | 1525 | { |
---|
1401 | 1526 | struct task_struct *p = NULL; |
---|
1402 | 1527 | int retval, success; |
---|
.. | .. |
---|
1411 | 1536 | return success ? 0 : retval; |
---|
1412 | 1537 | } |
---|
1413 | 1538 | |
---|
1414 | | -int kill_pid_info(int sig, struct siginfo *info, struct pid *pid) |
---|
| 1539 | +int kill_pid_info(int sig, struct kernel_siginfo *info, struct pid *pid) |
---|
1415 | 1540 | { |
---|
1416 | 1541 | int error = -ESRCH; |
---|
1417 | 1542 | struct task_struct *p; |
---|
.. | .. |
---|
1433 | 1558 | } |
---|
1434 | 1559 | } |
---|
1435 | 1560 | |
---|
1436 | | -static int kill_proc_info(int sig, struct siginfo *info, pid_t pid) |
---|
| 1561 | +static int kill_proc_info(int sig, struct kernel_siginfo *info, pid_t pid) |
---|
1437 | 1562 | { |
---|
1438 | 1563 | int error; |
---|
1439 | 1564 | rcu_read_lock(); |
---|
.. | .. |
---|
1453 | 1578 | uid_eq(cred->uid, pcred->uid); |
---|
1454 | 1579 | } |
---|
1455 | 1580 | |
---|
1456 | | -/* like kill_pid_info(), but doesn't use uid/euid of "current" */ |
---|
1457 | | -int kill_pid_info_as_cred(int sig, struct siginfo *info, struct pid *pid, |
---|
1458 | | - const struct cred *cred) |
---|
| 1581 | +/* |
---|
| 1582 | + * The usb asyncio usage of siginfo is wrong. The glibc support |
---|
| 1583 | + * for asyncio which uses SI_ASYNCIO assumes the layout is SIL_RT. |
---|
| 1584 | + * AKA after the generic fields: |
---|
| 1585 | + * kernel_pid_t si_pid; |
---|
| 1586 | + * kernel_uid32_t si_uid; |
---|
| 1587 | + * sigval_t si_value; |
---|
| 1588 | + * |
---|
| 1589 | + * Unfortunately when usb generates SI_ASYNCIO it assumes the layout |
---|
| 1590 | + * after the generic fields is: |
---|
| 1591 | + * void __user *si_addr; |
---|
| 1592 | + * |
---|
| 1593 | + * This is a practical problem when there is a 64bit big endian kernel |
---|
| 1594 | + * and a 32bit userspace. As the 32bit address will encoded in the low |
---|
| 1595 | + * 32bits of the pointer. Those low 32bits will be stored at higher |
---|
| 1596 | + * address than appear in a 32 bit pointer. So userspace will not |
---|
| 1597 | + * see the address it was expecting for it's completions. |
---|
| 1598 | + * |
---|
| 1599 | + * There is nothing in the encoding that can allow |
---|
| 1600 | + * copy_siginfo_to_user32 to detect this confusion of formats, so |
---|
| 1601 | + * handle this by requiring the caller of kill_pid_usb_asyncio to |
---|
| 1602 | + * notice when this situration takes place and to store the 32bit |
---|
| 1603 | + * pointer in sival_int, instead of sival_addr of the sigval_t addr |
---|
| 1604 | + * parameter. |
---|
| 1605 | + */ |
---|
| 1606 | +int kill_pid_usb_asyncio(int sig, int errno, sigval_t addr, |
---|
| 1607 | + struct pid *pid, const struct cred *cred) |
---|
1459 | 1608 | { |
---|
1460 | | - int ret = -EINVAL; |
---|
| 1609 | + struct kernel_siginfo info; |
---|
1461 | 1610 | struct task_struct *p; |
---|
1462 | 1611 | unsigned long flags; |
---|
| 1612 | + int ret = -EINVAL; |
---|
1463 | 1613 | |
---|
1464 | 1614 | if (!valid_signal(sig)) |
---|
1465 | 1615 | return ret; |
---|
| 1616 | + |
---|
| 1617 | + clear_siginfo(&info); |
---|
| 1618 | + info.si_signo = sig; |
---|
| 1619 | + info.si_errno = errno; |
---|
| 1620 | + info.si_code = SI_ASYNCIO; |
---|
| 1621 | + *((sigval_t *)&info.si_pid) = addr; |
---|
1466 | 1622 | |
---|
1467 | 1623 | rcu_read_lock(); |
---|
1468 | 1624 | p = pid_task(pid, PIDTYPE_PID); |
---|
.. | .. |
---|
1470 | 1626 | ret = -ESRCH; |
---|
1471 | 1627 | goto out_unlock; |
---|
1472 | 1628 | } |
---|
1473 | | - if (si_fromuser(info) && !kill_as_cred_perm(cred, p)) { |
---|
| 1629 | + if (!kill_as_cred_perm(cred, p)) { |
---|
1474 | 1630 | ret = -EPERM; |
---|
1475 | 1631 | goto out_unlock; |
---|
1476 | 1632 | } |
---|
1477 | | - ret = security_task_kill(p, info, sig, cred); |
---|
| 1633 | + ret = security_task_kill(p, &info, sig, cred); |
---|
1478 | 1634 | if (ret) |
---|
1479 | 1635 | goto out_unlock; |
---|
1480 | 1636 | |
---|
1481 | 1637 | if (sig) { |
---|
1482 | 1638 | if (lock_task_sighand(p, &flags)) { |
---|
1483 | | - ret = __send_signal(sig, info, p, PIDTYPE_TGID, 0); |
---|
| 1639 | + ret = __send_signal(sig, &info, p, PIDTYPE_TGID, false); |
---|
1484 | 1640 | unlock_task_sighand(p, &flags); |
---|
1485 | 1641 | } else |
---|
1486 | 1642 | ret = -ESRCH; |
---|
.. | .. |
---|
1489 | 1645 | rcu_read_unlock(); |
---|
1490 | 1646 | return ret; |
---|
1491 | 1647 | } |
---|
1492 | | -EXPORT_SYMBOL_GPL(kill_pid_info_as_cred); |
---|
| 1648 | +EXPORT_SYMBOL_GPL(kill_pid_usb_asyncio); |
---|
1493 | 1649 | |
---|
1494 | 1650 | /* |
---|
1495 | 1651 | * kill_something_info() interprets pid in interesting ways just like kill(2). |
---|
.. | .. |
---|
1498 | 1654 | * is probably wrong. Should make it like BSD or SYSV. |
---|
1499 | 1655 | */ |
---|
1500 | 1656 | |
---|
1501 | | -static int kill_something_info(int sig, struct siginfo *info, pid_t pid) |
---|
| 1657 | +static int kill_something_info(int sig, struct kernel_siginfo *info, pid_t pid) |
---|
1502 | 1658 | { |
---|
1503 | 1659 | int ret; |
---|
1504 | 1660 | |
---|
1505 | | - if (pid > 0) { |
---|
1506 | | - rcu_read_lock(); |
---|
1507 | | - ret = kill_pid_info(sig, info, find_vpid(pid)); |
---|
1508 | | - rcu_read_unlock(); |
---|
1509 | | - return ret; |
---|
1510 | | - } |
---|
| 1661 | + if (pid > 0) |
---|
| 1662 | + return kill_proc_info(sig, info, pid); |
---|
1511 | 1663 | |
---|
1512 | 1664 | /* -INT_MIN is undefined. Exclude this case to avoid a UBSAN warning */ |
---|
1513 | 1665 | if (pid == INT_MIN) |
---|
.. | .. |
---|
1542 | 1694 | * These are for backward compatibility with the rest of the kernel source. |
---|
1543 | 1695 | */ |
---|
1544 | 1696 | |
---|
1545 | | -int send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
---|
| 1697 | +int send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p) |
---|
1546 | 1698 | { |
---|
1547 | 1699 | /* |
---|
1548 | 1700 | * Make sure legacy kernel users don't send in bad values |
---|
.. | .. |
---|
1553 | 1705 | |
---|
1554 | 1706 | return do_send_sig_info(sig, info, p, PIDTYPE_PID); |
---|
1555 | 1707 | } |
---|
| 1708 | +EXPORT_SYMBOL(send_sig_info); |
---|
1556 | 1709 | |
---|
1557 | 1710 | #define __si_special(priv) \ |
---|
1558 | 1711 | ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO) |
---|
.. | .. |
---|
1562 | 1715 | { |
---|
1563 | 1716 | return send_sig_info(sig, __si_special(priv), p); |
---|
1564 | 1717 | } |
---|
| 1718 | +EXPORT_SYMBOL(send_sig); |
---|
1565 | 1719 | |
---|
1566 | | -void force_sig(int sig, struct task_struct *p) |
---|
| 1720 | +void force_sig(int sig) |
---|
1567 | 1721 | { |
---|
1568 | | - force_sig_info(sig, SEND_SIG_PRIV, p); |
---|
| 1722 | + struct kernel_siginfo info; |
---|
| 1723 | + |
---|
| 1724 | + clear_siginfo(&info); |
---|
| 1725 | + info.si_signo = sig; |
---|
| 1726 | + info.si_errno = 0; |
---|
| 1727 | + info.si_code = SI_KERNEL; |
---|
| 1728 | + info.si_pid = 0; |
---|
| 1729 | + info.si_uid = 0; |
---|
| 1730 | + force_sig_info(&info); |
---|
1569 | 1731 | } |
---|
| 1732 | +EXPORT_SYMBOL(force_sig); |
---|
1570 | 1733 | |
---|
1571 | 1734 | /* |
---|
1572 | 1735 | * When things go south during signal handling, we |
---|
.. | .. |
---|
1574 | 1737 | * the problem was already a SIGSEGV, we'll want to |
---|
1575 | 1738 | * make sure we don't even try to deliver the signal.. |
---|
1576 | 1739 | */ |
---|
1577 | | -void force_sigsegv(int sig, struct task_struct *p) |
---|
| 1740 | +void force_sigsegv(int sig) |
---|
1578 | 1741 | { |
---|
| 1742 | + struct task_struct *p = current; |
---|
| 1743 | + |
---|
1579 | 1744 | if (sig == SIGSEGV) { |
---|
1580 | 1745 | unsigned long flags; |
---|
1581 | 1746 | spin_lock_irqsave(&p->sighand->siglock, flags); |
---|
1582 | 1747 | p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL; |
---|
1583 | 1748 | spin_unlock_irqrestore(&p->sighand->siglock, flags); |
---|
1584 | 1749 | } |
---|
1585 | | - force_sig(SIGSEGV, p); |
---|
| 1750 | + force_sig(SIGSEGV); |
---|
1586 | 1751 | } |
---|
1587 | 1752 | |
---|
1588 | | -int force_sig_fault(int sig, int code, void __user *addr |
---|
| 1753 | +int force_sig_fault_to_task(int sig, int code, void __user *addr |
---|
1589 | 1754 | ___ARCH_SI_TRAPNO(int trapno) |
---|
1590 | 1755 | ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr) |
---|
1591 | 1756 | , struct task_struct *t) |
---|
1592 | 1757 | { |
---|
1593 | | - struct siginfo info; |
---|
| 1758 | + struct kernel_siginfo info; |
---|
1594 | 1759 | |
---|
1595 | 1760 | clear_siginfo(&info); |
---|
1596 | 1761 | info.si_signo = sig; |
---|
.. | .. |
---|
1605 | 1770 | info.si_flags = flags; |
---|
1606 | 1771 | info.si_isr = isr; |
---|
1607 | 1772 | #endif |
---|
1608 | | - return force_sig_info(info.si_signo, &info, t); |
---|
| 1773 | + return force_sig_info_to_task(&info, t); |
---|
| 1774 | +} |
---|
| 1775 | + |
---|
| 1776 | +int force_sig_fault(int sig, int code, void __user *addr |
---|
| 1777 | + ___ARCH_SI_TRAPNO(int trapno) |
---|
| 1778 | + ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)) |
---|
| 1779 | +{ |
---|
| 1780 | + return force_sig_fault_to_task(sig, code, addr |
---|
| 1781 | + ___ARCH_SI_TRAPNO(trapno) |
---|
| 1782 | + ___ARCH_SI_IA64(imm, flags, isr), current); |
---|
1609 | 1783 | } |
---|
1610 | 1784 | |
---|
1611 | 1785 | int send_sig_fault(int sig, int code, void __user *addr |
---|
.. | .. |
---|
1613 | 1787 | ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr) |
---|
1614 | 1788 | , struct task_struct *t) |
---|
1615 | 1789 | { |
---|
1616 | | - struct siginfo info; |
---|
| 1790 | + struct kernel_siginfo info; |
---|
1617 | 1791 | |
---|
1618 | 1792 | clear_siginfo(&info); |
---|
1619 | 1793 | info.si_signo = sig; |
---|
.. | .. |
---|
1631 | 1805 | return send_sig_info(info.si_signo, &info, t); |
---|
1632 | 1806 | } |
---|
1633 | 1807 | |
---|
1634 | | -int force_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t) |
---|
| 1808 | +int force_sig_mceerr(int code, void __user *addr, short lsb) |
---|
1635 | 1809 | { |
---|
1636 | | - struct siginfo info; |
---|
| 1810 | + struct kernel_siginfo info; |
---|
1637 | 1811 | |
---|
1638 | 1812 | WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR)); |
---|
1639 | 1813 | clear_siginfo(&info); |
---|
.. | .. |
---|
1642 | 1816 | info.si_code = code; |
---|
1643 | 1817 | info.si_addr = addr; |
---|
1644 | 1818 | info.si_addr_lsb = lsb; |
---|
1645 | | - return force_sig_info(info.si_signo, &info, t); |
---|
| 1819 | + return force_sig_info(&info); |
---|
1646 | 1820 | } |
---|
1647 | 1821 | |
---|
1648 | 1822 | int send_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t) |
---|
1649 | 1823 | { |
---|
1650 | | - struct siginfo info; |
---|
| 1824 | + struct kernel_siginfo info; |
---|
1651 | 1825 | |
---|
1652 | 1826 | WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR)); |
---|
1653 | 1827 | clear_siginfo(&info); |
---|
.. | .. |
---|
1662 | 1836 | |
---|
1663 | 1837 | int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper) |
---|
1664 | 1838 | { |
---|
1665 | | - struct siginfo info; |
---|
| 1839 | + struct kernel_siginfo info; |
---|
1666 | 1840 | |
---|
1667 | 1841 | clear_siginfo(&info); |
---|
1668 | 1842 | info.si_signo = SIGSEGV; |
---|
.. | .. |
---|
1671 | 1845 | info.si_addr = addr; |
---|
1672 | 1846 | info.si_lower = lower; |
---|
1673 | 1847 | info.si_upper = upper; |
---|
1674 | | - return force_sig_info(info.si_signo, &info, current); |
---|
| 1848 | + return force_sig_info(&info); |
---|
1675 | 1849 | } |
---|
1676 | 1850 | |
---|
1677 | 1851 | #ifdef SEGV_PKUERR |
---|
1678 | 1852 | int force_sig_pkuerr(void __user *addr, u32 pkey) |
---|
1679 | 1853 | { |
---|
1680 | | - struct siginfo info; |
---|
| 1854 | + struct kernel_siginfo info; |
---|
1681 | 1855 | |
---|
1682 | 1856 | clear_siginfo(&info); |
---|
1683 | 1857 | info.si_signo = SIGSEGV; |
---|
.. | .. |
---|
1685 | 1859 | info.si_code = SEGV_PKUERR; |
---|
1686 | 1860 | info.si_addr = addr; |
---|
1687 | 1861 | info.si_pkey = pkey; |
---|
1688 | | - return force_sig_info(info.si_signo, &info, current); |
---|
| 1862 | + return force_sig_info(&info); |
---|
1689 | 1863 | } |
---|
1690 | 1864 | #endif |
---|
1691 | 1865 | |
---|
.. | .. |
---|
1694 | 1868 | */ |
---|
1695 | 1869 | int force_sig_ptrace_errno_trap(int errno, void __user *addr) |
---|
1696 | 1870 | { |
---|
1697 | | - struct siginfo info; |
---|
| 1871 | + struct kernel_siginfo info; |
---|
1698 | 1872 | |
---|
1699 | 1873 | clear_siginfo(&info); |
---|
1700 | 1874 | info.si_signo = SIGTRAP; |
---|
1701 | 1875 | info.si_errno = errno; |
---|
1702 | 1876 | info.si_code = TRAP_HWBKPT; |
---|
1703 | 1877 | info.si_addr = addr; |
---|
1704 | | - return force_sig_info(info.si_signo, &info, current); |
---|
| 1878 | + return force_sig_info(&info); |
---|
1705 | 1879 | } |
---|
1706 | 1880 | |
---|
1707 | 1881 | int kill_pgrp(struct pid *pid, int sig, int priv) |
---|
.. | .. |
---|
1733 | 1907 | */ |
---|
1734 | 1908 | struct sigqueue *sigqueue_alloc(void) |
---|
1735 | 1909 | { |
---|
1736 | | - struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0); |
---|
| 1910 | + /* Preallocated sigqueue objects always from the slabcache ! */ |
---|
| 1911 | + struct sigqueue *q = __sigqueue_do_alloc(-1, current, GFP_KERNEL, 0, 1); |
---|
1737 | 1912 | |
---|
1738 | 1913 | if (q) |
---|
1739 | 1914 | q->flags |= SIGQUEUE_PREALLOC; |
---|
.. | .. |
---|
1818 | 1993 | { |
---|
1819 | 1994 | struct pid *pid; |
---|
1820 | 1995 | |
---|
| 1996 | + WARN_ON(task->exit_state == 0); |
---|
1821 | 1997 | pid = task_pid(task); |
---|
1822 | 1998 | wake_up_all(&pid->wait_pidfd); |
---|
1823 | 1999 | } |
---|
.. | .. |
---|
1831 | 2007 | */ |
---|
1832 | 2008 | bool do_notify_parent(struct task_struct *tsk, int sig) |
---|
1833 | 2009 | { |
---|
1834 | | - struct siginfo info; |
---|
| 2010 | + struct kernel_siginfo info; |
---|
1835 | 2011 | unsigned long flags; |
---|
1836 | 2012 | struct sighand_struct *psig; |
---|
1837 | 2013 | bool autoreap = false; |
---|
1838 | 2014 | u64 utime, stime; |
---|
1839 | 2015 | |
---|
1840 | | - BUG_ON(sig == -1); |
---|
| 2016 | + WARN_ON_ONCE(sig == -1); |
---|
1841 | 2017 | |
---|
1842 | | - /* do_notify_parent_cldstop should have been called instead. */ |
---|
1843 | | - BUG_ON(task_is_stopped_or_traced(tsk)); |
---|
| 2018 | + /* do_notify_parent_cldstop should have been called instead. */ |
---|
| 2019 | + WARN_ON_ONCE(task_is_stopped_or_traced(tsk)); |
---|
1844 | 2020 | |
---|
1845 | | - BUG_ON(!tsk->ptrace && |
---|
| 2021 | + WARN_ON_ONCE(!tsk->ptrace && |
---|
1846 | 2022 | (tsk->group_leader != tsk || !thread_group_empty(tsk))); |
---|
1847 | 2023 | |
---|
1848 | 2024 | /* Wake up all pidfd waiters */ |
---|
.. | .. |
---|
1915 | 2091 | if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) |
---|
1916 | 2092 | sig = 0; |
---|
1917 | 2093 | } |
---|
| 2094 | + /* |
---|
| 2095 | + * Send with __send_signal as si_pid and si_uid are in the |
---|
| 2096 | + * parent's namespaces. |
---|
| 2097 | + */ |
---|
1918 | 2098 | if (valid_signal(sig) && sig) |
---|
1919 | | - __group_send_sig_info(sig, &info, tsk->parent); |
---|
| 2099 | + __send_signal(sig, &info, tsk->parent, PIDTYPE_TGID, false); |
---|
1920 | 2100 | __wake_up_parent(tsk, tsk->parent); |
---|
1921 | 2101 | spin_unlock_irqrestore(&psig->siglock, flags); |
---|
1922 | 2102 | |
---|
.. | .. |
---|
1939 | 2119 | static void do_notify_parent_cldstop(struct task_struct *tsk, |
---|
1940 | 2120 | bool for_ptracer, int why) |
---|
1941 | 2121 | { |
---|
1942 | | - struct siginfo info; |
---|
| 2122 | + struct kernel_siginfo info; |
---|
1943 | 2123 | unsigned long flags; |
---|
1944 | 2124 | struct task_struct *parent; |
---|
1945 | 2125 | struct sighand_struct *sighand; |
---|
.. | .. |
---|
2030 | 2210 | * If we actually decide not to stop at all because the tracer |
---|
2031 | 2211 | * is gone, we keep current->exit_code unless clear_code. |
---|
2032 | 2212 | */ |
---|
2033 | | -static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info) |
---|
| 2213 | +static void ptrace_stop(int exit_code, int why, int clear_code, kernel_siginfo_t *info) |
---|
2034 | 2214 | __releases(¤t->sighand->siglock) |
---|
2035 | 2215 | __acquires(¤t->sighand->siglock) |
---|
2036 | 2216 | { |
---|
.. | .. |
---|
2114 | 2294 | if (gstop_done && ptrace_reparented(current)) |
---|
2115 | 2295 | do_notify_parent_cldstop(current, false, why); |
---|
2116 | 2296 | |
---|
2117 | | - /* |
---|
2118 | | - * Don't want to allow preemption here, because |
---|
2119 | | - * sys_ptrace() needs this task to be inactive. |
---|
2120 | | - * |
---|
2121 | | - * XXX: implement read_unlock_no_resched(). |
---|
2122 | | - */ |
---|
2123 | | - preempt_disable(); |
---|
2124 | 2297 | read_unlock(&tasklist_lock); |
---|
2125 | 2298 | cgroup_enter_frozen(); |
---|
2126 | | - preempt_enable_no_resched(); |
---|
2127 | 2299 | freezable_schedule(); |
---|
2128 | 2300 | cgroup_leave_frozen(true); |
---|
2129 | 2301 | } else { |
---|
.. | .. |
---|
2168 | 2340 | |
---|
2169 | 2341 | static void ptrace_do_notify(int signr, int exit_code, int why) |
---|
2170 | 2342 | { |
---|
2171 | | - siginfo_t info; |
---|
| 2343 | + kernel_siginfo_t info; |
---|
2172 | 2344 | |
---|
2173 | 2345 | clear_siginfo(&info); |
---|
2174 | 2346 | info.si_signo = signr; |
---|
.. | .. |
---|
2387 | 2559 | freezable_schedule(); |
---|
2388 | 2560 | } |
---|
2389 | 2561 | |
---|
2390 | | -static int ptrace_signal(int signr, siginfo_t *info) |
---|
| 2562 | +static int ptrace_signal(int signr, kernel_siginfo_t *info) |
---|
2391 | 2563 | { |
---|
2392 | 2564 | /* |
---|
2393 | 2565 | * We do not check sig_kernel_stop(signr) but set this marker |
---|
.. | .. |
---|
2428 | 2600 | |
---|
2429 | 2601 | /* If the (new) signal is now blocked, requeue it. */ |
---|
2430 | 2602 | if (sigismember(¤t->blocked, signr)) { |
---|
2431 | | - specific_send_sig_info(signr, info, current); |
---|
| 2603 | + send_signal(signr, info, current, PIDTYPE_PID); |
---|
2432 | 2604 | signr = 0; |
---|
2433 | 2605 | } |
---|
2434 | 2606 | |
---|
2435 | 2607 | return signr; |
---|
| 2608 | +} |
---|
| 2609 | + |
---|
| 2610 | +static void hide_si_addr_tag_bits(struct ksignal *ksig) |
---|
| 2611 | +{ |
---|
| 2612 | + switch (siginfo_layout(ksig->sig, ksig->info.si_code)) { |
---|
| 2613 | + case SIL_FAULT: |
---|
| 2614 | + case SIL_FAULT_MCEERR: |
---|
| 2615 | + case SIL_FAULT_BNDERR: |
---|
| 2616 | + case SIL_FAULT_PKUERR: |
---|
| 2617 | + ksig->info.si_addr = arch_untagged_si_addr( |
---|
| 2618 | + ksig->info.si_addr, ksig->sig, ksig->info.si_code); |
---|
| 2619 | + break; |
---|
| 2620 | + case SIL_KILL: |
---|
| 2621 | + case SIL_TIMER: |
---|
| 2622 | + case SIL_POLL: |
---|
| 2623 | + case SIL_CHLD: |
---|
| 2624 | + case SIL_RT: |
---|
| 2625 | + case SIL_SYS: |
---|
| 2626 | + break; |
---|
| 2627 | + } |
---|
2436 | 2628 | } |
---|
2437 | 2629 | |
---|
2438 | 2630 | bool get_signal(struct ksignal *ksig) |
---|
.. | .. |
---|
2443 | 2635 | |
---|
2444 | 2636 | if (unlikely(current->task_works)) |
---|
2445 | 2637 | task_work_run(); |
---|
| 2638 | + |
---|
| 2639 | + /* |
---|
| 2640 | + * For non-generic architectures, check for TIF_NOTIFY_SIGNAL so |
---|
| 2641 | + * that the arch handlers don't all have to do it. If we get here |
---|
| 2642 | + * without TIF_SIGPENDING, just exit after running signal work. |
---|
| 2643 | + */ |
---|
| 2644 | + if (!IS_ENABLED(CONFIG_GENERIC_ENTRY)) { |
---|
| 2645 | + if (test_thread_flag(TIF_NOTIFY_SIGNAL)) |
---|
| 2646 | + tracehook_notify_signal(); |
---|
| 2647 | + if (!task_sigpending(current)) |
---|
| 2648 | + return false; |
---|
| 2649 | + } |
---|
2446 | 2650 | |
---|
2447 | 2651 | if (unlikely(uprobe_deny_signal())) |
---|
2448 | 2652 | return false; |
---|
.. | .. |
---|
2456 | 2660 | |
---|
2457 | 2661 | relock: |
---|
2458 | 2662 | spin_lock_irq(&sighand->siglock); |
---|
| 2663 | + |
---|
2459 | 2664 | /* |
---|
2460 | 2665 | * Every stopped thread goes here after wakeup. Check to see if |
---|
2461 | 2666 | * we should notify the parent, prepare_signal(SIGCONT) encodes |
---|
.. | .. |
---|
2499 | 2704 | trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO, |
---|
2500 | 2705 | &sighand->action[SIGKILL - 1]); |
---|
2501 | 2706 | recalc_sigpending(); |
---|
2502 | | - current->jobctl &= ~JOBCTL_TRAP_FREEZE; |
---|
2503 | | - spin_unlock_irq(&sighand->siglock); |
---|
2504 | | - if (unlikely(cgroup_task_frozen(current))) |
---|
2505 | | - cgroup_leave_frozen(true); |
---|
2506 | 2707 | goto fatal; |
---|
2507 | 2708 | } |
---|
2508 | 2709 | |
---|
.. | .. |
---|
2530 | 2731 | */ |
---|
2531 | 2732 | if (unlikely(cgroup_task_frozen(current))) { |
---|
2532 | 2733 | spin_unlock_irq(&sighand->siglock); |
---|
2533 | | - cgroup_leave_frozen(true); |
---|
| 2734 | + cgroup_leave_frozen(false); |
---|
2534 | 2735 | goto relock; |
---|
2535 | 2736 | } |
---|
2536 | 2737 | |
---|
.. | .. |
---|
2624 | 2825 | continue; |
---|
2625 | 2826 | } |
---|
2626 | 2827 | |
---|
2627 | | - spin_unlock_irq(&sighand->siglock); |
---|
2628 | 2828 | fatal: |
---|
| 2829 | + spin_unlock_irq(&sighand->siglock); |
---|
| 2830 | + if (unlikely(cgroup_task_frozen(current))) |
---|
| 2831 | + cgroup_leave_frozen(true); |
---|
2629 | 2832 | |
---|
2630 | 2833 | /* |
---|
2631 | 2834 | * Anything else is fatal, maybe with a core dump. |
---|
.. | .. |
---|
2648 | 2851 | } |
---|
2649 | 2852 | |
---|
2650 | 2853 | /* |
---|
| 2854 | + * PF_IO_WORKER threads will catch and exit on fatal signals |
---|
| 2855 | + * themselves. They have cleanup that must be performed, so |
---|
| 2856 | + * we cannot call do_exit() on their behalf. |
---|
| 2857 | + */ |
---|
| 2858 | + if (current->flags & PF_IO_WORKER) |
---|
| 2859 | + goto out; |
---|
| 2860 | + |
---|
| 2861 | + /* |
---|
2651 | 2862 | * Death signals, no core dump. |
---|
2652 | 2863 | */ |
---|
2653 | 2864 | do_group_exit(ksig->info.si_signo); |
---|
2654 | 2865 | /* NOTREACHED */ |
---|
2655 | 2866 | } |
---|
2656 | 2867 | spin_unlock_irq(&sighand->siglock); |
---|
2657 | | - |
---|
| 2868 | +out: |
---|
2658 | 2869 | ksig->sig = signr; |
---|
| 2870 | + |
---|
| 2871 | + if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS)) |
---|
| 2872 | + hide_si_addr_tag_bits(ksig); |
---|
| 2873 | + |
---|
2659 | 2874 | return ksig->sig > 0; |
---|
2660 | 2875 | } |
---|
2661 | 2876 | |
---|
.. | .. |
---|
2689 | 2904 | void signal_setup_done(int failed, struct ksignal *ksig, int stepping) |
---|
2690 | 2905 | { |
---|
2691 | 2906 | if (failed) |
---|
2692 | | - force_sigsegv(ksig->sig, current); |
---|
| 2907 | + force_sigsegv(ksig->sig); |
---|
2693 | 2908 | else |
---|
2694 | 2909 | signal_delivered(ksig, stepping); |
---|
2695 | 2910 | } |
---|
.. | .. |
---|
2718 | 2933 | /* Remove the signals this thread can handle. */ |
---|
2719 | 2934 | sigandsets(&retarget, &retarget, &t->blocked); |
---|
2720 | 2935 | |
---|
2721 | | - if (!signal_pending(t)) |
---|
| 2936 | + if (!task_sigpending(t)) |
---|
2722 | 2937 | signal_wake_up(t, 0); |
---|
2723 | 2938 | |
---|
2724 | 2939 | if (sigisemptyset(&retarget)) |
---|
.. | .. |
---|
2752 | 2967 | |
---|
2753 | 2968 | cgroup_threadgroup_change_end(tsk); |
---|
2754 | 2969 | |
---|
2755 | | - if (!signal_pending(tsk)) |
---|
| 2970 | + if (!task_sigpending(tsk)) |
---|
2756 | 2971 | goto out; |
---|
2757 | 2972 | |
---|
2758 | 2973 | unblocked = tsk->blocked; |
---|
.. | .. |
---|
2776 | 2991 | } |
---|
2777 | 2992 | } |
---|
2778 | 2993 | |
---|
2779 | | -EXPORT_SYMBOL(recalc_sigpending); |
---|
2780 | | -EXPORT_SYMBOL_GPL(dequeue_signal); |
---|
2781 | | -EXPORT_SYMBOL(flush_signals); |
---|
2782 | | -EXPORT_SYMBOL(force_sig); |
---|
2783 | | -EXPORT_SYMBOL(send_sig); |
---|
2784 | | -EXPORT_SYMBOL(send_sig_info); |
---|
2785 | | -EXPORT_SYMBOL(sigprocmask); |
---|
2786 | | - |
---|
2787 | 2994 | /* |
---|
2788 | 2995 | * System call entry points. |
---|
2789 | 2996 | */ |
---|
.. | .. |
---|
2804 | 3011 | |
---|
2805 | 3012 | static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset) |
---|
2806 | 3013 | { |
---|
2807 | | - if (signal_pending(tsk) && !thread_group_empty(tsk)) { |
---|
| 3014 | + if (task_sigpending(tsk) && !thread_group_empty(tsk)) { |
---|
2808 | 3015 | sigset_t newblocked; |
---|
2809 | 3016 | /* A set of now blocked but previously unblocked signals. */ |
---|
2810 | 3017 | sigandnsets(&newblocked, newset, ¤t->blocked); |
---|
.. | .. |
---|
2877 | 3084 | __set_current_blocked(&newset); |
---|
2878 | 3085 | return 0; |
---|
2879 | 3086 | } |
---|
| 3087 | +EXPORT_SYMBOL(sigprocmask); |
---|
| 3088 | + |
---|
| 3089 | +/* |
---|
| 3090 | + * The api helps set app-provided sigmasks. |
---|
| 3091 | + * |
---|
| 3092 | + * This is useful for syscalls such as ppoll, pselect, io_pgetevents and |
---|
| 3093 | + * epoll_pwait where a new sigmask is passed from userland for the syscalls. |
---|
| 3094 | + * |
---|
| 3095 | + * Note that it does set_restore_sigmask() in advance, so it must be always |
---|
| 3096 | + * paired with restore_saved_sigmask_unless() before return from syscall. |
---|
| 3097 | + */ |
---|
| 3098 | +int set_user_sigmask(const sigset_t __user *umask, size_t sigsetsize) |
---|
| 3099 | +{ |
---|
| 3100 | + sigset_t kmask; |
---|
| 3101 | + |
---|
| 3102 | + if (!umask) |
---|
| 3103 | + return 0; |
---|
| 3104 | + if (sigsetsize != sizeof(sigset_t)) |
---|
| 3105 | + return -EINVAL; |
---|
| 3106 | + if (copy_from_user(&kmask, umask, sizeof(sigset_t))) |
---|
| 3107 | + return -EFAULT; |
---|
| 3108 | + |
---|
| 3109 | + set_restore_sigmask(); |
---|
| 3110 | + current->saved_sigmask = current->blocked; |
---|
| 3111 | + set_current_blocked(&kmask); |
---|
| 3112 | + |
---|
| 3113 | + return 0; |
---|
| 3114 | +} |
---|
| 3115 | + |
---|
| 3116 | +#ifdef CONFIG_COMPAT |
---|
| 3117 | +int set_compat_user_sigmask(const compat_sigset_t __user *umask, |
---|
| 3118 | + size_t sigsetsize) |
---|
| 3119 | +{ |
---|
| 3120 | + sigset_t kmask; |
---|
| 3121 | + |
---|
| 3122 | + if (!umask) |
---|
| 3123 | + return 0; |
---|
| 3124 | + if (sigsetsize != sizeof(compat_sigset_t)) |
---|
| 3125 | + return -EINVAL; |
---|
| 3126 | + if (get_compat_sigset(&kmask, umask)) |
---|
| 3127 | + return -EFAULT; |
---|
| 3128 | + |
---|
| 3129 | + set_restore_sigmask(); |
---|
| 3130 | + current->saved_sigmask = current->blocked; |
---|
| 3131 | + set_current_blocked(&kmask); |
---|
| 3132 | + |
---|
| 3133 | + return 0; |
---|
| 3134 | +} |
---|
| 3135 | +#endif |
---|
2880 | 3136 | |
---|
2881 | 3137 | /** |
---|
2882 | 3138 | * sys_rt_sigprocmask - change the list of currently blocked signals |
---|
.. | .. |
---|
2987 | 3243 | } |
---|
2988 | 3244 | #endif |
---|
2989 | 3245 | |
---|
| 3246 | +static const struct { |
---|
| 3247 | + unsigned char limit, layout; |
---|
| 3248 | +} sig_sicodes[] = { |
---|
| 3249 | + [SIGILL] = { NSIGILL, SIL_FAULT }, |
---|
| 3250 | + [SIGFPE] = { NSIGFPE, SIL_FAULT }, |
---|
| 3251 | + [SIGSEGV] = { NSIGSEGV, SIL_FAULT }, |
---|
| 3252 | + [SIGBUS] = { NSIGBUS, SIL_FAULT }, |
---|
| 3253 | + [SIGTRAP] = { NSIGTRAP, SIL_FAULT }, |
---|
| 3254 | +#if defined(SIGEMT) |
---|
| 3255 | + [SIGEMT] = { NSIGEMT, SIL_FAULT }, |
---|
| 3256 | +#endif |
---|
| 3257 | + [SIGCHLD] = { NSIGCHLD, SIL_CHLD }, |
---|
| 3258 | + [SIGPOLL] = { NSIGPOLL, SIL_POLL }, |
---|
| 3259 | + [SIGSYS] = { NSIGSYS, SIL_SYS }, |
---|
| 3260 | +}; |
---|
| 3261 | + |
---|
| 3262 | +static bool known_siginfo_layout(unsigned sig, int si_code) |
---|
| 3263 | +{ |
---|
| 3264 | + if (si_code == SI_KERNEL) |
---|
| 3265 | + return true; |
---|
| 3266 | + else if ((si_code > SI_USER)) { |
---|
| 3267 | + if (sig_specific_sicodes(sig)) { |
---|
| 3268 | + if (si_code <= sig_sicodes[sig].limit) |
---|
| 3269 | + return true; |
---|
| 3270 | + } |
---|
| 3271 | + else if (si_code <= NSIGPOLL) |
---|
| 3272 | + return true; |
---|
| 3273 | + } |
---|
| 3274 | + else if (si_code >= SI_DETHREAD) |
---|
| 3275 | + return true; |
---|
| 3276 | + else if (si_code == SI_ASYNCNL) |
---|
| 3277 | + return true; |
---|
| 3278 | + return false; |
---|
| 3279 | +} |
---|
| 3280 | + |
---|
2990 | 3281 | enum siginfo_layout siginfo_layout(unsigned sig, int si_code) |
---|
2991 | 3282 | { |
---|
2992 | 3283 | enum siginfo_layout layout = SIL_KILL; |
---|
2993 | 3284 | if ((si_code > SI_USER) && (si_code < SI_KERNEL)) { |
---|
2994 | | - static const struct { |
---|
2995 | | - unsigned char limit, layout; |
---|
2996 | | - } filter[] = { |
---|
2997 | | - [SIGILL] = { NSIGILL, SIL_FAULT }, |
---|
2998 | | - [SIGFPE] = { NSIGFPE, SIL_FAULT }, |
---|
2999 | | - [SIGSEGV] = { NSIGSEGV, SIL_FAULT }, |
---|
3000 | | - [SIGBUS] = { NSIGBUS, SIL_FAULT }, |
---|
3001 | | - [SIGTRAP] = { NSIGTRAP, SIL_FAULT }, |
---|
3002 | | -#if defined(SIGEMT) && defined(NSIGEMT) |
---|
3003 | | - [SIGEMT] = { NSIGEMT, SIL_FAULT }, |
---|
3004 | | -#endif |
---|
3005 | | - [SIGCHLD] = { NSIGCHLD, SIL_CHLD }, |
---|
3006 | | - [SIGPOLL] = { NSIGPOLL, SIL_POLL }, |
---|
3007 | | - [SIGSYS] = { NSIGSYS, SIL_SYS }, |
---|
3008 | | - }; |
---|
3009 | | - if ((sig < ARRAY_SIZE(filter)) && (si_code <= filter[sig].limit)) { |
---|
3010 | | - layout = filter[sig].layout; |
---|
| 3285 | + if ((sig < ARRAY_SIZE(sig_sicodes)) && |
---|
| 3286 | + (si_code <= sig_sicodes[sig].limit)) { |
---|
| 3287 | + layout = sig_sicodes[sig].layout; |
---|
3011 | 3288 | /* Handle the exceptions */ |
---|
3012 | 3289 | if ((sig == SIGBUS) && |
---|
3013 | 3290 | (si_code >= BUS_MCEERR_AR) && (si_code <= BUS_MCEERR_AO)) |
---|
.. | .. |
---|
3032 | 3309 | return layout; |
---|
3033 | 3310 | } |
---|
3034 | 3311 | |
---|
3035 | | -int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from) |
---|
| 3312 | +static inline char __user *si_expansion(const siginfo_t __user *info) |
---|
3036 | 3313 | { |
---|
3037 | | - if (copy_to_user(to, from , sizeof(struct siginfo))) |
---|
| 3314 | + return ((char __user *)info) + sizeof(struct kernel_siginfo); |
---|
| 3315 | +} |
---|
| 3316 | + |
---|
| 3317 | +int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from) |
---|
| 3318 | +{ |
---|
| 3319 | + char __user *expansion = si_expansion(to); |
---|
| 3320 | + if (copy_to_user(to, from , sizeof(struct kernel_siginfo))) |
---|
| 3321 | + return -EFAULT; |
---|
| 3322 | + if (clear_user(expansion, SI_EXPANSION_SIZE)) |
---|
3038 | 3323 | return -EFAULT; |
---|
3039 | 3324 | return 0; |
---|
| 3325 | +} |
---|
| 3326 | + |
---|
| 3327 | +static int post_copy_siginfo_from_user(kernel_siginfo_t *info, |
---|
| 3328 | + const siginfo_t __user *from) |
---|
| 3329 | +{ |
---|
| 3330 | + if (unlikely(!known_siginfo_layout(info->si_signo, info->si_code))) { |
---|
| 3331 | + char __user *expansion = si_expansion(from); |
---|
| 3332 | + char buf[SI_EXPANSION_SIZE]; |
---|
| 3333 | + int i; |
---|
| 3334 | + /* |
---|
| 3335 | + * An unknown si_code might need more than |
---|
| 3336 | + * sizeof(struct kernel_siginfo) bytes. Verify all of the |
---|
| 3337 | + * extra bytes are 0. This guarantees copy_siginfo_to_user |
---|
| 3338 | + * will return this data to userspace exactly. |
---|
| 3339 | + */ |
---|
| 3340 | + if (copy_from_user(&buf, expansion, SI_EXPANSION_SIZE)) |
---|
| 3341 | + return -EFAULT; |
---|
| 3342 | + for (i = 0; i < SI_EXPANSION_SIZE; i++) { |
---|
| 3343 | + if (buf[i] != 0) |
---|
| 3344 | + return -E2BIG; |
---|
| 3345 | + } |
---|
| 3346 | + } |
---|
| 3347 | + return 0; |
---|
| 3348 | +} |
---|
| 3349 | + |
---|
| 3350 | +static int __copy_siginfo_from_user(int signo, kernel_siginfo_t *to, |
---|
| 3351 | + const siginfo_t __user *from) |
---|
| 3352 | +{ |
---|
| 3353 | + if (copy_from_user(to, from, sizeof(struct kernel_siginfo))) |
---|
| 3354 | + return -EFAULT; |
---|
| 3355 | + to->si_signo = signo; |
---|
| 3356 | + return post_copy_siginfo_from_user(to, from); |
---|
| 3357 | +} |
---|
| 3358 | + |
---|
| 3359 | +int copy_siginfo_from_user(kernel_siginfo_t *to, const siginfo_t __user *from) |
---|
| 3360 | +{ |
---|
| 3361 | + if (copy_from_user(to, from, sizeof(struct kernel_siginfo))) |
---|
| 3362 | + return -EFAULT; |
---|
| 3363 | + return post_copy_siginfo_from_user(to, from); |
---|
3040 | 3364 | } |
---|
3041 | 3365 | |
---|
3042 | 3366 | #ifdef CONFIG_COMPAT |
---|
3043 | | -int copy_siginfo_to_user32(struct compat_siginfo __user *to, |
---|
3044 | | - const struct siginfo *from) |
---|
3045 | | -#if defined(CONFIG_X86_X32_ABI) || defined(CONFIG_IA32_EMULATION) |
---|
| 3367 | +/** |
---|
| 3368 | + * copy_siginfo_to_external32 - copy a kernel siginfo into a compat user siginfo |
---|
| 3369 | + * @to: compat siginfo destination |
---|
| 3370 | + * @from: kernel siginfo source |
---|
| 3371 | + * |
---|
| 3372 | + * Note: This function does not work properly for the SIGCHLD on x32, but |
---|
| 3373 | + * fortunately it doesn't have to. The only valid callers for this function are |
---|
| 3374 | + * copy_siginfo_to_user32, which is overriden for x32 and the coredump code. |
---|
| 3375 | + * The latter does not care because SIGCHLD will never cause a coredump. |
---|
| 3376 | + */ |
---|
| 3377 | +void copy_siginfo_to_external32(struct compat_siginfo *to, |
---|
| 3378 | + const struct kernel_siginfo *from) |
---|
3046 | 3379 | { |
---|
3047 | | - return __copy_siginfo_to_user32(to, from, in_x32_syscall()); |
---|
3048 | | -} |
---|
3049 | | -int __copy_siginfo_to_user32(struct compat_siginfo __user *to, |
---|
3050 | | - const struct siginfo *from, bool x32_ABI) |
---|
3051 | | -#endif |
---|
3052 | | -{ |
---|
3053 | | - struct compat_siginfo new; |
---|
3054 | | - memset(&new, 0, sizeof(new)); |
---|
| 3380 | + memset(to, 0, sizeof(*to)); |
---|
3055 | 3381 | |
---|
3056 | | - new.si_signo = from->si_signo; |
---|
3057 | | - new.si_errno = from->si_errno; |
---|
3058 | | - new.si_code = from->si_code; |
---|
| 3382 | + to->si_signo = from->si_signo; |
---|
| 3383 | + to->si_errno = from->si_errno; |
---|
| 3384 | + to->si_code = from->si_code; |
---|
3059 | 3385 | switch(siginfo_layout(from->si_signo, from->si_code)) { |
---|
3060 | 3386 | case SIL_KILL: |
---|
3061 | | - new.si_pid = from->si_pid; |
---|
3062 | | - new.si_uid = from->si_uid; |
---|
| 3387 | + to->si_pid = from->si_pid; |
---|
| 3388 | + to->si_uid = from->si_uid; |
---|
3063 | 3389 | break; |
---|
3064 | 3390 | case SIL_TIMER: |
---|
3065 | | - new.si_tid = from->si_tid; |
---|
3066 | | - new.si_overrun = from->si_overrun; |
---|
3067 | | - new.si_int = from->si_int; |
---|
| 3391 | + to->si_tid = from->si_tid; |
---|
| 3392 | + to->si_overrun = from->si_overrun; |
---|
| 3393 | + to->si_int = from->si_int; |
---|
3068 | 3394 | break; |
---|
3069 | 3395 | case SIL_POLL: |
---|
3070 | | - new.si_band = from->si_band; |
---|
3071 | | - new.si_fd = from->si_fd; |
---|
| 3396 | + to->si_band = from->si_band; |
---|
| 3397 | + to->si_fd = from->si_fd; |
---|
3072 | 3398 | break; |
---|
3073 | 3399 | case SIL_FAULT: |
---|
3074 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3400 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3075 | 3401 | #ifdef __ARCH_SI_TRAPNO |
---|
3076 | | - new.si_trapno = from->si_trapno; |
---|
| 3402 | + to->si_trapno = from->si_trapno; |
---|
3077 | 3403 | #endif |
---|
3078 | 3404 | break; |
---|
3079 | 3405 | case SIL_FAULT_MCEERR: |
---|
3080 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3406 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3081 | 3407 | #ifdef __ARCH_SI_TRAPNO |
---|
3082 | | - new.si_trapno = from->si_trapno; |
---|
| 3408 | + to->si_trapno = from->si_trapno; |
---|
3083 | 3409 | #endif |
---|
3084 | | - new.si_addr_lsb = from->si_addr_lsb; |
---|
| 3410 | + to->si_addr_lsb = from->si_addr_lsb; |
---|
3085 | 3411 | break; |
---|
3086 | 3412 | case SIL_FAULT_BNDERR: |
---|
3087 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3413 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3088 | 3414 | #ifdef __ARCH_SI_TRAPNO |
---|
3089 | | - new.si_trapno = from->si_trapno; |
---|
| 3415 | + to->si_trapno = from->si_trapno; |
---|
3090 | 3416 | #endif |
---|
3091 | | - new.si_lower = ptr_to_compat(from->si_lower); |
---|
3092 | | - new.si_upper = ptr_to_compat(from->si_upper); |
---|
| 3417 | + to->si_lower = ptr_to_compat(from->si_lower); |
---|
| 3418 | + to->si_upper = ptr_to_compat(from->si_upper); |
---|
3093 | 3419 | break; |
---|
3094 | 3420 | case SIL_FAULT_PKUERR: |
---|
3095 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3421 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3096 | 3422 | #ifdef __ARCH_SI_TRAPNO |
---|
3097 | | - new.si_trapno = from->si_trapno; |
---|
| 3423 | + to->si_trapno = from->si_trapno; |
---|
3098 | 3424 | #endif |
---|
3099 | | - new.si_pkey = from->si_pkey; |
---|
| 3425 | + to->si_pkey = from->si_pkey; |
---|
3100 | 3426 | break; |
---|
3101 | 3427 | case SIL_CHLD: |
---|
3102 | | - new.si_pid = from->si_pid; |
---|
3103 | | - new.si_uid = from->si_uid; |
---|
3104 | | - new.si_status = from->si_status; |
---|
3105 | | -#ifdef CONFIG_X86_X32_ABI |
---|
3106 | | - if (x32_ABI) { |
---|
3107 | | - new._sifields._sigchld_x32._utime = from->si_utime; |
---|
3108 | | - new._sifields._sigchld_x32._stime = from->si_stime; |
---|
3109 | | - } else |
---|
3110 | | -#endif |
---|
3111 | | - { |
---|
3112 | | - new.si_utime = from->si_utime; |
---|
3113 | | - new.si_stime = from->si_stime; |
---|
3114 | | - } |
---|
| 3428 | + to->si_pid = from->si_pid; |
---|
| 3429 | + to->si_uid = from->si_uid; |
---|
| 3430 | + to->si_status = from->si_status; |
---|
| 3431 | + to->si_utime = from->si_utime; |
---|
| 3432 | + to->si_stime = from->si_stime; |
---|
3115 | 3433 | break; |
---|
3116 | 3434 | case SIL_RT: |
---|
3117 | | - new.si_pid = from->si_pid; |
---|
3118 | | - new.si_uid = from->si_uid; |
---|
3119 | | - new.si_int = from->si_int; |
---|
| 3435 | + to->si_pid = from->si_pid; |
---|
| 3436 | + to->si_uid = from->si_uid; |
---|
| 3437 | + to->si_int = from->si_int; |
---|
3120 | 3438 | break; |
---|
3121 | 3439 | case SIL_SYS: |
---|
3122 | | - new.si_call_addr = ptr_to_compat(from->si_call_addr); |
---|
3123 | | - new.si_syscall = from->si_syscall; |
---|
3124 | | - new.si_arch = from->si_arch; |
---|
| 3440 | + to->si_call_addr = ptr_to_compat(from->si_call_addr); |
---|
| 3441 | + to->si_syscall = from->si_syscall; |
---|
| 3442 | + to->si_arch = from->si_arch; |
---|
3125 | 3443 | break; |
---|
3126 | 3444 | } |
---|
| 3445 | +} |
---|
3127 | 3446 | |
---|
| 3447 | +int __copy_siginfo_to_user32(struct compat_siginfo __user *to, |
---|
| 3448 | + const struct kernel_siginfo *from) |
---|
| 3449 | +{ |
---|
| 3450 | + struct compat_siginfo new; |
---|
| 3451 | + |
---|
| 3452 | + copy_siginfo_to_external32(&new, from); |
---|
3128 | 3453 | if (copy_to_user(to, &new, sizeof(struct compat_siginfo))) |
---|
3129 | 3454 | return -EFAULT; |
---|
3130 | | - |
---|
3131 | 3455 | return 0; |
---|
3132 | 3456 | } |
---|
3133 | 3457 | |
---|
3134 | | -int copy_siginfo_from_user32(struct siginfo *to, |
---|
| 3458 | +static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, |
---|
| 3459 | + const struct compat_siginfo *from) |
---|
| 3460 | +{ |
---|
| 3461 | + clear_siginfo(to); |
---|
| 3462 | + to->si_signo = from->si_signo; |
---|
| 3463 | + to->si_errno = from->si_errno; |
---|
| 3464 | + to->si_code = from->si_code; |
---|
| 3465 | + switch(siginfo_layout(from->si_signo, from->si_code)) { |
---|
| 3466 | + case SIL_KILL: |
---|
| 3467 | + to->si_pid = from->si_pid; |
---|
| 3468 | + to->si_uid = from->si_uid; |
---|
| 3469 | + break; |
---|
| 3470 | + case SIL_TIMER: |
---|
| 3471 | + to->si_tid = from->si_tid; |
---|
| 3472 | + to->si_overrun = from->si_overrun; |
---|
| 3473 | + to->si_int = from->si_int; |
---|
| 3474 | + break; |
---|
| 3475 | + case SIL_POLL: |
---|
| 3476 | + to->si_band = from->si_band; |
---|
| 3477 | + to->si_fd = from->si_fd; |
---|
| 3478 | + break; |
---|
| 3479 | + case SIL_FAULT: |
---|
| 3480 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3481 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3482 | + to->si_trapno = from->si_trapno; |
---|
| 3483 | +#endif |
---|
| 3484 | + break; |
---|
| 3485 | + case SIL_FAULT_MCEERR: |
---|
| 3486 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3487 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3488 | + to->si_trapno = from->si_trapno; |
---|
| 3489 | +#endif |
---|
| 3490 | + to->si_addr_lsb = from->si_addr_lsb; |
---|
| 3491 | + break; |
---|
| 3492 | + case SIL_FAULT_BNDERR: |
---|
| 3493 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3494 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3495 | + to->si_trapno = from->si_trapno; |
---|
| 3496 | +#endif |
---|
| 3497 | + to->si_lower = compat_ptr(from->si_lower); |
---|
| 3498 | + to->si_upper = compat_ptr(from->si_upper); |
---|
| 3499 | + break; |
---|
| 3500 | + case SIL_FAULT_PKUERR: |
---|
| 3501 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3502 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3503 | + to->si_trapno = from->si_trapno; |
---|
| 3504 | +#endif |
---|
| 3505 | + to->si_pkey = from->si_pkey; |
---|
| 3506 | + break; |
---|
| 3507 | + case SIL_CHLD: |
---|
| 3508 | + to->si_pid = from->si_pid; |
---|
| 3509 | + to->si_uid = from->si_uid; |
---|
| 3510 | + to->si_status = from->si_status; |
---|
| 3511 | +#ifdef CONFIG_X86_X32_ABI |
---|
| 3512 | + if (in_x32_syscall()) { |
---|
| 3513 | + to->si_utime = from->_sifields._sigchld_x32._utime; |
---|
| 3514 | + to->si_stime = from->_sifields._sigchld_x32._stime; |
---|
| 3515 | + } else |
---|
| 3516 | +#endif |
---|
| 3517 | + { |
---|
| 3518 | + to->si_utime = from->si_utime; |
---|
| 3519 | + to->si_stime = from->si_stime; |
---|
| 3520 | + } |
---|
| 3521 | + break; |
---|
| 3522 | + case SIL_RT: |
---|
| 3523 | + to->si_pid = from->si_pid; |
---|
| 3524 | + to->si_uid = from->si_uid; |
---|
| 3525 | + to->si_int = from->si_int; |
---|
| 3526 | + break; |
---|
| 3527 | + case SIL_SYS: |
---|
| 3528 | + to->si_call_addr = compat_ptr(from->si_call_addr); |
---|
| 3529 | + to->si_syscall = from->si_syscall; |
---|
| 3530 | + to->si_arch = from->si_arch; |
---|
| 3531 | + break; |
---|
| 3532 | + } |
---|
| 3533 | + return 0; |
---|
| 3534 | +} |
---|
| 3535 | + |
---|
| 3536 | +static int __copy_siginfo_from_user32(int signo, struct kernel_siginfo *to, |
---|
| 3537 | + const struct compat_siginfo __user *ufrom) |
---|
| 3538 | +{ |
---|
| 3539 | + struct compat_siginfo from; |
---|
| 3540 | + |
---|
| 3541 | + if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo))) |
---|
| 3542 | + return -EFAULT; |
---|
| 3543 | + |
---|
| 3544 | + from.si_signo = signo; |
---|
| 3545 | + return post_copy_siginfo_from_user32(to, &from); |
---|
| 3546 | +} |
---|
| 3547 | + |
---|
| 3548 | +int copy_siginfo_from_user32(struct kernel_siginfo *to, |
---|
3135 | 3549 | const struct compat_siginfo __user *ufrom) |
---|
3136 | 3550 | { |
---|
3137 | 3551 | struct compat_siginfo from; |
---|
.. | .. |
---|
3139 | 3553 | if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo))) |
---|
3140 | 3554 | return -EFAULT; |
---|
3141 | 3555 | |
---|
3142 | | - clear_siginfo(to); |
---|
3143 | | - to->si_signo = from.si_signo; |
---|
3144 | | - to->si_errno = from.si_errno; |
---|
3145 | | - to->si_code = from.si_code; |
---|
3146 | | - switch(siginfo_layout(from.si_signo, from.si_code)) { |
---|
3147 | | - case SIL_KILL: |
---|
3148 | | - to->si_pid = from.si_pid; |
---|
3149 | | - to->si_uid = from.si_uid; |
---|
3150 | | - break; |
---|
3151 | | - case SIL_TIMER: |
---|
3152 | | - to->si_tid = from.si_tid; |
---|
3153 | | - to->si_overrun = from.si_overrun; |
---|
3154 | | - to->si_int = from.si_int; |
---|
3155 | | - break; |
---|
3156 | | - case SIL_POLL: |
---|
3157 | | - to->si_band = from.si_band; |
---|
3158 | | - to->si_fd = from.si_fd; |
---|
3159 | | - break; |
---|
3160 | | - case SIL_FAULT: |
---|
3161 | | - to->si_addr = compat_ptr(from.si_addr); |
---|
3162 | | -#ifdef __ARCH_SI_TRAPNO |
---|
3163 | | - to->si_trapno = from.si_trapno; |
---|
3164 | | -#endif |
---|
3165 | | - break; |
---|
3166 | | - case SIL_FAULT_MCEERR: |
---|
3167 | | - to->si_addr = compat_ptr(from.si_addr); |
---|
3168 | | -#ifdef __ARCH_SI_TRAPNO |
---|
3169 | | - to->si_trapno = from.si_trapno; |
---|
3170 | | -#endif |
---|
3171 | | - to->si_addr_lsb = from.si_addr_lsb; |
---|
3172 | | - break; |
---|
3173 | | - case SIL_FAULT_BNDERR: |
---|
3174 | | - to->si_addr = compat_ptr(from.si_addr); |
---|
3175 | | -#ifdef __ARCH_SI_TRAPNO |
---|
3176 | | - to->si_trapno = from.si_trapno; |
---|
3177 | | -#endif |
---|
3178 | | - to->si_lower = compat_ptr(from.si_lower); |
---|
3179 | | - to->si_upper = compat_ptr(from.si_upper); |
---|
3180 | | - break; |
---|
3181 | | - case SIL_FAULT_PKUERR: |
---|
3182 | | - to->si_addr = compat_ptr(from.si_addr); |
---|
3183 | | -#ifdef __ARCH_SI_TRAPNO |
---|
3184 | | - to->si_trapno = from.si_trapno; |
---|
3185 | | -#endif |
---|
3186 | | - to->si_pkey = from.si_pkey; |
---|
3187 | | - break; |
---|
3188 | | - case SIL_CHLD: |
---|
3189 | | - to->si_pid = from.si_pid; |
---|
3190 | | - to->si_uid = from.si_uid; |
---|
3191 | | - to->si_status = from.si_status; |
---|
3192 | | -#ifdef CONFIG_X86_X32_ABI |
---|
3193 | | - if (in_x32_syscall()) { |
---|
3194 | | - to->si_utime = from._sifields._sigchld_x32._utime; |
---|
3195 | | - to->si_stime = from._sifields._sigchld_x32._stime; |
---|
3196 | | - } else |
---|
3197 | | -#endif |
---|
3198 | | - { |
---|
3199 | | - to->si_utime = from.si_utime; |
---|
3200 | | - to->si_stime = from.si_stime; |
---|
3201 | | - } |
---|
3202 | | - break; |
---|
3203 | | - case SIL_RT: |
---|
3204 | | - to->si_pid = from.si_pid; |
---|
3205 | | - to->si_uid = from.si_uid; |
---|
3206 | | - to->si_int = from.si_int; |
---|
3207 | | - break; |
---|
3208 | | - case SIL_SYS: |
---|
3209 | | - to->si_call_addr = compat_ptr(from.si_call_addr); |
---|
3210 | | - to->si_syscall = from.si_syscall; |
---|
3211 | | - to->si_arch = from.si_arch; |
---|
3212 | | - break; |
---|
3213 | | - } |
---|
3214 | | - return 0; |
---|
| 3556 | + return post_copy_siginfo_from_user32(to, &from); |
---|
3215 | 3557 | } |
---|
3216 | 3558 | #endif /* CONFIG_COMPAT */ |
---|
3217 | 3559 | |
---|
.. | .. |
---|
3221 | 3563 | * @info: if non-null, the signal's siginfo is returned here |
---|
3222 | 3564 | * @ts: upper bound on process time suspension |
---|
3223 | 3565 | */ |
---|
3224 | | -static int do_sigtimedwait(const sigset_t *which, siginfo_t *info, |
---|
3225 | | - const struct timespec *ts) |
---|
| 3566 | +static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info, |
---|
| 3567 | + const struct timespec64 *ts) |
---|
3226 | 3568 | { |
---|
3227 | 3569 | ktime_t *to = NULL, timeout = KTIME_MAX; |
---|
3228 | 3570 | struct task_struct *tsk = current; |
---|
.. | .. |
---|
3230 | 3572 | int sig, ret = 0; |
---|
3231 | 3573 | |
---|
3232 | 3574 | if (ts) { |
---|
3233 | | - if (!timespec_valid(ts)) |
---|
| 3575 | + if (!timespec64_valid(ts)) |
---|
3234 | 3576 | return -EINVAL; |
---|
3235 | | - timeout = timespec_to_ktime(*ts); |
---|
| 3577 | + timeout = timespec64_to_ktime(*ts); |
---|
3236 | 3578 | to = &timeout; |
---|
3237 | 3579 | } |
---|
3238 | 3580 | |
---|
.. | .. |
---|
3280 | 3622 | * @sigsetsize: size of sigset_t type |
---|
3281 | 3623 | */ |
---|
3282 | 3624 | SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, |
---|
3283 | | - siginfo_t __user *, uinfo, const struct timespec __user *, uts, |
---|
| 3625 | + siginfo_t __user *, uinfo, |
---|
| 3626 | + const struct __kernel_timespec __user *, uts, |
---|
3284 | 3627 | size_t, sigsetsize) |
---|
3285 | 3628 | { |
---|
3286 | 3629 | sigset_t these; |
---|
3287 | | - struct timespec ts; |
---|
3288 | | - siginfo_t info; |
---|
| 3630 | + struct timespec64 ts; |
---|
| 3631 | + kernel_siginfo_t info; |
---|
3289 | 3632 | int ret; |
---|
3290 | 3633 | |
---|
3291 | 3634 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
---|
.. | .. |
---|
3296 | 3639 | return -EFAULT; |
---|
3297 | 3640 | |
---|
3298 | 3641 | if (uts) { |
---|
3299 | | - if (copy_from_user(&ts, uts, sizeof(ts))) |
---|
| 3642 | + if (get_timespec64(&ts, uts)) |
---|
3300 | 3643 | return -EFAULT; |
---|
3301 | 3644 | } |
---|
3302 | 3645 | |
---|
.. | .. |
---|
3310 | 3653 | return ret; |
---|
3311 | 3654 | } |
---|
3312 | 3655 | |
---|
| 3656 | +#ifdef CONFIG_COMPAT_32BIT_TIME |
---|
| 3657 | +SYSCALL_DEFINE4(rt_sigtimedwait_time32, const sigset_t __user *, uthese, |
---|
| 3658 | + siginfo_t __user *, uinfo, |
---|
| 3659 | + const struct old_timespec32 __user *, uts, |
---|
| 3660 | + size_t, sigsetsize) |
---|
| 3661 | +{ |
---|
| 3662 | + sigset_t these; |
---|
| 3663 | + struct timespec64 ts; |
---|
| 3664 | + kernel_siginfo_t info; |
---|
| 3665 | + int ret; |
---|
| 3666 | + |
---|
| 3667 | + if (sigsetsize != sizeof(sigset_t)) |
---|
| 3668 | + return -EINVAL; |
---|
| 3669 | + |
---|
| 3670 | + if (copy_from_user(&these, uthese, sizeof(these))) |
---|
| 3671 | + return -EFAULT; |
---|
| 3672 | + |
---|
| 3673 | + if (uts) { |
---|
| 3674 | + if (get_old_timespec32(&ts, uts)) |
---|
| 3675 | + return -EFAULT; |
---|
| 3676 | + } |
---|
| 3677 | + |
---|
| 3678 | + ret = do_sigtimedwait(&these, &info, uts ? &ts : NULL); |
---|
| 3679 | + |
---|
| 3680 | + if (ret > 0 && uinfo) { |
---|
| 3681 | + if (copy_siginfo_to_user(uinfo, &info)) |
---|
| 3682 | + ret = -EFAULT; |
---|
| 3683 | + } |
---|
| 3684 | + |
---|
| 3685 | + return ret; |
---|
| 3686 | +} |
---|
| 3687 | +#endif |
---|
| 3688 | + |
---|
3313 | 3689 | #ifdef CONFIG_COMPAT |
---|
3314 | | -COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, |
---|
| 3690 | +COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time64, compat_sigset_t __user *, uthese, |
---|
3315 | 3691 | struct compat_siginfo __user *, uinfo, |
---|
3316 | | - struct compat_timespec __user *, uts, compat_size_t, sigsetsize) |
---|
| 3692 | + struct __kernel_timespec __user *, uts, compat_size_t, sigsetsize) |
---|
3317 | 3693 | { |
---|
3318 | 3694 | sigset_t s; |
---|
3319 | | - struct timespec t; |
---|
3320 | | - siginfo_t info; |
---|
| 3695 | + struct timespec64 t; |
---|
| 3696 | + kernel_siginfo_t info; |
---|
3321 | 3697 | long ret; |
---|
3322 | 3698 | |
---|
3323 | 3699 | if (sigsetsize != sizeof(sigset_t)) |
---|
.. | .. |
---|
3327 | 3703 | return -EFAULT; |
---|
3328 | 3704 | |
---|
3329 | 3705 | if (uts) { |
---|
3330 | | - if (compat_get_timespec(&t, uts)) |
---|
| 3706 | + if (get_timespec64(&t, uts)) |
---|
| 3707 | + return -EFAULT; |
---|
| 3708 | + } |
---|
| 3709 | + |
---|
| 3710 | + ret = do_sigtimedwait(&s, &info, uts ? &t : NULL); |
---|
| 3711 | + |
---|
| 3712 | + if (ret > 0 && uinfo) { |
---|
| 3713 | + if (copy_siginfo_to_user32(uinfo, &info)) |
---|
| 3714 | + ret = -EFAULT; |
---|
| 3715 | + } |
---|
| 3716 | + |
---|
| 3717 | + return ret; |
---|
| 3718 | +} |
---|
| 3719 | + |
---|
| 3720 | +#ifdef CONFIG_COMPAT_32BIT_TIME |
---|
| 3721 | +COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time32, compat_sigset_t __user *, uthese, |
---|
| 3722 | + struct compat_siginfo __user *, uinfo, |
---|
| 3723 | + struct old_timespec32 __user *, uts, compat_size_t, sigsetsize) |
---|
| 3724 | +{ |
---|
| 3725 | + sigset_t s; |
---|
| 3726 | + struct timespec64 t; |
---|
| 3727 | + kernel_siginfo_t info; |
---|
| 3728 | + long ret; |
---|
| 3729 | + |
---|
| 3730 | + if (sigsetsize != sizeof(sigset_t)) |
---|
| 3731 | + return -EINVAL; |
---|
| 3732 | + |
---|
| 3733 | + if (get_compat_sigset(&s, uthese)) |
---|
| 3734 | + return -EFAULT; |
---|
| 3735 | + |
---|
| 3736 | + if (uts) { |
---|
| 3737 | + if (get_old_timespec32(&t, uts)) |
---|
3331 | 3738 | return -EFAULT; |
---|
3332 | 3739 | } |
---|
3333 | 3740 | |
---|
.. | .. |
---|
3341 | 3748 | return ret; |
---|
3342 | 3749 | } |
---|
3343 | 3750 | #endif |
---|
| 3751 | +#endif |
---|
3344 | 3752 | |
---|
3345 | | -static inline void prepare_kill_siginfo(int sig, struct siginfo *info) |
---|
| 3753 | +static inline void prepare_kill_siginfo(int sig, struct kernel_siginfo *info) |
---|
3346 | 3754 | { |
---|
3347 | 3755 | clear_siginfo(info); |
---|
3348 | 3756 | info->si_signo = sig; |
---|
.. | .. |
---|
3359 | 3767 | */ |
---|
3360 | 3768 | SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) |
---|
3361 | 3769 | { |
---|
3362 | | - struct siginfo info; |
---|
| 3770 | + struct kernel_siginfo info; |
---|
3363 | 3771 | |
---|
3364 | 3772 | prepare_kill_siginfo(sig, &info); |
---|
3365 | 3773 | |
---|
.. | .. |
---|
3387 | 3795 | return true; |
---|
3388 | 3796 | } |
---|
3389 | 3797 | |
---|
3390 | | -static int copy_siginfo_from_user_any(siginfo_t *kinfo, siginfo_t __user *info) |
---|
| 3798 | +static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info) |
---|
3391 | 3799 | { |
---|
3392 | 3800 | #ifdef CONFIG_COMPAT |
---|
3393 | 3801 | /* |
---|
.. | .. |
---|
3399 | 3807 | return copy_siginfo_from_user32( |
---|
3400 | 3808 | kinfo, (struct compat_siginfo __user *)info); |
---|
3401 | 3809 | #endif |
---|
3402 | | - return copy_from_user(kinfo, info, sizeof(siginfo_t)); |
---|
| 3810 | + return copy_siginfo_from_user(kinfo, info); |
---|
3403 | 3811 | } |
---|
3404 | 3812 | |
---|
3405 | 3813 | static struct pid *pidfd_to_pid(const struct file *file) |
---|
3406 | 3814 | { |
---|
3407 | | - if (file->f_op == &pidfd_fops) |
---|
3408 | | - return file->private_data; |
---|
| 3815 | + struct pid *pid; |
---|
| 3816 | + |
---|
| 3817 | + pid = pidfd_pid(file); |
---|
| 3818 | + if (!IS_ERR(pid)) |
---|
| 3819 | + return pid; |
---|
3409 | 3820 | |
---|
3410 | 3821 | return tgid_pidfd_to_pid(file); |
---|
3411 | 3822 | } |
---|
.. | .. |
---|
3434 | 3845 | int ret; |
---|
3435 | 3846 | struct fd f; |
---|
3436 | 3847 | struct pid *pid; |
---|
3437 | | - siginfo_t kinfo; |
---|
| 3848 | + kernel_siginfo_t kinfo; |
---|
3438 | 3849 | |
---|
3439 | 3850 | /* Enforce flags be set to 0 until we add an extension. */ |
---|
3440 | 3851 | if (flags) |
---|
.. | .. |
---|
3481 | 3892 | } |
---|
3482 | 3893 | |
---|
3483 | 3894 | static int |
---|
3484 | | -do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info) |
---|
| 3895 | +do_send_specific(pid_t tgid, pid_t pid, int sig, struct kernel_siginfo *info) |
---|
3485 | 3896 | { |
---|
3486 | 3897 | struct task_struct *p; |
---|
3487 | 3898 | int error = -ESRCH; |
---|
.. | .. |
---|
3512 | 3923 | |
---|
3513 | 3924 | static int do_tkill(pid_t tgid, pid_t pid, int sig) |
---|
3514 | 3925 | { |
---|
3515 | | - struct siginfo info; |
---|
| 3926 | + struct kernel_siginfo info; |
---|
3516 | 3927 | |
---|
3517 | 3928 | clear_siginfo(&info); |
---|
3518 | 3929 | info.si_signo = sig; |
---|
.. | .. |
---|
3559 | 3970 | return do_tkill(0, pid, sig); |
---|
3560 | 3971 | } |
---|
3561 | 3972 | |
---|
3562 | | -static int do_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t *info) |
---|
| 3973 | +static int do_rt_sigqueueinfo(pid_t pid, int sig, kernel_siginfo_t *info) |
---|
3563 | 3974 | { |
---|
3564 | 3975 | /* Not even root can pretend to send signals from the kernel. |
---|
3565 | 3976 | * Nor can they impersonate a kill()/tgkill(), which adds source info. |
---|
.. | .. |
---|
3567 | 3978 | if ((info->si_code >= 0 || info->si_code == SI_TKILL) && |
---|
3568 | 3979 | (task_pid_vnr(current) != pid)) |
---|
3569 | 3980 | return -EPERM; |
---|
3570 | | - |
---|
3571 | | - info->si_signo = sig; |
---|
3572 | 3981 | |
---|
3573 | 3982 | /* POSIX.1b doesn't mention process groups. */ |
---|
3574 | 3983 | return kill_proc_info(sig, info, pid); |
---|
.. | .. |
---|
3583 | 3992 | SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, |
---|
3584 | 3993 | siginfo_t __user *, uinfo) |
---|
3585 | 3994 | { |
---|
3586 | | - siginfo_t info; |
---|
3587 | | - if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) |
---|
3588 | | - return -EFAULT; |
---|
| 3995 | + kernel_siginfo_t info; |
---|
| 3996 | + int ret = __copy_siginfo_from_user(sig, &info, uinfo); |
---|
| 3997 | + if (unlikely(ret)) |
---|
| 3998 | + return ret; |
---|
3589 | 3999 | return do_rt_sigqueueinfo(pid, sig, &info); |
---|
3590 | 4000 | } |
---|
3591 | 4001 | |
---|
.. | .. |
---|
3595 | 4005 | int, sig, |
---|
3596 | 4006 | struct compat_siginfo __user *, uinfo) |
---|
3597 | 4007 | { |
---|
3598 | | - siginfo_t info; |
---|
3599 | | - int ret = copy_siginfo_from_user32(&info, uinfo); |
---|
| 4008 | + kernel_siginfo_t info; |
---|
| 4009 | + int ret = __copy_siginfo_from_user32(sig, &info, uinfo); |
---|
3600 | 4010 | if (unlikely(ret)) |
---|
3601 | 4011 | return ret; |
---|
3602 | 4012 | return do_rt_sigqueueinfo(pid, sig, &info); |
---|
3603 | 4013 | } |
---|
3604 | 4014 | #endif |
---|
3605 | 4015 | |
---|
3606 | | -static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, siginfo_t *info) |
---|
| 4016 | +static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, kernel_siginfo_t *info) |
---|
3607 | 4017 | { |
---|
3608 | 4018 | /* This is only valid for single tasks */ |
---|
3609 | 4019 | if (pid <= 0 || tgid <= 0) |
---|
.. | .. |
---|
3616 | 4026 | (task_pid_vnr(current) != pid)) |
---|
3617 | 4027 | return -EPERM; |
---|
3618 | 4028 | |
---|
3619 | | - info->si_signo = sig; |
---|
3620 | | - |
---|
3621 | 4029 | return do_send_specific(tgid, pid, sig, info); |
---|
3622 | 4030 | } |
---|
3623 | 4031 | |
---|
3624 | 4032 | SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig, |
---|
3625 | 4033 | siginfo_t __user *, uinfo) |
---|
3626 | 4034 | { |
---|
3627 | | - siginfo_t info; |
---|
3628 | | - |
---|
3629 | | - if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) |
---|
3630 | | - return -EFAULT; |
---|
3631 | | - |
---|
| 4035 | + kernel_siginfo_t info; |
---|
| 4036 | + int ret = __copy_siginfo_from_user(sig, &info, uinfo); |
---|
| 4037 | + if (unlikely(ret)) |
---|
| 4038 | + return ret; |
---|
3632 | 4039 | return do_rt_tgsigqueueinfo(tgid, pid, sig, &info); |
---|
3633 | 4040 | } |
---|
3634 | 4041 | |
---|
.. | .. |
---|
3639 | 4046 | int, sig, |
---|
3640 | 4047 | struct compat_siginfo __user *, uinfo) |
---|
3641 | 4048 | { |
---|
3642 | | - siginfo_t info; |
---|
3643 | | - |
---|
3644 | | - if (copy_siginfo_from_user32(&info, uinfo)) |
---|
3645 | | - return -EFAULT; |
---|
| 4049 | + kernel_siginfo_t info; |
---|
| 4050 | + int ret = __copy_siginfo_from_user32(sig, &info, uinfo); |
---|
| 4051 | + if (unlikely(ret)) |
---|
| 4052 | + return ret; |
---|
3646 | 4053 | return do_rt_tgsigqueueinfo(tgid, pid, sig, &info); |
---|
3647 | 4054 | } |
---|
3648 | 4055 | #endif |
---|
.. | .. |
---|
3687 | 4094 | spin_lock_irq(&p->sighand->siglock); |
---|
3688 | 4095 | if (oact) |
---|
3689 | 4096 | *oact = *k; |
---|
| 4097 | + |
---|
| 4098 | + /* |
---|
| 4099 | + * Make sure that we never accidentally claim to support SA_UNSUPPORTED, |
---|
| 4100 | + * e.g. by having an architecture use the bit in their uapi. |
---|
| 4101 | + */ |
---|
| 4102 | + BUILD_BUG_ON(UAPI_SA_FLAGS & SA_UNSUPPORTED); |
---|
| 4103 | + |
---|
| 4104 | + /* |
---|
| 4105 | + * Clear unknown flag bits in order to allow userspace to detect missing |
---|
| 4106 | + * support for flag bits and to allow the kernel to use non-uapi bits |
---|
| 4107 | + * internally. |
---|
| 4108 | + */ |
---|
| 4109 | + if (act) |
---|
| 4110 | + act->sa.sa_flags &= UAPI_SA_FLAGS; |
---|
| 4111 | + if (oact) |
---|
| 4112 | + oact->sa.sa_flags &= UAPI_SA_FLAGS; |
---|
3690 | 4113 | |
---|
3691 | 4114 | sigaction_compat_abi(act, oact); |
---|
3692 | 4115 | |
---|
.. | .. |
---|
4033 | 4456 | |
---|
4034 | 4457 | if (act) { |
---|
4035 | 4458 | old_sigset_t mask; |
---|
4036 | | - if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
---|
| 4459 | + if (!access_ok(act, sizeof(*act)) || |
---|
4037 | 4460 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
---|
4038 | 4461 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) || |
---|
4039 | 4462 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || |
---|
.. | .. |
---|
4048 | 4471 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
---|
4049 | 4472 | |
---|
4050 | 4473 | if (!ret && oact) { |
---|
4051 | | - if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
---|
| 4474 | + if (!access_ok(oact, sizeof(*oact)) || |
---|
4052 | 4475 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
---|
4053 | 4476 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) || |
---|
4054 | 4477 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || |
---|
.. | .. |
---|
4070 | 4493 | compat_uptr_t handler, restorer; |
---|
4071 | 4494 | |
---|
4072 | 4495 | if (act) { |
---|
4073 | | - if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
---|
| 4496 | + if (!access_ok(act, sizeof(*act)) || |
---|
4074 | 4497 | __get_user(handler, &act->sa_handler) || |
---|
4075 | 4498 | __get_user(restorer, &act->sa_restorer) || |
---|
4076 | 4499 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || |
---|
.. | .. |
---|
4088 | 4511 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
---|
4089 | 4512 | |
---|
4090 | 4513 | if (!ret && oact) { |
---|
4091 | | - if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
---|
| 4514 | + if (!access_ok(oact, sizeof(*oact)) || |
---|
4092 | 4515 | __put_user(ptr_to_compat(old_ka.sa.sa_handler), |
---|
4093 | 4516 | &oact->sa_handler) || |
---|
4094 | 4517 | __put_user(ptr_to_compat(old_ka.sa.sa_restorer), |
---|
.. | .. |
---|
4225 | 4648 | return NULL; |
---|
4226 | 4649 | } |
---|
4227 | 4650 | |
---|
| 4651 | +static inline void siginfo_buildtime_checks(void) |
---|
| 4652 | +{ |
---|
| 4653 | + BUILD_BUG_ON(sizeof(struct siginfo) != SI_MAX_SIZE); |
---|
| 4654 | + |
---|
| 4655 | + /* Verify the offsets in the two siginfos match */ |
---|
| 4656 | +#define CHECK_OFFSET(field) \ |
---|
| 4657 | + BUILD_BUG_ON(offsetof(siginfo_t, field) != offsetof(kernel_siginfo_t, field)) |
---|
| 4658 | + |
---|
| 4659 | + /* kill */ |
---|
| 4660 | + CHECK_OFFSET(si_pid); |
---|
| 4661 | + CHECK_OFFSET(si_uid); |
---|
| 4662 | + |
---|
| 4663 | + /* timer */ |
---|
| 4664 | + CHECK_OFFSET(si_tid); |
---|
| 4665 | + CHECK_OFFSET(si_overrun); |
---|
| 4666 | + CHECK_OFFSET(si_value); |
---|
| 4667 | + |
---|
| 4668 | + /* rt */ |
---|
| 4669 | + CHECK_OFFSET(si_pid); |
---|
| 4670 | + CHECK_OFFSET(si_uid); |
---|
| 4671 | + CHECK_OFFSET(si_value); |
---|
| 4672 | + |
---|
| 4673 | + /* sigchld */ |
---|
| 4674 | + CHECK_OFFSET(si_pid); |
---|
| 4675 | + CHECK_OFFSET(si_uid); |
---|
| 4676 | + CHECK_OFFSET(si_status); |
---|
| 4677 | + CHECK_OFFSET(si_utime); |
---|
| 4678 | + CHECK_OFFSET(si_stime); |
---|
| 4679 | + |
---|
| 4680 | + /* sigfault */ |
---|
| 4681 | + CHECK_OFFSET(si_addr); |
---|
| 4682 | + CHECK_OFFSET(si_addr_lsb); |
---|
| 4683 | + CHECK_OFFSET(si_lower); |
---|
| 4684 | + CHECK_OFFSET(si_upper); |
---|
| 4685 | + CHECK_OFFSET(si_pkey); |
---|
| 4686 | + |
---|
| 4687 | + /* sigpoll */ |
---|
| 4688 | + CHECK_OFFSET(si_band); |
---|
| 4689 | + CHECK_OFFSET(si_fd); |
---|
| 4690 | + |
---|
| 4691 | + /* sigsys */ |
---|
| 4692 | + CHECK_OFFSET(si_call_addr); |
---|
| 4693 | + CHECK_OFFSET(si_syscall); |
---|
| 4694 | + CHECK_OFFSET(si_arch); |
---|
| 4695 | +#undef CHECK_OFFSET |
---|
| 4696 | + |
---|
| 4697 | + /* usb asyncio */ |
---|
| 4698 | + BUILD_BUG_ON(offsetof(struct siginfo, si_pid) != |
---|
| 4699 | + offsetof(struct siginfo, si_addr)); |
---|
| 4700 | + if (sizeof(int) == sizeof(void __user *)) { |
---|
| 4701 | + BUILD_BUG_ON(sizeof_field(struct siginfo, si_pid) != |
---|
| 4702 | + sizeof(void __user *)); |
---|
| 4703 | + } else { |
---|
| 4704 | + BUILD_BUG_ON((sizeof_field(struct siginfo, si_pid) + |
---|
| 4705 | + sizeof_field(struct siginfo, si_uid)) != |
---|
| 4706 | + sizeof(void __user *)); |
---|
| 4707 | + BUILD_BUG_ON(offsetofend(struct siginfo, si_pid) != |
---|
| 4708 | + offsetof(struct siginfo, si_uid)); |
---|
| 4709 | + } |
---|
| 4710 | +#ifdef CONFIG_COMPAT |
---|
| 4711 | + BUILD_BUG_ON(offsetof(struct compat_siginfo, si_pid) != |
---|
| 4712 | + offsetof(struct compat_siginfo, si_addr)); |
---|
| 4713 | + BUILD_BUG_ON(sizeof_field(struct compat_siginfo, si_pid) != |
---|
| 4714 | + sizeof(compat_uptr_t)); |
---|
| 4715 | + BUILD_BUG_ON(sizeof_field(struct compat_siginfo, si_pid) != |
---|
| 4716 | + sizeof_field(struct siginfo, si_pid)); |
---|
| 4717 | +#endif |
---|
| 4718 | +} |
---|
| 4719 | + |
---|
4228 | 4720 | void __init signals_init(void) |
---|
4229 | 4721 | { |
---|
4230 | | - /* If this check fails, the __ARCH_SI_PREAMBLE_SIZE value is wrong! */ |
---|
4231 | | - BUILD_BUG_ON(__ARCH_SI_PREAMBLE_SIZE |
---|
4232 | | - != offsetof(struct siginfo, _sifields._pad)); |
---|
4233 | | - BUILD_BUG_ON(sizeof(struct siginfo) != SI_MAX_SIZE); |
---|
| 4722 | + siginfo_buildtime_checks(); |
---|
4234 | 4723 | |
---|
4235 | 4724 | sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC); |
---|
4236 | 4725 | } |
---|