.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/kernel/signal.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
44 | 45 | #include <linux/posix-timers.h> |
---|
45 | 46 | #include <linux/livepatch.h> |
---|
46 | 47 | #include <linux/cgroup.h> |
---|
| 48 | +#include <linux/audit.h> |
---|
| 49 | +#include <linux/oom.h> |
---|
47 | 50 | |
---|
48 | 51 | #define CREATE_TRACE_POINTS |
---|
49 | 52 | #include <trace/events/signal.h> |
---|
.. | .. |
---|
53 | 56 | #include <asm/unistd.h> |
---|
54 | 57 | #include <asm/siginfo.h> |
---|
55 | 58 | #include <asm/cacheflush.h> |
---|
56 | | -#include "audit.h" /* audit_signal_info() */ |
---|
57 | 59 | |
---|
| 60 | +#undef CREATE_TRACE_POINTS |
---|
| 61 | +#include <trace/hooks/signal.h> |
---|
58 | 62 | /* |
---|
59 | 63 | * SLAB caches for signal bits. |
---|
60 | 64 | */ |
---|
.. | .. |
---|
185 | 189 | clear_thread_flag(TIF_SIGPENDING); |
---|
186 | 190 | |
---|
187 | 191 | } |
---|
| 192 | +EXPORT_SYMBOL(recalc_sigpending); |
---|
188 | 193 | |
---|
189 | 194 | void calculate_sigpending(void) |
---|
190 | 195 | { |
---|
.. | .. |
---|
352 | 357 | * @task has %JOBCTL_STOP_PENDING set and is participating in a group stop. |
---|
353 | 358 | * Group stop states are cleared and the group stop count is consumed if |
---|
354 | 359 | * %JOBCTL_STOP_CONSUME was set. If the consumption completes the group |
---|
355 | | - * stop, the appropriate %SIGNAL_* flags are set. |
---|
| 360 | + * stop, the appropriate `SIGNAL_*` flags are set. |
---|
356 | 361 | * |
---|
357 | 362 | * CONTEXT: |
---|
358 | 363 | * Must be called with @task->sighand->siglock held. |
---|
.. | .. |
---|
481 | 486 | flush_sigqueue(&t->signal->shared_pending); |
---|
482 | 487 | spin_unlock_irqrestore(&t->sighand->siglock, flags); |
---|
483 | 488 | } |
---|
| 489 | +EXPORT_SYMBOL(flush_signals); |
---|
484 | 490 | |
---|
485 | 491 | #ifdef CONFIG_POSIX_TIMERS |
---|
486 | 492 | static void __flush_itimer_signals(struct sigpending *pending) |
---|
.. | .. |
---|
562 | 568 | return !tsk->ptrace; |
---|
563 | 569 | } |
---|
564 | 570 | |
---|
565 | | -static void collect_signal(int sig, struct sigpending *list, siginfo_t *info, |
---|
| 571 | +static void collect_signal(int sig, struct sigpending *list, kernel_siginfo_t *info, |
---|
566 | 572 | bool *resched_timer) |
---|
567 | 573 | { |
---|
568 | 574 | struct sigqueue *q, *first = NULL; |
---|
.. | .. |
---|
608 | 614 | } |
---|
609 | 615 | |
---|
610 | 616 | static int __dequeue_signal(struct sigpending *pending, sigset_t *mask, |
---|
611 | | - siginfo_t *info, bool *resched_timer) |
---|
| 617 | + kernel_siginfo_t *info, bool *resched_timer) |
---|
612 | 618 | { |
---|
613 | 619 | int sig = next_signal(pending, mask); |
---|
614 | 620 | |
---|
.. | .. |
---|
623 | 629 | * |
---|
624 | 630 | * All callers have to hold the siglock. |
---|
625 | 631 | */ |
---|
626 | | -int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) |
---|
| 632 | +int dequeue_signal(struct task_struct *tsk, sigset_t *mask, kernel_siginfo_t *info) |
---|
627 | 633 | { |
---|
628 | 634 | bool resched_timer = false; |
---|
629 | 635 | int signr; |
---|
.. | .. |
---|
699 | 705 | #endif |
---|
700 | 706 | return signr; |
---|
701 | 707 | } |
---|
| 708 | +EXPORT_SYMBOL_GPL(dequeue_signal); |
---|
702 | 709 | |
---|
703 | | -static int dequeue_synchronous_signal(siginfo_t *info) |
---|
| 710 | +static int dequeue_synchronous_signal(kernel_siginfo_t *info) |
---|
704 | 711 | { |
---|
705 | 712 | struct task_struct *tsk = current; |
---|
706 | 713 | struct sigpending *pending = &tsk->pending; |
---|
.. | .. |
---|
716 | 723 | * Return the first synchronous signal in the queue. |
---|
717 | 724 | */ |
---|
718 | 725 | list_for_each_entry(q, &pending->list, list) { |
---|
719 | | - /* Synchronous signals have a postive si_code */ |
---|
| 726 | + /* Synchronous signals have a positive si_code */ |
---|
720 | 727 | if ((q->info.si_code > SI_USER) && |
---|
721 | 728 | (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) { |
---|
722 | 729 | sync = q; |
---|
.. | .. |
---|
791 | 798 | } |
---|
792 | 799 | } |
---|
793 | 800 | |
---|
794 | | -static inline int is_si_special(const struct siginfo *info) |
---|
| 801 | +static inline int is_si_special(const struct kernel_siginfo *info) |
---|
795 | 802 | { |
---|
796 | | - return info <= SEND_SIG_FORCED; |
---|
| 803 | + return info <= SEND_SIG_PRIV; |
---|
797 | 804 | } |
---|
798 | 805 | |
---|
799 | | -static inline bool si_fromuser(const struct siginfo *info) |
---|
| 806 | +static inline bool si_fromuser(const struct kernel_siginfo *info) |
---|
800 | 807 | { |
---|
801 | 808 | return info == SEND_SIG_NOINFO || |
---|
802 | 809 | (!is_si_special(info) && SI_FROMUSER(info)); |
---|
.. | .. |
---|
821 | 828 | * Bad permissions for sending the signal |
---|
822 | 829 | * - the caller must hold the RCU read lock |
---|
823 | 830 | */ |
---|
824 | | -static int check_kill_permission(int sig, struct siginfo *info, |
---|
| 831 | +static int check_kill_permission(int sig, struct kernel_siginfo *info, |
---|
825 | 832 | struct task_struct *t) |
---|
826 | 833 | { |
---|
827 | 834 | struct pid *sid; |
---|
.. | .. |
---|
848 | 855 | */ |
---|
849 | 856 | if (!sid || sid == task_session(current)) |
---|
850 | 857 | break; |
---|
| 858 | + fallthrough; |
---|
851 | 859 | default: |
---|
852 | 860 | return -EPERM; |
---|
853 | 861 | } |
---|
.. | .. |
---|
946 | 954 | /* |
---|
947 | 955 | * The first thread which returns from do_signal_stop() |
---|
948 | 956 | * will take ->siglock, notice SIGNAL_CLD_MASK, and |
---|
949 | | - * notify its parent. See get_signal_to_deliver(). |
---|
| 957 | + * notify its parent. See get_signal(). |
---|
950 | 958 | */ |
---|
951 | 959 | signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED); |
---|
952 | 960 | signal->group_stop_count = 0; |
---|
.. | .. |
---|
979 | 987 | if (task_is_stopped_or_traced(p)) |
---|
980 | 988 | return false; |
---|
981 | 989 | |
---|
982 | | - return task_curr(p) || !signal_pending(p); |
---|
| 990 | + return task_curr(p) || !task_sigpending(p); |
---|
983 | 991 | } |
---|
984 | 992 | |
---|
985 | 993 | static void complete_signal(int sig, struct task_struct *p, enum pid_type type) |
---|
.. | .. |
---|
1063 | 1071 | return (sig < SIGRTMIN) && sigismember(&signals->signal, sig); |
---|
1064 | 1072 | } |
---|
1065 | 1073 | |
---|
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) |
---|
| 1074 | +static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t, |
---|
| 1075 | + enum pid_type type, bool force) |
---|
1089 | 1076 | { |
---|
1090 | 1077 | struct sigpending *pending; |
---|
1091 | 1078 | struct sigqueue *q; |
---|
.. | .. |
---|
1095 | 1082 | assert_spin_locked(&t->sighand->siglock); |
---|
1096 | 1083 | |
---|
1097 | 1084 | result = TRACE_SIGNAL_IGNORED; |
---|
1098 | | - if (!prepare_signal(sig, t, |
---|
1099 | | - from_ancestor_ns || (info == SEND_SIG_PRIV) || (info == SEND_SIG_FORCED))) |
---|
| 1085 | + if (!prepare_signal(sig, t, force)) |
---|
1100 | 1086 | goto ret; |
---|
1101 | 1087 | |
---|
1102 | 1088 | pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; |
---|
.. | .. |
---|
1111 | 1097 | |
---|
1112 | 1098 | result = TRACE_SIGNAL_DELIVERED; |
---|
1113 | 1099 | /* |
---|
1114 | | - * fast-pathed signals for kernel-internal things like SIGSTOP |
---|
1115 | | - * or SIGKILL. |
---|
| 1100 | + * Skip useless siginfo allocation for SIGKILL and kernel threads. |
---|
1116 | 1101 | */ |
---|
1117 | | - if (info == SEND_SIG_FORCED) |
---|
| 1102 | + if ((sig == SIGKILL) || (t->flags & PF_KTHREAD)) |
---|
1118 | 1103 | goto out_set; |
---|
1119 | 1104 | |
---|
1120 | 1105 | /* |
---|
.. | .. |
---|
1142 | 1127 | q->info.si_code = SI_USER; |
---|
1143 | 1128 | q->info.si_pid = task_tgid_nr_ns(current, |
---|
1144 | 1129 | task_active_pid_ns(t)); |
---|
1145 | | - q->info.si_uid = from_kuid_munged(current_user_ns(), current_uid()); |
---|
| 1130 | + rcu_read_lock(); |
---|
| 1131 | + q->info.si_uid = |
---|
| 1132 | + from_kuid_munged(task_cred_xxx(t, user_ns), |
---|
| 1133 | + current_uid()); |
---|
| 1134 | + rcu_read_unlock(); |
---|
1146 | 1135 | break; |
---|
1147 | 1136 | case (unsigned long) SEND_SIG_PRIV: |
---|
1148 | 1137 | clear_siginfo(&q->info); |
---|
.. | .. |
---|
1154 | 1143 | break; |
---|
1155 | 1144 | default: |
---|
1156 | 1145 | copy_siginfo(&q->info, info); |
---|
1157 | | - if (from_ancestor_ns) |
---|
1158 | | - q->info.si_pid = 0; |
---|
1159 | 1146 | break; |
---|
1160 | 1147 | } |
---|
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 | | - } |
---|
| 1148 | + } else if (!is_si_special(info) && |
---|
| 1149 | + sig >= SIGRTMIN && info->si_code != SI_USER) { |
---|
| 1150 | + /* |
---|
| 1151 | + * Queue overflow, abort. We may abort if the |
---|
| 1152 | + * signal was rt and sent by user using something |
---|
| 1153 | + * other than kill(). |
---|
| 1154 | + */ |
---|
| 1155 | + result = TRACE_SIGNAL_OVERFLOW_FAIL; |
---|
| 1156 | + ret = -EAGAIN; |
---|
| 1157 | + goto ret; |
---|
| 1158 | + } else { |
---|
| 1159 | + /* |
---|
| 1160 | + * This is a silent loss of information. We still |
---|
| 1161 | + * send the signal, but the *info bits are lost. |
---|
| 1162 | + */ |
---|
| 1163 | + result = TRACE_SIGNAL_LOSE_INFO; |
---|
1181 | 1164 | } |
---|
1182 | 1165 | |
---|
1183 | 1166 | out_set: |
---|
.. | .. |
---|
1204 | 1187 | return ret; |
---|
1205 | 1188 | } |
---|
1206 | 1189 | |
---|
1207 | | -static int send_signal(int sig, struct siginfo *info, struct task_struct *t, |
---|
| 1190 | +static inline bool has_si_pid_and_uid(struct kernel_siginfo *info) |
---|
| 1191 | +{ |
---|
| 1192 | + bool ret = false; |
---|
| 1193 | + switch (siginfo_layout(info->si_signo, info->si_code)) { |
---|
| 1194 | + case SIL_KILL: |
---|
| 1195 | + case SIL_CHLD: |
---|
| 1196 | + case SIL_RT: |
---|
| 1197 | + ret = true; |
---|
| 1198 | + break; |
---|
| 1199 | + case SIL_TIMER: |
---|
| 1200 | + case SIL_POLL: |
---|
| 1201 | + case SIL_FAULT: |
---|
| 1202 | + case SIL_FAULT_MCEERR: |
---|
| 1203 | + case SIL_FAULT_BNDERR: |
---|
| 1204 | + case SIL_FAULT_PKUERR: |
---|
| 1205 | + case SIL_SYS: |
---|
| 1206 | + ret = false; |
---|
| 1207 | + break; |
---|
| 1208 | + } |
---|
| 1209 | + return ret; |
---|
| 1210 | +} |
---|
| 1211 | + |
---|
| 1212 | +static int send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t, |
---|
1208 | 1213 | enum pid_type type) |
---|
1209 | 1214 | { |
---|
1210 | | - int from_ancestor_ns = 0; |
---|
| 1215 | + /* Should SIGKILL or SIGSTOP be received by a pid namespace init? */ |
---|
| 1216 | + bool force = false; |
---|
1211 | 1217 | |
---|
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 |
---|
| 1218 | + if (info == SEND_SIG_NOINFO) { |
---|
| 1219 | + /* Force if sent from an ancestor pid namespace */ |
---|
| 1220 | + force = !task_pid_nr_ns(current, task_active_pid_ns(t)); |
---|
| 1221 | + } else if (info == SEND_SIG_PRIV) { |
---|
| 1222 | + /* Don't ignore kernel generated signals */ |
---|
| 1223 | + force = true; |
---|
| 1224 | + } else if (has_si_pid_and_uid(info)) { |
---|
| 1225 | + /* SIGKILL and SIGSTOP is special or has ids */ |
---|
| 1226 | + struct user_namespace *t_user_ns; |
---|
1216 | 1227 | |
---|
1217 | | - return __send_signal(sig, info, t, type, from_ancestor_ns); |
---|
| 1228 | + rcu_read_lock(); |
---|
| 1229 | + t_user_ns = task_cred_xxx(t, user_ns); |
---|
| 1230 | + if (current_user_ns() != t_user_ns) { |
---|
| 1231 | + kuid_t uid = make_kuid(current_user_ns(), info->si_uid); |
---|
| 1232 | + info->si_uid = from_kuid_munged(t_user_ns, uid); |
---|
| 1233 | + } |
---|
| 1234 | + rcu_read_unlock(); |
---|
| 1235 | + |
---|
| 1236 | + /* A kernel generated signal? */ |
---|
| 1237 | + force = (info->si_code == SI_KERNEL); |
---|
| 1238 | + |
---|
| 1239 | + /* From an ancestor pid namespace? */ |
---|
| 1240 | + if (!task_pid_nr_ns(current, task_active_pid_ns(t))) { |
---|
| 1241 | + info->si_pid = 0; |
---|
| 1242 | + force = true; |
---|
| 1243 | + } |
---|
| 1244 | + } |
---|
| 1245 | + return __send_signal(sig, info, t, type, force); |
---|
1218 | 1246 | } |
---|
1219 | 1247 | |
---|
1220 | 1248 | static void print_fatal_signal(int signr) |
---|
.. | .. |
---|
1251 | 1279 | __setup("print-fatal-signals=", setup_print_fatal_signals); |
---|
1252 | 1280 | |
---|
1253 | 1281 | int |
---|
1254 | | -__group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
---|
| 1282 | +__group_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p) |
---|
1255 | 1283 | { |
---|
1256 | 1284 | return send_signal(sig, info, p, PIDTYPE_TGID); |
---|
1257 | 1285 | } |
---|
1258 | 1286 | |
---|
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, |
---|
| 1287 | +int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p, |
---|
1266 | 1288 | enum pid_type type) |
---|
1267 | 1289 | { |
---|
1268 | 1290 | unsigned long flags; |
---|
1269 | 1291 | int ret = -ESRCH; |
---|
1270 | | - |
---|
| 1292 | + trace_android_vh_do_send_sig_info(sig, current, p); |
---|
1271 | 1293 | if (lock_task_sighand(p, &flags)) { |
---|
1272 | 1294 | ret = send_signal(sig, info, p, type); |
---|
1273 | 1295 | unlock_task_sighand(p, &flags); |
---|
.. | .. |
---|
1287 | 1309 | * We don't want to have recursive SIGSEGV's etc, for example, |
---|
1288 | 1310 | * that is why we also clear SIGNAL_UNKILLABLE. |
---|
1289 | 1311 | */ |
---|
1290 | | -int |
---|
1291 | | -force_sig_info(int sig, struct siginfo *info, struct task_struct *t) |
---|
| 1312 | +static int |
---|
| 1313 | +force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t) |
---|
1292 | 1314 | { |
---|
1293 | 1315 | unsigned long int flags; |
---|
1294 | 1316 | int ret, blocked, ignored; |
---|
1295 | 1317 | struct k_sigaction *action; |
---|
| 1318 | + int sig = info->si_signo; |
---|
1296 | 1319 | |
---|
1297 | 1320 | spin_lock_irqsave(&t->sighand->siglock, flags); |
---|
1298 | 1321 | action = &t->sighand->action[sig-1]; |
---|
.. | .. |
---|
1311 | 1334 | */ |
---|
1312 | 1335 | if (action->sa.sa_handler == SIG_DFL && !t->ptrace) |
---|
1313 | 1336 | t->signal->flags &= ~SIGNAL_UNKILLABLE; |
---|
1314 | | - ret = specific_send_sig_info(sig, info, t); |
---|
| 1337 | + ret = send_signal(sig, info, t, PIDTYPE_PID); |
---|
1315 | 1338 | spin_unlock_irqrestore(&t->sighand->siglock, flags); |
---|
1316 | 1339 | |
---|
1317 | 1340 | return ret; |
---|
| 1341 | +} |
---|
| 1342 | + |
---|
| 1343 | +int force_sig_info(struct kernel_siginfo *info) |
---|
| 1344 | +{ |
---|
| 1345 | + return force_sig_info_to_task(info, current); |
---|
1318 | 1346 | } |
---|
1319 | 1347 | |
---|
1320 | 1348 | /* |
---|
.. | .. |
---|
1364 | 1392 | * must see ->sighand == NULL. |
---|
1365 | 1393 | */ |
---|
1366 | 1394 | spin_lock_irqsave(&sighand->siglock, *flags); |
---|
1367 | | - if (likely(sighand == tsk->sighand)) |
---|
| 1395 | + if (likely(sighand == rcu_access_pointer(tsk->sighand))) |
---|
1368 | 1396 | break; |
---|
1369 | 1397 | spin_unlock_irqrestore(&sighand->siglock, *flags); |
---|
1370 | 1398 | } |
---|
.. | .. |
---|
1376 | 1404 | /* |
---|
1377 | 1405 | * send signal info to all the members of a group |
---|
1378 | 1406 | */ |
---|
1379 | | -int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p, |
---|
1380 | | - enum pid_type type) |
---|
| 1407 | +int group_send_sig_info(int sig, struct kernel_siginfo *info, |
---|
| 1408 | + struct task_struct *p, enum pid_type type) |
---|
1381 | 1409 | { |
---|
1382 | 1410 | int ret; |
---|
1383 | 1411 | |
---|
.. | .. |
---|
1385 | 1413 | ret = check_kill_permission(sig, info, p); |
---|
1386 | 1414 | rcu_read_unlock(); |
---|
1387 | 1415 | |
---|
1388 | | - if (!ret && sig) |
---|
| 1416 | + if (!ret && sig) { |
---|
1389 | 1417 | ret = do_send_sig_info(sig, info, p, type); |
---|
| 1418 | + if (!ret && sig == SIGKILL) { |
---|
| 1419 | + bool reap = false; |
---|
| 1420 | + |
---|
| 1421 | + trace_android_vh_process_killed(current, &reap); |
---|
| 1422 | + trace_android_vh_killed_process(current, p, &reap); |
---|
| 1423 | + if (reap) |
---|
| 1424 | + add_to_oom_reaper(p); |
---|
| 1425 | + } |
---|
| 1426 | + } |
---|
1390 | 1427 | |
---|
1391 | 1428 | return ret; |
---|
1392 | 1429 | } |
---|
.. | .. |
---|
1396 | 1433 | * control characters do (^C, ^Z etc) |
---|
1397 | 1434 | * - the caller must hold at least a readlock on tasklist_lock |
---|
1398 | 1435 | */ |
---|
1399 | | -int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp) |
---|
| 1436 | +int __kill_pgrp_info(int sig, struct kernel_siginfo *info, struct pid *pgrp) |
---|
1400 | 1437 | { |
---|
1401 | 1438 | struct task_struct *p = NULL; |
---|
1402 | 1439 | int retval, success; |
---|
.. | .. |
---|
1411 | 1448 | return success ? 0 : retval; |
---|
1412 | 1449 | } |
---|
1413 | 1450 | |
---|
1414 | | -int kill_pid_info(int sig, struct siginfo *info, struct pid *pid) |
---|
| 1451 | +int kill_pid_info(int sig, struct kernel_siginfo *info, struct pid *pid) |
---|
1415 | 1452 | { |
---|
1416 | 1453 | int error = -ESRCH; |
---|
1417 | 1454 | struct task_struct *p; |
---|
.. | .. |
---|
1433 | 1470 | } |
---|
1434 | 1471 | } |
---|
1435 | 1472 | |
---|
1436 | | -static int kill_proc_info(int sig, struct siginfo *info, pid_t pid) |
---|
| 1473 | +static int kill_proc_info(int sig, struct kernel_siginfo *info, pid_t pid) |
---|
1437 | 1474 | { |
---|
1438 | 1475 | int error; |
---|
1439 | 1476 | rcu_read_lock(); |
---|
.. | .. |
---|
1453 | 1490 | uid_eq(cred->uid, pcred->uid); |
---|
1454 | 1491 | } |
---|
1455 | 1492 | |
---|
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) |
---|
| 1493 | +/* |
---|
| 1494 | + * The usb asyncio usage of siginfo is wrong. The glibc support |
---|
| 1495 | + * for asyncio which uses SI_ASYNCIO assumes the layout is SIL_RT. |
---|
| 1496 | + * AKA after the generic fields: |
---|
| 1497 | + * kernel_pid_t si_pid; |
---|
| 1498 | + * kernel_uid32_t si_uid; |
---|
| 1499 | + * sigval_t si_value; |
---|
| 1500 | + * |
---|
| 1501 | + * Unfortunately when usb generates SI_ASYNCIO it assumes the layout |
---|
| 1502 | + * after the generic fields is: |
---|
| 1503 | + * void __user *si_addr; |
---|
| 1504 | + * |
---|
| 1505 | + * This is a practical problem when there is a 64bit big endian kernel |
---|
| 1506 | + * and a 32bit userspace. As the 32bit address will encoded in the low |
---|
| 1507 | + * 32bits of the pointer. Those low 32bits will be stored at higher |
---|
| 1508 | + * address than appear in a 32 bit pointer. So userspace will not |
---|
| 1509 | + * see the address it was expecting for it's completions. |
---|
| 1510 | + * |
---|
| 1511 | + * There is nothing in the encoding that can allow |
---|
| 1512 | + * copy_siginfo_to_user32 to detect this confusion of formats, so |
---|
| 1513 | + * handle this by requiring the caller of kill_pid_usb_asyncio to |
---|
| 1514 | + * notice when this situration takes place and to store the 32bit |
---|
| 1515 | + * pointer in sival_int, instead of sival_addr of the sigval_t addr |
---|
| 1516 | + * parameter. |
---|
| 1517 | + */ |
---|
| 1518 | +int kill_pid_usb_asyncio(int sig, int errno, sigval_t addr, |
---|
| 1519 | + struct pid *pid, const struct cred *cred) |
---|
1459 | 1520 | { |
---|
1460 | | - int ret = -EINVAL; |
---|
| 1521 | + struct kernel_siginfo info; |
---|
1461 | 1522 | struct task_struct *p; |
---|
1462 | 1523 | unsigned long flags; |
---|
| 1524 | + int ret = -EINVAL; |
---|
1463 | 1525 | |
---|
1464 | 1526 | if (!valid_signal(sig)) |
---|
1465 | 1527 | return ret; |
---|
| 1528 | + |
---|
| 1529 | + clear_siginfo(&info); |
---|
| 1530 | + info.si_signo = sig; |
---|
| 1531 | + info.si_errno = errno; |
---|
| 1532 | + info.si_code = SI_ASYNCIO; |
---|
| 1533 | + *((sigval_t *)&info.si_pid) = addr; |
---|
1466 | 1534 | |
---|
1467 | 1535 | rcu_read_lock(); |
---|
1468 | 1536 | p = pid_task(pid, PIDTYPE_PID); |
---|
.. | .. |
---|
1470 | 1538 | ret = -ESRCH; |
---|
1471 | 1539 | goto out_unlock; |
---|
1472 | 1540 | } |
---|
1473 | | - if (si_fromuser(info) && !kill_as_cred_perm(cred, p)) { |
---|
| 1541 | + if (!kill_as_cred_perm(cred, p)) { |
---|
1474 | 1542 | ret = -EPERM; |
---|
1475 | 1543 | goto out_unlock; |
---|
1476 | 1544 | } |
---|
1477 | | - ret = security_task_kill(p, info, sig, cred); |
---|
| 1545 | + ret = security_task_kill(p, &info, sig, cred); |
---|
1478 | 1546 | if (ret) |
---|
1479 | 1547 | goto out_unlock; |
---|
1480 | 1548 | |
---|
1481 | 1549 | if (sig) { |
---|
1482 | 1550 | if (lock_task_sighand(p, &flags)) { |
---|
1483 | | - ret = __send_signal(sig, info, p, PIDTYPE_TGID, 0); |
---|
| 1551 | + ret = __send_signal(sig, &info, p, PIDTYPE_TGID, false); |
---|
1484 | 1552 | unlock_task_sighand(p, &flags); |
---|
1485 | 1553 | } else |
---|
1486 | 1554 | ret = -ESRCH; |
---|
.. | .. |
---|
1489 | 1557 | rcu_read_unlock(); |
---|
1490 | 1558 | return ret; |
---|
1491 | 1559 | } |
---|
1492 | | -EXPORT_SYMBOL_GPL(kill_pid_info_as_cred); |
---|
| 1560 | +EXPORT_SYMBOL_GPL(kill_pid_usb_asyncio); |
---|
1493 | 1561 | |
---|
1494 | 1562 | /* |
---|
1495 | 1563 | * kill_something_info() interprets pid in interesting ways just like kill(2). |
---|
.. | .. |
---|
1498 | 1566 | * is probably wrong. Should make it like BSD or SYSV. |
---|
1499 | 1567 | */ |
---|
1500 | 1568 | |
---|
1501 | | -static int kill_something_info(int sig, struct siginfo *info, pid_t pid) |
---|
| 1569 | +static int kill_something_info(int sig, struct kernel_siginfo *info, pid_t pid) |
---|
1502 | 1570 | { |
---|
1503 | 1571 | int ret; |
---|
1504 | 1572 | |
---|
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 | | - } |
---|
| 1573 | + if (pid > 0) |
---|
| 1574 | + return kill_proc_info(sig, info, pid); |
---|
1511 | 1575 | |
---|
1512 | 1576 | /* -INT_MIN is undefined. Exclude this case to avoid a UBSAN warning */ |
---|
1513 | 1577 | if (pid == INT_MIN) |
---|
.. | .. |
---|
1542 | 1606 | * These are for backward compatibility with the rest of the kernel source. |
---|
1543 | 1607 | */ |
---|
1544 | 1608 | |
---|
1545 | | -int send_sig_info(int sig, struct siginfo *info, struct task_struct *p) |
---|
| 1609 | +int send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p) |
---|
1546 | 1610 | { |
---|
1547 | 1611 | /* |
---|
1548 | 1612 | * Make sure legacy kernel users don't send in bad values |
---|
.. | .. |
---|
1553 | 1617 | |
---|
1554 | 1618 | return do_send_sig_info(sig, info, p, PIDTYPE_PID); |
---|
1555 | 1619 | } |
---|
| 1620 | +EXPORT_SYMBOL(send_sig_info); |
---|
1556 | 1621 | |
---|
1557 | 1622 | #define __si_special(priv) \ |
---|
1558 | 1623 | ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO) |
---|
.. | .. |
---|
1562 | 1627 | { |
---|
1563 | 1628 | return send_sig_info(sig, __si_special(priv), p); |
---|
1564 | 1629 | } |
---|
| 1630 | +EXPORT_SYMBOL(send_sig); |
---|
1565 | 1631 | |
---|
1566 | | -void force_sig(int sig, struct task_struct *p) |
---|
| 1632 | +void force_sig(int sig) |
---|
1567 | 1633 | { |
---|
1568 | | - force_sig_info(sig, SEND_SIG_PRIV, p); |
---|
| 1634 | + struct kernel_siginfo info; |
---|
| 1635 | + |
---|
| 1636 | + clear_siginfo(&info); |
---|
| 1637 | + info.si_signo = sig; |
---|
| 1638 | + info.si_errno = 0; |
---|
| 1639 | + info.si_code = SI_KERNEL; |
---|
| 1640 | + info.si_pid = 0; |
---|
| 1641 | + info.si_uid = 0; |
---|
| 1642 | + force_sig_info(&info); |
---|
1569 | 1643 | } |
---|
| 1644 | +EXPORT_SYMBOL(force_sig); |
---|
1570 | 1645 | |
---|
1571 | 1646 | /* |
---|
1572 | 1647 | * When things go south during signal handling, we |
---|
.. | .. |
---|
1574 | 1649 | * the problem was already a SIGSEGV, we'll want to |
---|
1575 | 1650 | * make sure we don't even try to deliver the signal.. |
---|
1576 | 1651 | */ |
---|
1577 | | -void force_sigsegv(int sig, struct task_struct *p) |
---|
| 1652 | +void force_sigsegv(int sig) |
---|
1578 | 1653 | { |
---|
| 1654 | + struct task_struct *p = current; |
---|
| 1655 | + |
---|
1579 | 1656 | if (sig == SIGSEGV) { |
---|
1580 | 1657 | unsigned long flags; |
---|
1581 | 1658 | spin_lock_irqsave(&p->sighand->siglock, flags); |
---|
1582 | 1659 | p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL; |
---|
1583 | 1660 | spin_unlock_irqrestore(&p->sighand->siglock, flags); |
---|
1584 | 1661 | } |
---|
1585 | | - force_sig(SIGSEGV, p); |
---|
| 1662 | + force_sig(SIGSEGV); |
---|
1586 | 1663 | } |
---|
1587 | 1664 | |
---|
1588 | | -int force_sig_fault(int sig, int code, void __user *addr |
---|
| 1665 | +int force_sig_fault_to_task(int sig, int code, void __user *addr |
---|
1589 | 1666 | ___ARCH_SI_TRAPNO(int trapno) |
---|
1590 | 1667 | ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr) |
---|
1591 | 1668 | , struct task_struct *t) |
---|
1592 | 1669 | { |
---|
1593 | | - struct siginfo info; |
---|
| 1670 | + struct kernel_siginfo info; |
---|
1594 | 1671 | |
---|
1595 | 1672 | clear_siginfo(&info); |
---|
1596 | 1673 | info.si_signo = sig; |
---|
.. | .. |
---|
1605 | 1682 | info.si_flags = flags; |
---|
1606 | 1683 | info.si_isr = isr; |
---|
1607 | 1684 | #endif |
---|
1608 | | - return force_sig_info(info.si_signo, &info, t); |
---|
| 1685 | + return force_sig_info_to_task(&info, t); |
---|
| 1686 | +} |
---|
| 1687 | + |
---|
| 1688 | +int force_sig_fault(int sig, int code, void __user *addr |
---|
| 1689 | + ___ARCH_SI_TRAPNO(int trapno) |
---|
| 1690 | + ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)) |
---|
| 1691 | +{ |
---|
| 1692 | + return force_sig_fault_to_task(sig, code, addr |
---|
| 1693 | + ___ARCH_SI_TRAPNO(trapno) |
---|
| 1694 | + ___ARCH_SI_IA64(imm, flags, isr), current); |
---|
1609 | 1695 | } |
---|
1610 | 1696 | |
---|
1611 | 1697 | int send_sig_fault(int sig, int code, void __user *addr |
---|
.. | .. |
---|
1613 | 1699 | ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr) |
---|
1614 | 1700 | , struct task_struct *t) |
---|
1615 | 1701 | { |
---|
1616 | | - struct siginfo info; |
---|
| 1702 | + struct kernel_siginfo info; |
---|
1617 | 1703 | |
---|
1618 | 1704 | clear_siginfo(&info); |
---|
1619 | 1705 | info.si_signo = sig; |
---|
.. | .. |
---|
1631 | 1717 | return send_sig_info(info.si_signo, &info, t); |
---|
1632 | 1718 | } |
---|
1633 | 1719 | |
---|
1634 | | -int force_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t) |
---|
| 1720 | +int force_sig_mceerr(int code, void __user *addr, short lsb) |
---|
1635 | 1721 | { |
---|
1636 | | - struct siginfo info; |
---|
| 1722 | + struct kernel_siginfo info; |
---|
1637 | 1723 | |
---|
1638 | 1724 | WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR)); |
---|
1639 | 1725 | clear_siginfo(&info); |
---|
.. | .. |
---|
1642 | 1728 | info.si_code = code; |
---|
1643 | 1729 | info.si_addr = addr; |
---|
1644 | 1730 | info.si_addr_lsb = lsb; |
---|
1645 | | - return force_sig_info(info.si_signo, &info, t); |
---|
| 1731 | + return force_sig_info(&info); |
---|
1646 | 1732 | } |
---|
1647 | 1733 | |
---|
1648 | 1734 | int send_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t) |
---|
1649 | 1735 | { |
---|
1650 | | - struct siginfo info; |
---|
| 1736 | + struct kernel_siginfo info; |
---|
1651 | 1737 | |
---|
1652 | 1738 | WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR)); |
---|
1653 | 1739 | clear_siginfo(&info); |
---|
.. | .. |
---|
1662 | 1748 | |
---|
1663 | 1749 | int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper) |
---|
1664 | 1750 | { |
---|
1665 | | - struct siginfo info; |
---|
| 1751 | + struct kernel_siginfo info; |
---|
1666 | 1752 | |
---|
1667 | 1753 | clear_siginfo(&info); |
---|
1668 | 1754 | info.si_signo = SIGSEGV; |
---|
.. | .. |
---|
1671 | 1757 | info.si_addr = addr; |
---|
1672 | 1758 | info.si_lower = lower; |
---|
1673 | 1759 | info.si_upper = upper; |
---|
1674 | | - return force_sig_info(info.si_signo, &info, current); |
---|
| 1760 | + return force_sig_info(&info); |
---|
1675 | 1761 | } |
---|
1676 | 1762 | |
---|
1677 | 1763 | #ifdef SEGV_PKUERR |
---|
1678 | 1764 | int force_sig_pkuerr(void __user *addr, u32 pkey) |
---|
1679 | 1765 | { |
---|
1680 | | - struct siginfo info; |
---|
| 1766 | + struct kernel_siginfo info; |
---|
1681 | 1767 | |
---|
1682 | 1768 | clear_siginfo(&info); |
---|
1683 | 1769 | info.si_signo = SIGSEGV; |
---|
.. | .. |
---|
1685 | 1771 | info.si_code = SEGV_PKUERR; |
---|
1686 | 1772 | info.si_addr = addr; |
---|
1687 | 1773 | info.si_pkey = pkey; |
---|
1688 | | - return force_sig_info(info.si_signo, &info, current); |
---|
| 1774 | + return force_sig_info(&info); |
---|
1689 | 1775 | } |
---|
1690 | 1776 | #endif |
---|
1691 | 1777 | |
---|
.. | .. |
---|
1694 | 1780 | */ |
---|
1695 | 1781 | int force_sig_ptrace_errno_trap(int errno, void __user *addr) |
---|
1696 | 1782 | { |
---|
1697 | | - struct siginfo info; |
---|
| 1783 | + struct kernel_siginfo info; |
---|
1698 | 1784 | |
---|
1699 | 1785 | clear_siginfo(&info); |
---|
1700 | 1786 | info.si_signo = SIGTRAP; |
---|
1701 | 1787 | info.si_errno = errno; |
---|
1702 | 1788 | info.si_code = TRAP_HWBKPT; |
---|
1703 | 1789 | info.si_addr = addr; |
---|
1704 | | - return force_sig_info(info.si_signo, &info, current); |
---|
| 1790 | + return force_sig_info(&info); |
---|
1705 | 1791 | } |
---|
1706 | 1792 | |
---|
1707 | 1793 | int kill_pgrp(struct pid *pid, int sig, int priv) |
---|
.. | .. |
---|
1818 | 1904 | { |
---|
1819 | 1905 | struct pid *pid; |
---|
1820 | 1906 | |
---|
| 1907 | + WARN_ON(task->exit_state == 0); |
---|
1821 | 1908 | pid = task_pid(task); |
---|
1822 | 1909 | wake_up_all(&pid->wait_pidfd); |
---|
1823 | 1910 | } |
---|
.. | .. |
---|
1831 | 1918 | */ |
---|
1832 | 1919 | bool do_notify_parent(struct task_struct *tsk, int sig) |
---|
1833 | 1920 | { |
---|
1834 | | - struct siginfo info; |
---|
| 1921 | + struct kernel_siginfo info; |
---|
1835 | 1922 | unsigned long flags; |
---|
1836 | 1923 | struct sighand_struct *psig; |
---|
1837 | 1924 | bool autoreap = false; |
---|
1838 | 1925 | u64 utime, stime; |
---|
1839 | 1926 | |
---|
1840 | | - BUG_ON(sig == -1); |
---|
| 1927 | + WARN_ON_ONCE(sig == -1); |
---|
1841 | 1928 | |
---|
1842 | | - /* do_notify_parent_cldstop should have been called instead. */ |
---|
1843 | | - BUG_ON(task_is_stopped_or_traced(tsk)); |
---|
| 1929 | + /* do_notify_parent_cldstop should have been called instead. */ |
---|
| 1930 | + WARN_ON_ONCE(task_is_stopped_or_traced(tsk)); |
---|
1844 | 1931 | |
---|
1845 | | - BUG_ON(!tsk->ptrace && |
---|
| 1932 | + WARN_ON_ONCE(!tsk->ptrace && |
---|
1846 | 1933 | (tsk->group_leader != tsk || !thread_group_empty(tsk))); |
---|
1847 | 1934 | |
---|
1848 | 1935 | /* Wake up all pidfd waiters */ |
---|
.. | .. |
---|
1915 | 2002 | if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) |
---|
1916 | 2003 | sig = 0; |
---|
1917 | 2004 | } |
---|
| 2005 | + /* |
---|
| 2006 | + * Send with __send_signal as si_pid and si_uid are in the |
---|
| 2007 | + * parent's namespaces. |
---|
| 2008 | + */ |
---|
1918 | 2009 | if (valid_signal(sig) && sig) |
---|
1919 | | - __group_send_sig_info(sig, &info, tsk->parent); |
---|
| 2010 | + __send_signal(sig, &info, tsk->parent, PIDTYPE_TGID, false); |
---|
1920 | 2011 | __wake_up_parent(tsk, tsk->parent); |
---|
1921 | 2012 | spin_unlock_irqrestore(&psig->siglock, flags); |
---|
1922 | 2013 | |
---|
.. | .. |
---|
1939 | 2030 | static void do_notify_parent_cldstop(struct task_struct *tsk, |
---|
1940 | 2031 | bool for_ptracer, int why) |
---|
1941 | 2032 | { |
---|
1942 | | - struct siginfo info; |
---|
| 2033 | + struct kernel_siginfo info; |
---|
1943 | 2034 | unsigned long flags; |
---|
1944 | 2035 | struct task_struct *parent; |
---|
1945 | 2036 | struct sighand_struct *sighand; |
---|
.. | .. |
---|
2030 | 2121 | * If we actually decide not to stop at all because the tracer |
---|
2031 | 2122 | * is gone, we keep current->exit_code unless clear_code. |
---|
2032 | 2123 | */ |
---|
2033 | | -static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info) |
---|
| 2124 | +static void ptrace_stop(int exit_code, int why, int clear_code, kernel_siginfo_t *info) |
---|
2034 | 2125 | __releases(¤t->sighand->siglock) |
---|
2035 | 2126 | __acquires(¤t->sighand->siglock) |
---|
2036 | 2127 | { |
---|
.. | .. |
---|
2168 | 2259 | |
---|
2169 | 2260 | static void ptrace_do_notify(int signr, int exit_code, int why) |
---|
2170 | 2261 | { |
---|
2171 | | - siginfo_t info; |
---|
| 2262 | + kernel_siginfo_t info; |
---|
2172 | 2263 | |
---|
2173 | 2264 | clear_siginfo(&info); |
---|
2174 | 2265 | info.si_signo = signr; |
---|
.. | .. |
---|
2387 | 2478 | freezable_schedule(); |
---|
2388 | 2479 | } |
---|
2389 | 2480 | |
---|
2390 | | -static int ptrace_signal(int signr, siginfo_t *info) |
---|
| 2481 | +static int ptrace_signal(int signr, kernel_siginfo_t *info) |
---|
2391 | 2482 | { |
---|
2392 | 2483 | /* |
---|
2393 | 2484 | * We do not check sig_kernel_stop(signr) but set this marker |
---|
.. | .. |
---|
2428 | 2519 | |
---|
2429 | 2520 | /* If the (new) signal is now blocked, requeue it. */ |
---|
2430 | 2521 | if (sigismember(¤t->blocked, signr)) { |
---|
2431 | | - specific_send_sig_info(signr, info, current); |
---|
| 2522 | + send_signal(signr, info, current, PIDTYPE_PID); |
---|
2432 | 2523 | signr = 0; |
---|
2433 | 2524 | } |
---|
2434 | 2525 | |
---|
2435 | 2526 | return signr; |
---|
| 2527 | +} |
---|
| 2528 | + |
---|
| 2529 | +static void hide_si_addr_tag_bits(struct ksignal *ksig) |
---|
| 2530 | +{ |
---|
| 2531 | + switch (siginfo_layout(ksig->sig, ksig->info.si_code)) { |
---|
| 2532 | + case SIL_FAULT: |
---|
| 2533 | + case SIL_FAULT_MCEERR: |
---|
| 2534 | + case SIL_FAULT_BNDERR: |
---|
| 2535 | + case SIL_FAULT_PKUERR: |
---|
| 2536 | + ksig->info.si_addr = arch_untagged_si_addr( |
---|
| 2537 | + ksig->info.si_addr, ksig->sig, ksig->info.si_code); |
---|
| 2538 | + break; |
---|
| 2539 | + case SIL_KILL: |
---|
| 2540 | + case SIL_TIMER: |
---|
| 2541 | + case SIL_POLL: |
---|
| 2542 | + case SIL_CHLD: |
---|
| 2543 | + case SIL_RT: |
---|
| 2544 | + case SIL_SYS: |
---|
| 2545 | + break; |
---|
| 2546 | + } |
---|
2436 | 2547 | } |
---|
2437 | 2548 | |
---|
2438 | 2549 | bool get_signal(struct ksignal *ksig) |
---|
.. | .. |
---|
2443 | 2554 | |
---|
2444 | 2555 | if (unlikely(current->task_works)) |
---|
2445 | 2556 | task_work_run(); |
---|
| 2557 | + |
---|
| 2558 | + /* |
---|
| 2559 | + * For non-generic architectures, check for TIF_NOTIFY_SIGNAL so |
---|
| 2560 | + * that the arch handlers don't all have to do it. If we get here |
---|
| 2561 | + * without TIF_SIGPENDING, just exit after running signal work. |
---|
| 2562 | + */ |
---|
| 2563 | + if (!IS_ENABLED(CONFIG_GENERIC_ENTRY)) { |
---|
| 2564 | + if (test_thread_flag(TIF_NOTIFY_SIGNAL)) |
---|
| 2565 | + tracehook_notify_signal(); |
---|
| 2566 | + if (!task_sigpending(current)) |
---|
| 2567 | + return false; |
---|
| 2568 | + } |
---|
2446 | 2569 | |
---|
2447 | 2570 | if (unlikely(uprobe_deny_signal())) |
---|
2448 | 2571 | return false; |
---|
.. | .. |
---|
2456 | 2579 | |
---|
2457 | 2580 | relock: |
---|
2458 | 2581 | spin_lock_irq(&sighand->siglock); |
---|
| 2582 | + |
---|
2459 | 2583 | /* |
---|
2460 | 2584 | * Every stopped thread goes here after wakeup. Check to see if |
---|
2461 | 2585 | * we should notify the parent, prepare_signal(SIGCONT) encodes |
---|
.. | .. |
---|
2499 | 2623 | trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO, |
---|
2500 | 2624 | &sighand->action[SIGKILL - 1]); |
---|
2501 | 2625 | 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 | 2626 | goto fatal; |
---|
2507 | 2627 | } |
---|
2508 | 2628 | |
---|
.. | .. |
---|
2530 | 2650 | */ |
---|
2531 | 2651 | if (unlikely(cgroup_task_frozen(current))) { |
---|
2532 | 2652 | spin_unlock_irq(&sighand->siglock); |
---|
2533 | | - cgroup_leave_frozen(true); |
---|
| 2653 | + cgroup_leave_frozen(false); |
---|
2534 | 2654 | goto relock; |
---|
2535 | 2655 | } |
---|
2536 | 2656 | |
---|
.. | .. |
---|
2624 | 2744 | continue; |
---|
2625 | 2745 | } |
---|
2626 | 2746 | |
---|
2627 | | - spin_unlock_irq(&sighand->siglock); |
---|
2628 | 2747 | fatal: |
---|
| 2748 | + spin_unlock_irq(&sighand->siglock); |
---|
| 2749 | + if (unlikely(cgroup_task_frozen(current))) |
---|
| 2750 | + cgroup_leave_frozen(true); |
---|
2629 | 2751 | |
---|
2630 | 2752 | /* |
---|
2631 | 2753 | * Anything else is fatal, maybe with a core dump. |
---|
.. | .. |
---|
2648 | 2770 | } |
---|
2649 | 2771 | |
---|
2650 | 2772 | /* |
---|
| 2773 | + * PF_IO_WORKER threads will catch and exit on fatal signals |
---|
| 2774 | + * themselves. They have cleanup that must be performed, so |
---|
| 2775 | + * we cannot call do_exit() on their behalf. |
---|
| 2776 | + */ |
---|
| 2777 | + if (current->flags & PF_IO_WORKER) |
---|
| 2778 | + goto out; |
---|
| 2779 | + |
---|
| 2780 | + /* |
---|
2651 | 2781 | * Death signals, no core dump. |
---|
2652 | 2782 | */ |
---|
2653 | 2783 | do_group_exit(ksig->info.si_signo); |
---|
2654 | 2784 | /* NOTREACHED */ |
---|
2655 | 2785 | } |
---|
2656 | 2786 | spin_unlock_irq(&sighand->siglock); |
---|
2657 | | - |
---|
| 2787 | +out: |
---|
2658 | 2788 | ksig->sig = signr; |
---|
| 2789 | + |
---|
| 2790 | + if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS)) |
---|
| 2791 | + hide_si_addr_tag_bits(ksig); |
---|
| 2792 | + |
---|
2659 | 2793 | return ksig->sig > 0; |
---|
2660 | 2794 | } |
---|
2661 | 2795 | |
---|
.. | .. |
---|
2689 | 2823 | void signal_setup_done(int failed, struct ksignal *ksig, int stepping) |
---|
2690 | 2824 | { |
---|
2691 | 2825 | if (failed) |
---|
2692 | | - force_sigsegv(ksig->sig, current); |
---|
| 2826 | + force_sigsegv(ksig->sig); |
---|
2693 | 2827 | else |
---|
2694 | 2828 | signal_delivered(ksig, stepping); |
---|
2695 | 2829 | } |
---|
.. | .. |
---|
2718 | 2852 | /* Remove the signals this thread can handle. */ |
---|
2719 | 2853 | sigandsets(&retarget, &retarget, &t->blocked); |
---|
2720 | 2854 | |
---|
2721 | | - if (!signal_pending(t)) |
---|
| 2855 | + if (!task_sigpending(t)) |
---|
2722 | 2856 | signal_wake_up(t, 0); |
---|
2723 | 2857 | |
---|
2724 | 2858 | if (sigisemptyset(&retarget)) |
---|
.. | .. |
---|
2752 | 2886 | |
---|
2753 | 2887 | cgroup_threadgroup_change_end(tsk); |
---|
2754 | 2888 | |
---|
2755 | | - if (!signal_pending(tsk)) |
---|
| 2889 | + if (!task_sigpending(tsk)) |
---|
2756 | 2890 | goto out; |
---|
2757 | 2891 | |
---|
2758 | 2892 | unblocked = tsk->blocked; |
---|
.. | .. |
---|
2776 | 2910 | } |
---|
2777 | 2911 | } |
---|
2778 | 2912 | |
---|
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 | 2913 | /* |
---|
2788 | 2914 | * System call entry points. |
---|
2789 | 2915 | */ |
---|
.. | .. |
---|
2804 | 2930 | |
---|
2805 | 2931 | static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset) |
---|
2806 | 2932 | { |
---|
2807 | | - if (signal_pending(tsk) && !thread_group_empty(tsk)) { |
---|
| 2933 | + if (task_sigpending(tsk) && !thread_group_empty(tsk)) { |
---|
2808 | 2934 | sigset_t newblocked; |
---|
2809 | 2935 | /* A set of now blocked but previously unblocked signals. */ |
---|
2810 | 2936 | sigandnsets(&newblocked, newset, ¤t->blocked); |
---|
.. | .. |
---|
2877 | 3003 | __set_current_blocked(&newset); |
---|
2878 | 3004 | return 0; |
---|
2879 | 3005 | } |
---|
| 3006 | +EXPORT_SYMBOL(sigprocmask); |
---|
| 3007 | + |
---|
| 3008 | +/* |
---|
| 3009 | + * The api helps set app-provided sigmasks. |
---|
| 3010 | + * |
---|
| 3011 | + * This is useful for syscalls such as ppoll, pselect, io_pgetevents and |
---|
| 3012 | + * epoll_pwait where a new sigmask is passed from userland for the syscalls. |
---|
| 3013 | + * |
---|
| 3014 | + * Note that it does set_restore_sigmask() in advance, so it must be always |
---|
| 3015 | + * paired with restore_saved_sigmask_unless() before return from syscall. |
---|
| 3016 | + */ |
---|
| 3017 | +int set_user_sigmask(const sigset_t __user *umask, size_t sigsetsize) |
---|
| 3018 | +{ |
---|
| 3019 | + sigset_t kmask; |
---|
| 3020 | + |
---|
| 3021 | + if (!umask) |
---|
| 3022 | + return 0; |
---|
| 3023 | + if (sigsetsize != sizeof(sigset_t)) |
---|
| 3024 | + return -EINVAL; |
---|
| 3025 | + if (copy_from_user(&kmask, umask, sizeof(sigset_t))) |
---|
| 3026 | + return -EFAULT; |
---|
| 3027 | + |
---|
| 3028 | + set_restore_sigmask(); |
---|
| 3029 | + current->saved_sigmask = current->blocked; |
---|
| 3030 | + set_current_blocked(&kmask); |
---|
| 3031 | + |
---|
| 3032 | + return 0; |
---|
| 3033 | +} |
---|
| 3034 | + |
---|
| 3035 | +#ifdef CONFIG_COMPAT |
---|
| 3036 | +int set_compat_user_sigmask(const compat_sigset_t __user *umask, |
---|
| 3037 | + size_t sigsetsize) |
---|
| 3038 | +{ |
---|
| 3039 | + sigset_t kmask; |
---|
| 3040 | + |
---|
| 3041 | + if (!umask) |
---|
| 3042 | + return 0; |
---|
| 3043 | + if (sigsetsize != sizeof(compat_sigset_t)) |
---|
| 3044 | + return -EINVAL; |
---|
| 3045 | + if (get_compat_sigset(&kmask, umask)) |
---|
| 3046 | + return -EFAULT; |
---|
| 3047 | + |
---|
| 3048 | + set_restore_sigmask(); |
---|
| 3049 | + current->saved_sigmask = current->blocked; |
---|
| 3050 | + set_current_blocked(&kmask); |
---|
| 3051 | + |
---|
| 3052 | + return 0; |
---|
| 3053 | +} |
---|
| 3054 | +#endif |
---|
2880 | 3055 | |
---|
2881 | 3056 | /** |
---|
2882 | 3057 | * sys_rt_sigprocmask - change the list of currently blocked signals |
---|
.. | .. |
---|
2987 | 3162 | } |
---|
2988 | 3163 | #endif |
---|
2989 | 3164 | |
---|
| 3165 | +static const struct { |
---|
| 3166 | + unsigned char limit, layout; |
---|
| 3167 | +} sig_sicodes[] = { |
---|
| 3168 | + [SIGILL] = { NSIGILL, SIL_FAULT }, |
---|
| 3169 | + [SIGFPE] = { NSIGFPE, SIL_FAULT }, |
---|
| 3170 | + [SIGSEGV] = { NSIGSEGV, SIL_FAULT }, |
---|
| 3171 | + [SIGBUS] = { NSIGBUS, SIL_FAULT }, |
---|
| 3172 | + [SIGTRAP] = { NSIGTRAP, SIL_FAULT }, |
---|
| 3173 | +#if defined(SIGEMT) |
---|
| 3174 | + [SIGEMT] = { NSIGEMT, SIL_FAULT }, |
---|
| 3175 | +#endif |
---|
| 3176 | + [SIGCHLD] = { NSIGCHLD, SIL_CHLD }, |
---|
| 3177 | + [SIGPOLL] = { NSIGPOLL, SIL_POLL }, |
---|
| 3178 | + [SIGSYS] = { NSIGSYS, SIL_SYS }, |
---|
| 3179 | +}; |
---|
| 3180 | + |
---|
| 3181 | +static bool known_siginfo_layout(unsigned sig, int si_code) |
---|
| 3182 | +{ |
---|
| 3183 | + if (si_code == SI_KERNEL) |
---|
| 3184 | + return true; |
---|
| 3185 | + else if ((si_code > SI_USER)) { |
---|
| 3186 | + if (sig_specific_sicodes(sig)) { |
---|
| 3187 | + if (si_code <= sig_sicodes[sig].limit) |
---|
| 3188 | + return true; |
---|
| 3189 | + } |
---|
| 3190 | + else if (si_code <= NSIGPOLL) |
---|
| 3191 | + return true; |
---|
| 3192 | + } |
---|
| 3193 | + else if (si_code >= SI_DETHREAD) |
---|
| 3194 | + return true; |
---|
| 3195 | + else if (si_code == SI_ASYNCNL) |
---|
| 3196 | + return true; |
---|
| 3197 | + return false; |
---|
| 3198 | +} |
---|
| 3199 | + |
---|
2990 | 3200 | enum siginfo_layout siginfo_layout(unsigned sig, int si_code) |
---|
2991 | 3201 | { |
---|
2992 | 3202 | enum siginfo_layout layout = SIL_KILL; |
---|
2993 | 3203 | 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; |
---|
| 3204 | + if ((sig < ARRAY_SIZE(sig_sicodes)) && |
---|
| 3205 | + (si_code <= sig_sicodes[sig].limit)) { |
---|
| 3206 | + layout = sig_sicodes[sig].layout; |
---|
3011 | 3207 | /* Handle the exceptions */ |
---|
3012 | 3208 | if ((sig == SIGBUS) && |
---|
3013 | 3209 | (si_code >= BUS_MCEERR_AR) && (si_code <= BUS_MCEERR_AO)) |
---|
.. | .. |
---|
3032 | 3228 | return layout; |
---|
3033 | 3229 | } |
---|
3034 | 3230 | |
---|
3035 | | -int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from) |
---|
| 3231 | +static inline char __user *si_expansion(const siginfo_t __user *info) |
---|
3036 | 3232 | { |
---|
3037 | | - if (copy_to_user(to, from , sizeof(struct siginfo))) |
---|
| 3233 | + return ((char __user *)info) + sizeof(struct kernel_siginfo); |
---|
| 3234 | +} |
---|
| 3235 | + |
---|
| 3236 | +int copy_siginfo_to_user(siginfo_t __user *to, const kernel_siginfo_t *from) |
---|
| 3237 | +{ |
---|
| 3238 | + char __user *expansion = si_expansion(to); |
---|
| 3239 | + if (copy_to_user(to, from , sizeof(struct kernel_siginfo))) |
---|
| 3240 | + return -EFAULT; |
---|
| 3241 | + if (clear_user(expansion, SI_EXPANSION_SIZE)) |
---|
3038 | 3242 | return -EFAULT; |
---|
3039 | 3243 | return 0; |
---|
| 3244 | +} |
---|
| 3245 | + |
---|
| 3246 | +static int post_copy_siginfo_from_user(kernel_siginfo_t *info, |
---|
| 3247 | + const siginfo_t __user *from) |
---|
| 3248 | +{ |
---|
| 3249 | + if (unlikely(!known_siginfo_layout(info->si_signo, info->si_code))) { |
---|
| 3250 | + char __user *expansion = si_expansion(from); |
---|
| 3251 | + char buf[SI_EXPANSION_SIZE]; |
---|
| 3252 | + int i; |
---|
| 3253 | + /* |
---|
| 3254 | + * An unknown si_code might need more than |
---|
| 3255 | + * sizeof(struct kernel_siginfo) bytes. Verify all of the |
---|
| 3256 | + * extra bytes are 0. This guarantees copy_siginfo_to_user |
---|
| 3257 | + * will return this data to userspace exactly. |
---|
| 3258 | + */ |
---|
| 3259 | + if (copy_from_user(&buf, expansion, SI_EXPANSION_SIZE)) |
---|
| 3260 | + return -EFAULT; |
---|
| 3261 | + for (i = 0; i < SI_EXPANSION_SIZE; i++) { |
---|
| 3262 | + if (buf[i] != 0) |
---|
| 3263 | + return -E2BIG; |
---|
| 3264 | + } |
---|
| 3265 | + } |
---|
| 3266 | + return 0; |
---|
| 3267 | +} |
---|
| 3268 | + |
---|
| 3269 | +static int __copy_siginfo_from_user(int signo, kernel_siginfo_t *to, |
---|
| 3270 | + const siginfo_t __user *from) |
---|
| 3271 | +{ |
---|
| 3272 | + if (copy_from_user(to, from, sizeof(struct kernel_siginfo))) |
---|
| 3273 | + return -EFAULT; |
---|
| 3274 | + to->si_signo = signo; |
---|
| 3275 | + return post_copy_siginfo_from_user(to, from); |
---|
| 3276 | +} |
---|
| 3277 | + |
---|
| 3278 | +int copy_siginfo_from_user(kernel_siginfo_t *to, const siginfo_t __user *from) |
---|
| 3279 | +{ |
---|
| 3280 | + if (copy_from_user(to, from, sizeof(struct kernel_siginfo))) |
---|
| 3281 | + return -EFAULT; |
---|
| 3282 | + return post_copy_siginfo_from_user(to, from); |
---|
3040 | 3283 | } |
---|
3041 | 3284 | |
---|
3042 | 3285 | #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) |
---|
| 3286 | +/** |
---|
| 3287 | + * copy_siginfo_to_external32 - copy a kernel siginfo into a compat user siginfo |
---|
| 3288 | + * @to: compat siginfo destination |
---|
| 3289 | + * @from: kernel siginfo source |
---|
| 3290 | + * |
---|
| 3291 | + * Note: This function does not work properly for the SIGCHLD on x32, but |
---|
| 3292 | + * fortunately it doesn't have to. The only valid callers for this function are |
---|
| 3293 | + * copy_siginfo_to_user32, which is overriden for x32 and the coredump code. |
---|
| 3294 | + * The latter does not care because SIGCHLD will never cause a coredump. |
---|
| 3295 | + */ |
---|
| 3296 | +void copy_siginfo_to_external32(struct compat_siginfo *to, |
---|
| 3297 | + const struct kernel_siginfo *from) |
---|
3046 | 3298 | { |
---|
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)); |
---|
| 3299 | + memset(to, 0, sizeof(*to)); |
---|
3055 | 3300 | |
---|
3056 | | - new.si_signo = from->si_signo; |
---|
3057 | | - new.si_errno = from->si_errno; |
---|
3058 | | - new.si_code = from->si_code; |
---|
| 3301 | + to->si_signo = from->si_signo; |
---|
| 3302 | + to->si_errno = from->si_errno; |
---|
| 3303 | + to->si_code = from->si_code; |
---|
3059 | 3304 | switch(siginfo_layout(from->si_signo, from->si_code)) { |
---|
3060 | 3305 | case SIL_KILL: |
---|
3061 | | - new.si_pid = from->si_pid; |
---|
3062 | | - new.si_uid = from->si_uid; |
---|
| 3306 | + to->si_pid = from->si_pid; |
---|
| 3307 | + to->si_uid = from->si_uid; |
---|
3063 | 3308 | break; |
---|
3064 | 3309 | case SIL_TIMER: |
---|
3065 | | - new.si_tid = from->si_tid; |
---|
3066 | | - new.si_overrun = from->si_overrun; |
---|
3067 | | - new.si_int = from->si_int; |
---|
| 3310 | + to->si_tid = from->si_tid; |
---|
| 3311 | + to->si_overrun = from->si_overrun; |
---|
| 3312 | + to->si_int = from->si_int; |
---|
3068 | 3313 | break; |
---|
3069 | 3314 | case SIL_POLL: |
---|
3070 | | - new.si_band = from->si_band; |
---|
3071 | | - new.si_fd = from->si_fd; |
---|
| 3315 | + to->si_band = from->si_band; |
---|
| 3316 | + to->si_fd = from->si_fd; |
---|
3072 | 3317 | break; |
---|
3073 | 3318 | case SIL_FAULT: |
---|
3074 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3319 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3075 | 3320 | #ifdef __ARCH_SI_TRAPNO |
---|
3076 | | - new.si_trapno = from->si_trapno; |
---|
| 3321 | + to->si_trapno = from->si_trapno; |
---|
3077 | 3322 | #endif |
---|
3078 | 3323 | break; |
---|
3079 | 3324 | case SIL_FAULT_MCEERR: |
---|
3080 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3325 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3081 | 3326 | #ifdef __ARCH_SI_TRAPNO |
---|
3082 | | - new.si_trapno = from->si_trapno; |
---|
| 3327 | + to->si_trapno = from->si_trapno; |
---|
3083 | 3328 | #endif |
---|
3084 | | - new.si_addr_lsb = from->si_addr_lsb; |
---|
| 3329 | + to->si_addr_lsb = from->si_addr_lsb; |
---|
3085 | 3330 | break; |
---|
3086 | 3331 | case SIL_FAULT_BNDERR: |
---|
3087 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3332 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3088 | 3333 | #ifdef __ARCH_SI_TRAPNO |
---|
3089 | | - new.si_trapno = from->si_trapno; |
---|
| 3334 | + to->si_trapno = from->si_trapno; |
---|
3090 | 3335 | #endif |
---|
3091 | | - new.si_lower = ptr_to_compat(from->si_lower); |
---|
3092 | | - new.si_upper = ptr_to_compat(from->si_upper); |
---|
| 3336 | + to->si_lower = ptr_to_compat(from->si_lower); |
---|
| 3337 | + to->si_upper = ptr_to_compat(from->si_upper); |
---|
3093 | 3338 | break; |
---|
3094 | 3339 | case SIL_FAULT_PKUERR: |
---|
3095 | | - new.si_addr = ptr_to_compat(from->si_addr); |
---|
| 3340 | + to->si_addr = ptr_to_compat(from->si_addr); |
---|
3096 | 3341 | #ifdef __ARCH_SI_TRAPNO |
---|
3097 | | - new.si_trapno = from->si_trapno; |
---|
| 3342 | + to->si_trapno = from->si_trapno; |
---|
3098 | 3343 | #endif |
---|
3099 | | - new.si_pkey = from->si_pkey; |
---|
| 3344 | + to->si_pkey = from->si_pkey; |
---|
3100 | 3345 | break; |
---|
3101 | 3346 | 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 | | - } |
---|
| 3347 | + to->si_pid = from->si_pid; |
---|
| 3348 | + to->si_uid = from->si_uid; |
---|
| 3349 | + to->si_status = from->si_status; |
---|
| 3350 | + to->si_utime = from->si_utime; |
---|
| 3351 | + to->si_stime = from->si_stime; |
---|
3115 | 3352 | break; |
---|
3116 | 3353 | case SIL_RT: |
---|
3117 | | - new.si_pid = from->si_pid; |
---|
3118 | | - new.si_uid = from->si_uid; |
---|
3119 | | - new.si_int = from->si_int; |
---|
| 3354 | + to->si_pid = from->si_pid; |
---|
| 3355 | + to->si_uid = from->si_uid; |
---|
| 3356 | + to->si_int = from->si_int; |
---|
3120 | 3357 | break; |
---|
3121 | 3358 | 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; |
---|
| 3359 | + to->si_call_addr = ptr_to_compat(from->si_call_addr); |
---|
| 3360 | + to->si_syscall = from->si_syscall; |
---|
| 3361 | + to->si_arch = from->si_arch; |
---|
3125 | 3362 | break; |
---|
3126 | 3363 | } |
---|
| 3364 | +} |
---|
3127 | 3365 | |
---|
| 3366 | +int __copy_siginfo_to_user32(struct compat_siginfo __user *to, |
---|
| 3367 | + const struct kernel_siginfo *from) |
---|
| 3368 | +{ |
---|
| 3369 | + struct compat_siginfo new; |
---|
| 3370 | + |
---|
| 3371 | + copy_siginfo_to_external32(&new, from); |
---|
3128 | 3372 | if (copy_to_user(to, &new, sizeof(struct compat_siginfo))) |
---|
3129 | 3373 | return -EFAULT; |
---|
3130 | | - |
---|
3131 | 3374 | return 0; |
---|
3132 | 3375 | } |
---|
3133 | 3376 | |
---|
3134 | | -int copy_siginfo_from_user32(struct siginfo *to, |
---|
| 3377 | +static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, |
---|
| 3378 | + const struct compat_siginfo *from) |
---|
| 3379 | +{ |
---|
| 3380 | + clear_siginfo(to); |
---|
| 3381 | + to->si_signo = from->si_signo; |
---|
| 3382 | + to->si_errno = from->si_errno; |
---|
| 3383 | + to->si_code = from->si_code; |
---|
| 3384 | + switch(siginfo_layout(from->si_signo, from->si_code)) { |
---|
| 3385 | + case SIL_KILL: |
---|
| 3386 | + to->si_pid = from->si_pid; |
---|
| 3387 | + to->si_uid = from->si_uid; |
---|
| 3388 | + break; |
---|
| 3389 | + case SIL_TIMER: |
---|
| 3390 | + to->si_tid = from->si_tid; |
---|
| 3391 | + to->si_overrun = from->si_overrun; |
---|
| 3392 | + to->si_int = from->si_int; |
---|
| 3393 | + break; |
---|
| 3394 | + case SIL_POLL: |
---|
| 3395 | + to->si_band = from->si_band; |
---|
| 3396 | + to->si_fd = from->si_fd; |
---|
| 3397 | + break; |
---|
| 3398 | + case SIL_FAULT: |
---|
| 3399 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3400 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3401 | + to->si_trapno = from->si_trapno; |
---|
| 3402 | +#endif |
---|
| 3403 | + break; |
---|
| 3404 | + case SIL_FAULT_MCEERR: |
---|
| 3405 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3406 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3407 | + to->si_trapno = from->si_trapno; |
---|
| 3408 | +#endif |
---|
| 3409 | + to->si_addr_lsb = from->si_addr_lsb; |
---|
| 3410 | + break; |
---|
| 3411 | + case SIL_FAULT_BNDERR: |
---|
| 3412 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3413 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3414 | + to->si_trapno = from->si_trapno; |
---|
| 3415 | +#endif |
---|
| 3416 | + to->si_lower = compat_ptr(from->si_lower); |
---|
| 3417 | + to->si_upper = compat_ptr(from->si_upper); |
---|
| 3418 | + break; |
---|
| 3419 | + case SIL_FAULT_PKUERR: |
---|
| 3420 | + to->si_addr = compat_ptr(from->si_addr); |
---|
| 3421 | +#ifdef __ARCH_SI_TRAPNO |
---|
| 3422 | + to->si_trapno = from->si_trapno; |
---|
| 3423 | +#endif |
---|
| 3424 | + to->si_pkey = from->si_pkey; |
---|
| 3425 | + break; |
---|
| 3426 | + case SIL_CHLD: |
---|
| 3427 | + to->si_pid = from->si_pid; |
---|
| 3428 | + to->si_uid = from->si_uid; |
---|
| 3429 | + to->si_status = from->si_status; |
---|
| 3430 | +#ifdef CONFIG_X86_X32_ABI |
---|
| 3431 | + if (in_x32_syscall()) { |
---|
| 3432 | + to->si_utime = from->_sifields._sigchld_x32._utime; |
---|
| 3433 | + to->si_stime = from->_sifields._sigchld_x32._stime; |
---|
| 3434 | + } else |
---|
| 3435 | +#endif |
---|
| 3436 | + { |
---|
| 3437 | + to->si_utime = from->si_utime; |
---|
| 3438 | + to->si_stime = from->si_stime; |
---|
| 3439 | + } |
---|
| 3440 | + break; |
---|
| 3441 | + case SIL_RT: |
---|
| 3442 | + to->si_pid = from->si_pid; |
---|
| 3443 | + to->si_uid = from->si_uid; |
---|
| 3444 | + to->si_int = from->si_int; |
---|
| 3445 | + break; |
---|
| 3446 | + case SIL_SYS: |
---|
| 3447 | + to->si_call_addr = compat_ptr(from->si_call_addr); |
---|
| 3448 | + to->si_syscall = from->si_syscall; |
---|
| 3449 | + to->si_arch = from->si_arch; |
---|
| 3450 | + break; |
---|
| 3451 | + } |
---|
| 3452 | + return 0; |
---|
| 3453 | +} |
---|
| 3454 | + |
---|
| 3455 | +static int __copy_siginfo_from_user32(int signo, struct kernel_siginfo *to, |
---|
| 3456 | + const struct compat_siginfo __user *ufrom) |
---|
| 3457 | +{ |
---|
| 3458 | + struct compat_siginfo from; |
---|
| 3459 | + |
---|
| 3460 | + if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo))) |
---|
| 3461 | + return -EFAULT; |
---|
| 3462 | + |
---|
| 3463 | + from.si_signo = signo; |
---|
| 3464 | + return post_copy_siginfo_from_user32(to, &from); |
---|
| 3465 | +} |
---|
| 3466 | + |
---|
| 3467 | +int copy_siginfo_from_user32(struct kernel_siginfo *to, |
---|
3135 | 3468 | const struct compat_siginfo __user *ufrom) |
---|
3136 | 3469 | { |
---|
3137 | 3470 | struct compat_siginfo from; |
---|
.. | .. |
---|
3139 | 3472 | if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo))) |
---|
3140 | 3473 | return -EFAULT; |
---|
3141 | 3474 | |
---|
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; |
---|
| 3475 | + return post_copy_siginfo_from_user32(to, &from); |
---|
3215 | 3476 | } |
---|
3216 | 3477 | #endif /* CONFIG_COMPAT */ |
---|
3217 | 3478 | |
---|
.. | .. |
---|
3221 | 3482 | * @info: if non-null, the signal's siginfo is returned here |
---|
3222 | 3483 | * @ts: upper bound on process time suspension |
---|
3223 | 3484 | */ |
---|
3224 | | -static int do_sigtimedwait(const sigset_t *which, siginfo_t *info, |
---|
3225 | | - const struct timespec *ts) |
---|
| 3485 | +static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info, |
---|
| 3486 | + const struct timespec64 *ts) |
---|
3226 | 3487 | { |
---|
3227 | 3488 | ktime_t *to = NULL, timeout = KTIME_MAX; |
---|
3228 | 3489 | struct task_struct *tsk = current; |
---|
.. | .. |
---|
3230 | 3491 | int sig, ret = 0; |
---|
3231 | 3492 | |
---|
3232 | 3493 | if (ts) { |
---|
3233 | | - if (!timespec_valid(ts)) |
---|
| 3494 | + if (!timespec64_valid(ts)) |
---|
3234 | 3495 | return -EINVAL; |
---|
3235 | | - timeout = timespec_to_ktime(*ts); |
---|
| 3496 | + timeout = timespec64_to_ktime(*ts); |
---|
3236 | 3497 | to = &timeout; |
---|
3237 | 3498 | } |
---|
3238 | 3499 | |
---|
.. | .. |
---|
3280 | 3541 | * @sigsetsize: size of sigset_t type |
---|
3281 | 3542 | */ |
---|
3282 | 3543 | SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese, |
---|
3283 | | - siginfo_t __user *, uinfo, const struct timespec __user *, uts, |
---|
| 3544 | + siginfo_t __user *, uinfo, |
---|
| 3545 | + const struct __kernel_timespec __user *, uts, |
---|
3284 | 3546 | size_t, sigsetsize) |
---|
3285 | 3547 | { |
---|
3286 | 3548 | sigset_t these; |
---|
3287 | | - struct timespec ts; |
---|
3288 | | - siginfo_t info; |
---|
| 3549 | + struct timespec64 ts; |
---|
| 3550 | + kernel_siginfo_t info; |
---|
3289 | 3551 | int ret; |
---|
3290 | 3552 | |
---|
3291 | 3553 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
---|
.. | .. |
---|
3296 | 3558 | return -EFAULT; |
---|
3297 | 3559 | |
---|
3298 | 3560 | if (uts) { |
---|
3299 | | - if (copy_from_user(&ts, uts, sizeof(ts))) |
---|
| 3561 | + if (get_timespec64(&ts, uts)) |
---|
3300 | 3562 | return -EFAULT; |
---|
3301 | 3563 | } |
---|
3302 | 3564 | |
---|
.. | .. |
---|
3310 | 3572 | return ret; |
---|
3311 | 3573 | } |
---|
3312 | 3574 | |
---|
| 3575 | +#ifdef CONFIG_COMPAT_32BIT_TIME |
---|
| 3576 | +SYSCALL_DEFINE4(rt_sigtimedwait_time32, const sigset_t __user *, uthese, |
---|
| 3577 | + siginfo_t __user *, uinfo, |
---|
| 3578 | + const struct old_timespec32 __user *, uts, |
---|
| 3579 | + size_t, sigsetsize) |
---|
| 3580 | +{ |
---|
| 3581 | + sigset_t these; |
---|
| 3582 | + struct timespec64 ts; |
---|
| 3583 | + kernel_siginfo_t info; |
---|
| 3584 | + int ret; |
---|
| 3585 | + |
---|
| 3586 | + if (sigsetsize != sizeof(sigset_t)) |
---|
| 3587 | + return -EINVAL; |
---|
| 3588 | + |
---|
| 3589 | + if (copy_from_user(&these, uthese, sizeof(these))) |
---|
| 3590 | + return -EFAULT; |
---|
| 3591 | + |
---|
| 3592 | + if (uts) { |
---|
| 3593 | + if (get_old_timespec32(&ts, uts)) |
---|
| 3594 | + return -EFAULT; |
---|
| 3595 | + } |
---|
| 3596 | + |
---|
| 3597 | + ret = do_sigtimedwait(&these, &info, uts ? &ts : NULL); |
---|
| 3598 | + |
---|
| 3599 | + if (ret > 0 && uinfo) { |
---|
| 3600 | + if (copy_siginfo_to_user(uinfo, &info)) |
---|
| 3601 | + ret = -EFAULT; |
---|
| 3602 | + } |
---|
| 3603 | + |
---|
| 3604 | + return ret; |
---|
| 3605 | +} |
---|
| 3606 | +#endif |
---|
| 3607 | + |
---|
3313 | 3608 | #ifdef CONFIG_COMPAT |
---|
3314 | | -COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, |
---|
| 3609 | +COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time64, compat_sigset_t __user *, uthese, |
---|
3315 | 3610 | struct compat_siginfo __user *, uinfo, |
---|
3316 | | - struct compat_timespec __user *, uts, compat_size_t, sigsetsize) |
---|
| 3611 | + struct __kernel_timespec __user *, uts, compat_size_t, sigsetsize) |
---|
3317 | 3612 | { |
---|
3318 | 3613 | sigset_t s; |
---|
3319 | | - struct timespec t; |
---|
3320 | | - siginfo_t info; |
---|
| 3614 | + struct timespec64 t; |
---|
| 3615 | + kernel_siginfo_t info; |
---|
3321 | 3616 | long ret; |
---|
3322 | 3617 | |
---|
3323 | 3618 | if (sigsetsize != sizeof(sigset_t)) |
---|
.. | .. |
---|
3327 | 3622 | return -EFAULT; |
---|
3328 | 3623 | |
---|
3329 | 3624 | if (uts) { |
---|
3330 | | - if (compat_get_timespec(&t, uts)) |
---|
| 3625 | + if (get_timespec64(&t, uts)) |
---|
| 3626 | + return -EFAULT; |
---|
| 3627 | + } |
---|
| 3628 | + |
---|
| 3629 | + ret = do_sigtimedwait(&s, &info, uts ? &t : NULL); |
---|
| 3630 | + |
---|
| 3631 | + if (ret > 0 && uinfo) { |
---|
| 3632 | + if (copy_siginfo_to_user32(uinfo, &info)) |
---|
| 3633 | + ret = -EFAULT; |
---|
| 3634 | + } |
---|
| 3635 | + |
---|
| 3636 | + return ret; |
---|
| 3637 | +} |
---|
| 3638 | + |
---|
| 3639 | +#ifdef CONFIG_COMPAT_32BIT_TIME |
---|
| 3640 | +COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time32, compat_sigset_t __user *, uthese, |
---|
| 3641 | + struct compat_siginfo __user *, uinfo, |
---|
| 3642 | + struct old_timespec32 __user *, uts, compat_size_t, sigsetsize) |
---|
| 3643 | +{ |
---|
| 3644 | + sigset_t s; |
---|
| 3645 | + struct timespec64 t; |
---|
| 3646 | + kernel_siginfo_t info; |
---|
| 3647 | + long ret; |
---|
| 3648 | + |
---|
| 3649 | + if (sigsetsize != sizeof(sigset_t)) |
---|
| 3650 | + return -EINVAL; |
---|
| 3651 | + |
---|
| 3652 | + if (get_compat_sigset(&s, uthese)) |
---|
| 3653 | + return -EFAULT; |
---|
| 3654 | + |
---|
| 3655 | + if (uts) { |
---|
| 3656 | + if (get_old_timespec32(&t, uts)) |
---|
3331 | 3657 | return -EFAULT; |
---|
3332 | 3658 | } |
---|
3333 | 3659 | |
---|
.. | .. |
---|
3341 | 3667 | return ret; |
---|
3342 | 3668 | } |
---|
3343 | 3669 | #endif |
---|
| 3670 | +#endif |
---|
3344 | 3671 | |
---|
3345 | | -static inline void prepare_kill_siginfo(int sig, struct siginfo *info) |
---|
| 3672 | +static inline void prepare_kill_siginfo(int sig, struct kernel_siginfo *info) |
---|
3346 | 3673 | { |
---|
3347 | 3674 | clear_siginfo(info); |
---|
3348 | 3675 | info->si_signo = sig; |
---|
.. | .. |
---|
3359 | 3686 | */ |
---|
3360 | 3687 | SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) |
---|
3361 | 3688 | { |
---|
3362 | | - struct siginfo info; |
---|
| 3689 | + struct kernel_siginfo info; |
---|
3363 | 3690 | |
---|
3364 | 3691 | prepare_kill_siginfo(sig, &info); |
---|
3365 | 3692 | |
---|
.. | .. |
---|
3387 | 3714 | return true; |
---|
3388 | 3715 | } |
---|
3389 | 3716 | |
---|
3390 | | -static int copy_siginfo_from_user_any(siginfo_t *kinfo, siginfo_t __user *info) |
---|
| 3717 | +static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info) |
---|
3391 | 3718 | { |
---|
3392 | 3719 | #ifdef CONFIG_COMPAT |
---|
3393 | 3720 | /* |
---|
.. | .. |
---|
3399 | 3726 | return copy_siginfo_from_user32( |
---|
3400 | 3727 | kinfo, (struct compat_siginfo __user *)info); |
---|
3401 | 3728 | #endif |
---|
3402 | | - return copy_from_user(kinfo, info, sizeof(siginfo_t)); |
---|
| 3729 | + return copy_siginfo_from_user(kinfo, info); |
---|
3403 | 3730 | } |
---|
3404 | 3731 | |
---|
3405 | 3732 | static struct pid *pidfd_to_pid(const struct file *file) |
---|
3406 | 3733 | { |
---|
3407 | | - if (file->f_op == &pidfd_fops) |
---|
3408 | | - return file->private_data; |
---|
| 3734 | + struct pid *pid; |
---|
| 3735 | + |
---|
| 3736 | + pid = pidfd_pid(file); |
---|
| 3737 | + if (!IS_ERR(pid)) |
---|
| 3738 | + return pid; |
---|
3409 | 3739 | |
---|
3410 | 3740 | return tgid_pidfd_to_pid(file); |
---|
3411 | 3741 | } |
---|
.. | .. |
---|
3434 | 3764 | int ret; |
---|
3435 | 3765 | struct fd f; |
---|
3436 | 3766 | struct pid *pid; |
---|
3437 | | - siginfo_t kinfo; |
---|
| 3767 | + kernel_siginfo_t kinfo; |
---|
3438 | 3768 | |
---|
3439 | 3769 | /* Enforce flags be set to 0 until we add an extension. */ |
---|
3440 | 3770 | if (flags) |
---|
.. | .. |
---|
3481 | 3811 | } |
---|
3482 | 3812 | |
---|
3483 | 3813 | static int |
---|
3484 | | -do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info) |
---|
| 3814 | +do_send_specific(pid_t tgid, pid_t pid, int sig, struct kernel_siginfo *info) |
---|
3485 | 3815 | { |
---|
3486 | 3816 | struct task_struct *p; |
---|
3487 | 3817 | int error = -ESRCH; |
---|
.. | .. |
---|
3512 | 3842 | |
---|
3513 | 3843 | static int do_tkill(pid_t tgid, pid_t pid, int sig) |
---|
3514 | 3844 | { |
---|
3515 | | - struct siginfo info; |
---|
| 3845 | + struct kernel_siginfo info; |
---|
3516 | 3846 | |
---|
3517 | 3847 | clear_siginfo(&info); |
---|
3518 | 3848 | info.si_signo = sig; |
---|
.. | .. |
---|
3559 | 3889 | return do_tkill(0, pid, sig); |
---|
3560 | 3890 | } |
---|
3561 | 3891 | |
---|
3562 | | -static int do_rt_sigqueueinfo(pid_t pid, int sig, siginfo_t *info) |
---|
| 3892 | +static int do_rt_sigqueueinfo(pid_t pid, int sig, kernel_siginfo_t *info) |
---|
3563 | 3893 | { |
---|
3564 | 3894 | /* Not even root can pretend to send signals from the kernel. |
---|
3565 | 3895 | * Nor can they impersonate a kill()/tgkill(), which adds source info. |
---|
.. | .. |
---|
3567 | 3897 | if ((info->si_code >= 0 || info->si_code == SI_TKILL) && |
---|
3568 | 3898 | (task_pid_vnr(current) != pid)) |
---|
3569 | 3899 | return -EPERM; |
---|
3570 | | - |
---|
3571 | | - info->si_signo = sig; |
---|
3572 | 3900 | |
---|
3573 | 3901 | /* POSIX.1b doesn't mention process groups. */ |
---|
3574 | 3902 | return kill_proc_info(sig, info, pid); |
---|
.. | .. |
---|
3583 | 3911 | SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig, |
---|
3584 | 3912 | siginfo_t __user *, uinfo) |
---|
3585 | 3913 | { |
---|
3586 | | - siginfo_t info; |
---|
3587 | | - if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) |
---|
3588 | | - return -EFAULT; |
---|
| 3914 | + kernel_siginfo_t info; |
---|
| 3915 | + int ret = __copy_siginfo_from_user(sig, &info, uinfo); |
---|
| 3916 | + if (unlikely(ret)) |
---|
| 3917 | + return ret; |
---|
3589 | 3918 | return do_rt_sigqueueinfo(pid, sig, &info); |
---|
3590 | 3919 | } |
---|
3591 | 3920 | |
---|
.. | .. |
---|
3595 | 3924 | int, sig, |
---|
3596 | 3925 | struct compat_siginfo __user *, uinfo) |
---|
3597 | 3926 | { |
---|
3598 | | - siginfo_t info; |
---|
3599 | | - int ret = copy_siginfo_from_user32(&info, uinfo); |
---|
| 3927 | + kernel_siginfo_t info; |
---|
| 3928 | + int ret = __copy_siginfo_from_user32(sig, &info, uinfo); |
---|
3600 | 3929 | if (unlikely(ret)) |
---|
3601 | 3930 | return ret; |
---|
3602 | 3931 | return do_rt_sigqueueinfo(pid, sig, &info); |
---|
3603 | 3932 | } |
---|
3604 | 3933 | #endif |
---|
3605 | 3934 | |
---|
3606 | | -static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, siginfo_t *info) |
---|
| 3935 | +static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, kernel_siginfo_t *info) |
---|
3607 | 3936 | { |
---|
3608 | 3937 | /* This is only valid for single tasks */ |
---|
3609 | 3938 | if (pid <= 0 || tgid <= 0) |
---|
.. | .. |
---|
3616 | 3945 | (task_pid_vnr(current) != pid)) |
---|
3617 | 3946 | return -EPERM; |
---|
3618 | 3947 | |
---|
3619 | | - info->si_signo = sig; |
---|
3620 | | - |
---|
3621 | 3948 | return do_send_specific(tgid, pid, sig, info); |
---|
3622 | 3949 | } |
---|
3623 | 3950 | |
---|
3624 | 3951 | SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig, |
---|
3625 | 3952 | siginfo_t __user *, uinfo) |
---|
3626 | 3953 | { |
---|
3627 | | - siginfo_t info; |
---|
3628 | | - |
---|
3629 | | - if (copy_from_user(&info, uinfo, sizeof(siginfo_t))) |
---|
3630 | | - return -EFAULT; |
---|
3631 | | - |
---|
| 3954 | + kernel_siginfo_t info; |
---|
| 3955 | + int ret = __copy_siginfo_from_user(sig, &info, uinfo); |
---|
| 3956 | + if (unlikely(ret)) |
---|
| 3957 | + return ret; |
---|
3632 | 3958 | return do_rt_tgsigqueueinfo(tgid, pid, sig, &info); |
---|
3633 | 3959 | } |
---|
3634 | 3960 | |
---|
.. | .. |
---|
3639 | 3965 | int, sig, |
---|
3640 | 3966 | struct compat_siginfo __user *, uinfo) |
---|
3641 | 3967 | { |
---|
3642 | | - siginfo_t info; |
---|
3643 | | - |
---|
3644 | | - if (copy_siginfo_from_user32(&info, uinfo)) |
---|
3645 | | - return -EFAULT; |
---|
| 3968 | + kernel_siginfo_t info; |
---|
| 3969 | + int ret = __copy_siginfo_from_user32(sig, &info, uinfo); |
---|
| 3970 | + if (unlikely(ret)) |
---|
| 3971 | + return ret; |
---|
3646 | 3972 | return do_rt_tgsigqueueinfo(tgid, pid, sig, &info); |
---|
3647 | 3973 | } |
---|
3648 | 3974 | #endif |
---|
.. | .. |
---|
3687 | 4013 | spin_lock_irq(&p->sighand->siglock); |
---|
3688 | 4014 | if (oact) |
---|
3689 | 4015 | *oact = *k; |
---|
| 4016 | + |
---|
| 4017 | + /* |
---|
| 4018 | + * Make sure that we never accidentally claim to support SA_UNSUPPORTED, |
---|
| 4019 | + * e.g. by having an architecture use the bit in their uapi. |
---|
| 4020 | + */ |
---|
| 4021 | + BUILD_BUG_ON(UAPI_SA_FLAGS & SA_UNSUPPORTED); |
---|
| 4022 | + |
---|
| 4023 | + /* |
---|
| 4024 | + * Clear unknown flag bits in order to allow userspace to detect missing |
---|
| 4025 | + * support for flag bits and to allow the kernel to use non-uapi bits |
---|
| 4026 | + * internally. |
---|
| 4027 | + */ |
---|
| 4028 | + if (act) |
---|
| 4029 | + act->sa.sa_flags &= UAPI_SA_FLAGS; |
---|
| 4030 | + if (oact) |
---|
| 4031 | + oact->sa.sa_flags &= UAPI_SA_FLAGS; |
---|
3690 | 4032 | |
---|
3691 | 4033 | sigaction_compat_abi(act, oact); |
---|
3692 | 4034 | |
---|
.. | .. |
---|
4033 | 4375 | |
---|
4034 | 4376 | if (act) { |
---|
4035 | 4377 | old_sigset_t mask; |
---|
4036 | | - if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
---|
| 4378 | + if (!access_ok(act, sizeof(*act)) || |
---|
4037 | 4379 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
---|
4038 | 4380 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) || |
---|
4039 | 4381 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || |
---|
.. | .. |
---|
4048 | 4390 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
---|
4049 | 4391 | |
---|
4050 | 4392 | if (!ret && oact) { |
---|
4051 | | - if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
---|
| 4393 | + if (!access_ok(oact, sizeof(*oact)) || |
---|
4052 | 4394 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
---|
4053 | 4395 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) || |
---|
4054 | 4396 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || |
---|
.. | .. |
---|
4070 | 4412 | compat_uptr_t handler, restorer; |
---|
4071 | 4413 | |
---|
4072 | 4414 | if (act) { |
---|
4073 | | - if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
---|
| 4415 | + if (!access_ok(act, sizeof(*act)) || |
---|
4074 | 4416 | __get_user(handler, &act->sa_handler) || |
---|
4075 | 4417 | __get_user(restorer, &act->sa_restorer) || |
---|
4076 | 4418 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || |
---|
.. | .. |
---|
4088 | 4430 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
---|
4089 | 4431 | |
---|
4090 | 4432 | if (!ret && oact) { |
---|
4091 | | - if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
---|
| 4433 | + if (!access_ok(oact, sizeof(*oact)) || |
---|
4092 | 4434 | __put_user(ptr_to_compat(old_ka.sa.sa_handler), |
---|
4093 | 4435 | &oact->sa_handler) || |
---|
4094 | 4436 | __put_user(ptr_to_compat(old_ka.sa.sa_restorer), |
---|
.. | .. |
---|
4225 | 4567 | return NULL; |
---|
4226 | 4568 | } |
---|
4227 | 4569 | |
---|
| 4570 | +static inline void siginfo_buildtime_checks(void) |
---|
| 4571 | +{ |
---|
| 4572 | + BUILD_BUG_ON(sizeof(struct siginfo) != SI_MAX_SIZE); |
---|
| 4573 | + |
---|
| 4574 | + /* Verify the offsets in the two siginfos match */ |
---|
| 4575 | +#define CHECK_OFFSET(field) \ |
---|
| 4576 | + BUILD_BUG_ON(offsetof(siginfo_t, field) != offsetof(kernel_siginfo_t, field)) |
---|
| 4577 | + |
---|
| 4578 | + /* kill */ |
---|
| 4579 | + CHECK_OFFSET(si_pid); |
---|
| 4580 | + CHECK_OFFSET(si_uid); |
---|
| 4581 | + |
---|
| 4582 | + /* timer */ |
---|
| 4583 | + CHECK_OFFSET(si_tid); |
---|
| 4584 | + CHECK_OFFSET(si_overrun); |
---|
| 4585 | + CHECK_OFFSET(si_value); |
---|
| 4586 | + |
---|
| 4587 | + /* rt */ |
---|
| 4588 | + CHECK_OFFSET(si_pid); |
---|
| 4589 | + CHECK_OFFSET(si_uid); |
---|
| 4590 | + CHECK_OFFSET(si_value); |
---|
| 4591 | + |
---|
| 4592 | + /* sigchld */ |
---|
| 4593 | + CHECK_OFFSET(si_pid); |
---|
| 4594 | + CHECK_OFFSET(si_uid); |
---|
| 4595 | + CHECK_OFFSET(si_status); |
---|
| 4596 | + CHECK_OFFSET(si_utime); |
---|
| 4597 | + CHECK_OFFSET(si_stime); |
---|
| 4598 | + |
---|
| 4599 | + /* sigfault */ |
---|
| 4600 | + CHECK_OFFSET(si_addr); |
---|
| 4601 | + CHECK_OFFSET(si_addr_lsb); |
---|
| 4602 | + CHECK_OFFSET(si_lower); |
---|
| 4603 | + CHECK_OFFSET(si_upper); |
---|
| 4604 | + CHECK_OFFSET(si_pkey); |
---|
| 4605 | + |
---|
| 4606 | + /* sigpoll */ |
---|
| 4607 | + CHECK_OFFSET(si_band); |
---|
| 4608 | + CHECK_OFFSET(si_fd); |
---|
| 4609 | + |
---|
| 4610 | + /* sigsys */ |
---|
| 4611 | + CHECK_OFFSET(si_call_addr); |
---|
| 4612 | + CHECK_OFFSET(si_syscall); |
---|
| 4613 | + CHECK_OFFSET(si_arch); |
---|
| 4614 | +#undef CHECK_OFFSET |
---|
| 4615 | + |
---|
| 4616 | + /* usb asyncio */ |
---|
| 4617 | + BUILD_BUG_ON(offsetof(struct siginfo, si_pid) != |
---|
| 4618 | + offsetof(struct siginfo, si_addr)); |
---|
| 4619 | + if (sizeof(int) == sizeof(void __user *)) { |
---|
| 4620 | + BUILD_BUG_ON(sizeof_field(struct siginfo, si_pid) != |
---|
| 4621 | + sizeof(void __user *)); |
---|
| 4622 | + } else { |
---|
| 4623 | + BUILD_BUG_ON((sizeof_field(struct siginfo, si_pid) + |
---|
| 4624 | + sizeof_field(struct siginfo, si_uid)) != |
---|
| 4625 | + sizeof(void __user *)); |
---|
| 4626 | + BUILD_BUG_ON(offsetofend(struct siginfo, si_pid) != |
---|
| 4627 | + offsetof(struct siginfo, si_uid)); |
---|
| 4628 | + } |
---|
| 4629 | +#ifdef CONFIG_COMPAT |
---|
| 4630 | + BUILD_BUG_ON(offsetof(struct compat_siginfo, si_pid) != |
---|
| 4631 | + offsetof(struct compat_siginfo, si_addr)); |
---|
| 4632 | + BUILD_BUG_ON(sizeof_field(struct compat_siginfo, si_pid) != |
---|
| 4633 | + sizeof(compat_uptr_t)); |
---|
| 4634 | + BUILD_BUG_ON(sizeof_field(struct compat_siginfo, si_pid) != |
---|
| 4635 | + sizeof_field(struct siginfo, si_pid)); |
---|
| 4636 | +#endif |
---|
| 4637 | +} |
---|
| 4638 | + |
---|
4228 | 4639 | void __init signals_init(void) |
---|
4229 | 4640 | { |
---|
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); |
---|
| 4641 | + siginfo_buildtime_checks(); |
---|
4234 | 4642 | |
---|
4235 | 4643 | sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC); |
---|
4236 | 4644 | } |
---|