hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/kernel/signal.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/kernel/signal.c
34 *
....@@ -19,8 +20,8 @@
1920 #include <linux/sched/task.h>
2021 #include <linux/sched/task_stack.h>
2122 #include <linux/sched/cputime.h>
22
-#include <linux/file.h>
2323 #include <linux/sched/rt.h>
24
+#include <linux/file.h>
2425 #include <linux/fs.h>
2526 #include <linux/proc_fs.h>
2627 #include <linux/tty.h>
....@@ -45,6 +46,8 @@
4546 #include <linux/posix-timers.h>
4647 #include <linux/livepatch.h>
4748 #include <linux/cgroup.h>
49
+#include <linux/audit.h>
50
+#include <linux/oom.h>
4851
4952 #define CREATE_TRACE_POINTS
5053 #include <trace/events/signal.h>
....@@ -54,8 +57,9 @@
5457 #include <asm/unistd.h>
5558 #include <asm/siginfo.h>
5659 #include <asm/cacheflush.h>
57
-#include "audit.h" /* audit_signal_info() */
5860
61
+#undef CREATE_TRACE_POINTS
62
+#include <trace/hooks/signal.h>
5963 /*
6064 * SLAB caches for signal bits.
6165 */
....@@ -186,6 +190,7 @@
186190 clear_thread_flag(TIF_SIGPENDING);
187191
188192 }
193
+EXPORT_SYMBOL(recalc_sigpending);
189194
190195 void calculate_sigpending(void)
191196 {
....@@ -353,7 +358,7 @@
353358 * @task has %JOBCTL_STOP_PENDING set and is participating in a group stop.
354359 * Group stop states are cleared and the group stop count is consumed if
355360 * %JOBCTL_STOP_CONSUME was set. If the consumption completes the group
356
- * stop, the appropriate %SIGNAL_* flags are set.
361
+ * stop, the appropriate `SIGNAL_*` flags are set.
357362 *
358363 * CONTEXT:
359364 * Must be called with @task->sighand->siglock held.
....@@ -539,6 +544,7 @@
539544 flush_sigqueue(&t->signal->shared_pending);
540545 spin_unlock_irqrestore(&t->sighand->siglock, flags);
541546 }
547
+EXPORT_SYMBOL(flush_signals);
542548
543549 #ifdef CONFIG_POSIX_TIMERS
544550 static void __flush_itimer_signals(struct sigpending *pending)
....@@ -620,7 +626,7 @@
620626 return !tsk->ptrace;
621627 }
622628
623
-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,
624630 bool *resched_timer)
625631 {
626632 struct sigqueue *q, *first = NULL;
....@@ -666,7 +672,7 @@
666672 }
667673
668674 static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
669
- siginfo_t *info, bool *resched_timer)
675
+ kernel_siginfo_t *info, bool *resched_timer)
670676 {
671677 int sig = next_signal(pending, mask);
672678
....@@ -681,7 +687,7 @@
681687 *
682688 * All callers have to hold the siglock.
683689 */
684
-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)
685691 {
686692 bool resched_timer = false;
687693 int signr;
....@@ -759,8 +765,9 @@
759765 #endif
760766 return signr;
761767 }
768
+EXPORT_SYMBOL_GPL(dequeue_signal);
762769
763
-static int dequeue_synchronous_signal(siginfo_t *info)
770
+static int dequeue_synchronous_signal(kernel_siginfo_t *info)
764771 {
765772 struct task_struct *tsk = current;
766773 struct sigpending *pending = &tsk->pending;
....@@ -776,7 +783,7 @@
776783 * Return the first synchronous signal in the queue.
777784 */
778785 list_for_each_entry(q, &pending->list, list) {
779
- /* Synchronous signals have a postive si_code */
786
+ /* Synchronous signals have a positive si_code */
780787 if ((q->info.si_code > SI_USER) &&
781788 (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) {
782789 sync = q;
....@@ -851,12 +858,12 @@
851858 }
852859 }
853860
854
-static inline int is_si_special(const struct siginfo *info)
861
+static inline int is_si_special(const struct kernel_siginfo *info)
855862 {
856
- return info <= SEND_SIG_FORCED;
863
+ return info <= SEND_SIG_PRIV;
857864 }
858865
859
-static inline bool si_fromuser(const struct siginfo *info)
866
+static inline bool si_fromuser(const struct kernel_siginfo *info)
860867 {
861868 return info == SEND_SIG_NOINFO ||
862869 (!is_si_special(info) && SI_FROMUSER(info));
....@@ -881,7 +888,7 @@
881888 * Bad permissions for sending the signal
882889 * - the caller must hold the RCU read lock
883890 */
884
-static int check_kill_permission(int sig, struct siginfo *info,
891
+static int check_kill_permission(int sig, struct kernel_siginfo *info,
885892 struct task_struct *t)
886893 {
887894 struct pid *sid;
....@@ -908,6 +915,7 @@
908915 */
909916 if (!sid || sid == task_session(current))
910917 break;
918
+ fallthrough;
911919 default:
912920 return -EPERM;
913921 }
....@@ -1006,7 +1014,7 @@
10061014 /*
10071015 * The first thread which returns from do_signal_stop()
10081016 * will take ->siglock, notice SIGNAL_CLD_MASK, and
1009
- * notify its parent. See get_signal_to_deliver().
1017
+ * notify its parent. See get_signal().
10101018 */
10111019 signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED);
10121020 signal->group_stop_count = 0;
....@@ -1039,7 +1047,7 @@
10391047 if (task_is_stopped_or_traced(p))
10401048 return false;
10411049
1042
- return task_curr(p) || !signal_pending(p);
1050
+ return task_curr(p) || !task_sigpending(p);
10431051 }
10441052
10451053 static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
....@@ -1123,29 +1131,8 @@
11231131 return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
11241132 }
11251133
1126
-#ifdef CONFIG_USER_NS
1127
-static inline void userns_fixup_signal_uid(struct siginfo *info, struct task_struct *t)
1128
-{
1129
- if (current_user_ns() == task_cred_xxx(t, user_ns))
1130
- return;
1131
-
1132
- if (SI_FROMKERNEL(info))
1133
- return;
1134
-
1135
- rcu_read_lock();
1136
- info->si_uid = from_kuid_munged(task_cred_xxx(t, user_ns),
1137
- make_kuid(current_user_ns(), info->si_uid));
1138
- rcu_read_unlock();
1139
-}
1140
-#else
1141
-static inline void userns_fixup_signal_uid(struct siginfo *info, struct task_struct *t)
1142
-{
1143
- return;
1144
-}
1145
-#endif
1146
-
1147
-static int __send_signal(int sig, struct siginfo *info, struct task_struct *t,
1148
- 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)
11491136 {
11501137 struct sigpending *pending;
11511138 struct sigqueue *q;
....@@ -1155,8 +1142,7 @@
11551142 assert_spin_locked(&t->sighand->siglock);
11561143
11571144 result = TRACE_SIGNAL_IGNORED;
1158
- if (!prepare_signal(sig, t,
1159
- from_ancestor_ns || (info == SEND_SIG_PRIV) || (info == SEND_SIG_FORCED)))
1145
+ if (!prepare_signal(sig, t, force))
11601146 goto ret;
11611147
11621148 pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending;
....@@ -1171,10 +1157,9 @@
11711157
11721158 result = TRACE_SIGNAL_DELIVERED;
11731159 /*
1174
- * fast-pathed signals for kernel-internal things like SIGSTOP
1175
- * or SIGKILL.
1160
+ * Skip useless siginfo allocation for SIGKILL and kernel threads.
11761161 */
1177
- if (info == SEND_SIG_FORCED)
1162
+ if ((sig == SIGKILL) || (t->flags & PF_KTHREAD))
11781163 goto out_set;
11791164
11801165 /*
....@@ -1202,7 +1187,11 @@
12021187 q->info.si_code = SI_USER;
12031188 q->info.si_pid = task_tgid_nr_ns(current,
12041189 task_active_pid_ns(t));
1205
- 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();
12061195 break;
12071196 case (unsigned long) SEND_SIG_PRIV:
12081197 clear_siginfo(&q->info);
....@@ -1214,30 +1203,24 @@
12141203 break;
12151204 default:
12161205 copy_siginfo(&q->info, info);
1217
- if (from_ancestor_ns)
1218
- q->info.si_pid = 0;
12191206 break;
12201207 }
1221
-
1222
- userns_fixup_signal_uid(&q->info, t);
1223
-
1224
- } else if (!is_si_special(info)) {
1225
- if (sig >= SIGRTMIN && info->si_code != SI_USER) {
1226
- /*
1227
- * Queue overflow, abort. We may abort if the
1228
- * signal was rt and sent by user using something
1229
- * other than kill().
1230
- */
1231
- result = TRACE_SIGNAL_OVERFLOW_FAIL;
1232
- ret = -EAGAIN;
1233
- goto ret;
1234
- } else {
1235
- /*
1236
- * This is a silent loss of information. We still
1237
- * send the signal, but the *info bits are lost.
1238
- */
1239
- result = TRACE_SIGNAL_LOSE_INFO;
1240
- }
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;
12411224 }
12421225
12431226 out_set:
....@@ -1264,17 +1247,62 @@
12641247 return ret;
12651248 }
12661249
1267
-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,
12681273 enum pid_type type)
12691274 {
1270
- int from_ancestor_ns = 0;
1275
+ /* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
1276
+ bool force = false;
12711277
1272
-#ifdef CONFIG_PID_NS
1273
- from_ancestor_ns = si_fromuser(info) &&
1274
- !task_pid_nr_ns(current, task_active_pid_ns(t));
1275
-#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;
12761287
1277
- 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);
12781306 }
12791307
12801308 static void print_fatal_signal(int signr)
....@@ -1311,23 +1339,17 @@
13111339 __setup("print-fatal-signals=", setup_print_fatal_signals);
13121340
13131341 int
1314
-__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)
13151343 {
13161344 return send_signal(sig, info, p, PIDTYPE_TGID);
13171345 }
13181346
1319
-static int
1320
-specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
1321
-{
1322
- return send_signal(sig, info, t, PIDTYPE_PID);
1323
-}
1324
-
1325
-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,
13261348 enum pid_type type)
13271349 {
13281350 unsigned long flags;
13291351 int ret = -ESRCH;
1330
-
1352
+ trace_android_vh_do_send_sig_info(sig, current, p);
13311353 if (lock_task_sighand(p, &flags)) {
13321354 ret = send_signal(sig, info, p, type);
13331355 unlock_task_sighand(p, &flags);
....@@ -1348,12 +1370,41 @@
13481370 * that is why we also clear SIGNAL_UNKILLABLE.
13491371 */
13501372 static int
1351
-do_force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
1373
+force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t)
13521374 {
13531375 unsigned long int flags;
13541376 int ret, blocked, ignored;
13551377 struct k_sigaction *action;
1378
+ int sig = info->si_signo;
13561379
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
13571408 spin_lock_irqsave(&t->sighand->siglock, flags);
13581409 action = &t->sighand->action[sig-1];
13591410 ignored = action->sa.sa_handler == SIG_IGN;
....@@ -1371,43 +1422,15 @@
13711422 */
13721423 if (action->sa.sa_handler == SIG_DFL && !t->ptrace)
13731424 t->signal->flags &= ~SIGNAL_UNKILLABLE;
1374
- ret = specific_send_sig_info(sig, info, t);
1425
+ ret = send_signal(sig, info, t, PIDTYPE_PID);
13751426 spin_unlock_irqrestore(&t->sighand->siglock, flags);
13761427
13771428 return ret;
13781429 }
13791430
1380
-int force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
1431
+int force_sig_info(struct kernel_siginfo *info)
13811432 {
1382
-/*
1383
- * On some archs, PREEMPT_RT has to delay sending a signal from a trap
1384
- * since it can not enable preemption, and the signal code's spin_locks
1385
- * turn into mutexes. Instead, it must set TIF_NOTIFY_RESUME which will
1386
- * send the signal on exit of the trap.
1387
- */
1388
-#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
1389
- if (in_atomic()) {
1390
- if (WARN_ON_ONCE(t != current))
1391
- return 0;
1392
- if (WARN_ON_ONCE(t->forced_info.si_signo))
1393
- return 0;
1394
-
1395
- if (is_si_special(info)) {
1396
- WARN_ON_ONCE(info != SEND_SIG_PRIV);
1397
- t->forced_info.si_signo = sig;
1398
- t->forced_info.si_errno = 0;
1399
- t->forced_info.si_code = SI_KERNEL;
1400
- t->forced_info.si_pid = 0;
1401
- t->forced_info.si_uid = 0;
1402
- } else {
1403
- t->forced_info = *info;
1404
- }
1405
-
1406
- set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
1407
- return 0;
1408
- }
1409
-#endif
1410
- return do_force_sig_info(sig, info, t);
1433
+ return force_sig_info_to_task(info, current);
14111434 }
14121435
14131436 /*
....@@ -1457,7 +1480,7 @@
14571480 * must see ->sighand == NULL.
14581481 */
14591482 spin_lock_irqsave(&sighand->siglock, *flags);
1460
- if (likely(sighand == tsk->sighand))
1483
+ if (likely(sighand == rcu_access_pointer(tsk->sighand)))
14611484 break;
14621485 spin_unlock_irqrestore(&sighand->siglock, *flags);
14631486 }
....@@ -1469,8 +1492,8 @@
14691492 /*
14701493 * send signal info to all the members of a group
14711494 */
1472
-int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p,
1473
- 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)
14741497 {
14751498 int ret;
14761499
....@@ -1478,8 +1501,17 @@
14781501 ret = check_kill_permission(sig, info, p);
14791502 rcu_read_unlock();
14801503
1481
- if (!ret && sig)
1504
+ if (!ret && sig) {
14821505 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
+ }
14831515
14841516 return ret;
14851517 }
....@@ -1489,7 +1521,7 @@
14891521 * control characters do (^C, ^Z etc)
14901522 * - the caller must hold at least a readlock on tasklist_lock
14911523 */
1492
-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)
14931525 {
14941526 struct task_struct *p = NULL;
14951527 int retval, success;
....@@ -1504,7 +1536,7 @@
15041536 return success ? 0 : retval;
15051537 }
15061538
1507
-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)
15081540 {
15091541 int error = -ESRCH;
15101542 struct task_struct *p;
....@@ -1526,7 +1558,7 @@
15261558 }
15271559 }
15281560
1529
-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)
15301562 {
15311563 int error;
15321564 rcu_read_lock();
....@@ -1546,16 +1578,47 @@
15461578 uid_eq(cred->uid, pcred->uid);
15471579 }
15481580
1549
-/* like kill_pid_info(), but doesn't use uid/euid of "current" */
1550
-int kill_pid_info_as_cred(int sig, struct siginfo *info, struct pid *pid,
1551
- 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)
15521608 {
1553
- int ret = -EINVAL;
1609
+ struct kernel_siginfo info;
15541610 struct task_struct *p;
15551611 unsigned long flags;
1612
+ int ret = -EINVAL;
15561613
15571614 if (!valid_signal(sig))
15581615 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;
15591622
15601623 rcu_read_lock();
15611624 p = pid_task(pid, PIDTYPE_PID);
....@@ -1563,17 +1626,17 @@
15631626 ret = -ESRCH;
15641627 goto out_unlock;
15651628 }
1566
- if (si_fromuser(info) && !kill_as_cred_perm(cred, p)) {
1629
+ if (!kill_as_cred_perm(cred, p)) {
15671630 ret = -EPERM;
15681631 goto out_unlock;
15691632 }
1570
- ret = security_task_kill(p, info, sig, cred);
1633
+ ret = security_task_kill(p, &info, sig, cred);
15711634 if (ret)
15721635 goto out_unlock;
15731636
15741637 if (sig) {
15751638 if (lock_task_sighand(p, &flags)) {
1576
- ret = __send_signal(sig, info, p, PIDTYPE_TGID, 0);
1639
+ ret = __send_signal(sig, &info, p, PIDTYPE_TGID, false);
15771640 unlock_task_sighand(p, &flags);
15781641 } else
15791642 ret = -ESRCH;
....@@ -1582,7 +1645,7 @@
15821645 rcu_read_unlock();
15831646 return ret;
15841647 }
1585
-EXPORT_SYMBOL_GPL(kill_pid_info_as_cred);
1648
+EXPORT_SYMBOL_GPL(kill_pid_usb_asyncio);
15861649
15871650 /*
15881651 * kill_something_info() interprets pid in interesting ways just like kill(2).
....@@ -1591,16 +1654,12 @@
15911654 * is probably wrong. Should make it like BSD or SYSV.
15921655 */
15931656
1594
-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)
15951658 {
15961659 int ret;
15971660
1598
- if (pid > 0) {
1599
- rcu_read_lock();
1600
- ret = kill_pid_info(sig, info, find_vpid(pid));
1601
- rcu_read_unlock();
1602
- return ret;
1603
- }
1661
+ if (pid > 0)
1662
+ return kill_proc_info(sig, info, pid);
16041663
16051664 /* -INT_MIN is undefined. Exclude this case to avoid a UBSAN warning */
16061665 if (pid == INT_MIN)
....@@ -1635,7 +1694,7 @@
16351694 * These are for backward compatibility with the rest of the kernel source.
16361695 */
16371696
1638
-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)
16391698 {
16401699 /*
16411700 * Make sure legacy kernel users don't send in bad values
....@@ -1646,6 +1705,7 @@
16461705
16471706 return do_send_sig_info(sig, info, p, PIDTYPE_PID);
16481707 }
1708
+EXPORT_SYMBOL(send_sig_info);
16491709
16501710 #define __si_special(priv) \
16511711 ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO)
....@@ -1655,11 +1715,21 @@
16551715 {
16561716 return send_sig_info(sig, __si_special(priv), p);
16571717 }
1718
+EXPORT_SYMBOL(send_sig);
16581719
1659
-void force_sig(int sig, struct task_struct *p)
1720
+void force_sig(int sig)
16601721 {
1661
- 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);
16621731 }
1732
+EXPORT_SYMBOL(force_sig);
16631733
16641734 /*
16651735 * When things go south during signal handling, we
....@@ -1667,23 +1737,25 @@
16671737 * the problem was already a SIGSEGV, we'll want to
16681738 * make sure we don't even try to deliver the signal..
16691739 */
1670
-void force_sigsegv(int sig, struct task_struct *p)
1740
+void force_sigsegv(int sig)
16711741 {
1742
+ struct task_struct *p = current;
1743
+
16721744 if (sig == SIGSEGV) {
16731745 unsigned long flags;
16741746 spin_lock_irqsave(&p->sighand->siglock, flags);
16751747 p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;
16761748 spin_unlock_irqrestore(&p->sighand->siglock, flags);
16771749 }
1678
- force_sig(SIGSEGV, p);
1750
+ force_sig(SIGSEGV);
16791751 }
16801752
1681
-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
16821754 ___ARCH_SI_TRAPNO(int trapno)
16831755 ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
16841756 , struct task_struct *t)
16851757 {
1686
- struct siginfo info;
1758
+ struct kernel_siginfo info;
16871759
16881760 clear_siginfo(&info);
16891761 info.si_signo = sig;
....@@ -1698,7 +1770,16 @@
16981770 info.si_flags = flags;
16991771 info.si_isr = isr;
17001772 #endif
1701
- 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);
17021783 }
17031784
17041785 int send_sig_fault(int sig, int code, void __user *addr
....@@ -1706,7 +1787,7 @@
17061787 ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
17071788 , struct task_struct *t)
17081789 {
1709
- struct siginfo info;
1790
+ struct kernel_siginfo info;
17101791
17111792 clear_siginfo(&info);
17121793 info.si_signo = sig;
....@@ -1724,9 +1805,9 @@
17241805 return send_sig_info(info.si_signo, &info, t);
17251806 }
17261807
1727
-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)
17281809 {
1729
- struct siginfo info;
1810
+ struct kernel_siginfo info;
17301811
17311812 WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR));
17321813 clear_siginfo(&info);
....@@ -1735,12 +1816,12 @@
17351816 info.si_code = code;
17361817 info.si_addr = addr;
17371818 info.si_addr_lsb = lsb;
1738
- return force_sig_info(info.si_signo, &info, t);
1819
+ return force_sig_info(&info);
17391820 }
17401821
17411822 int send_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t)
17421823 {
1743
- struct siginfo info;
1824
+ struct kernel_siginfo info;
17441825
17451826 WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR));
17461827 clear_siginfo(&info);
....@@ -1755,7 +1836,7 @@
17551836
17561837 int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper)
17571838 {
1758
- struct siginfo info;
1839
+ struct kernel_siginfo info;
17591840
17601841 clear_siginfo(&info);
17611842 info.si_signo = SIGSEGV;
....@@ -1764,13 +1845,13 @@
17641845 info.si_addr = addr;
17651846 info.si_lower = lower;
17661847 info.si_upper = upper;
1767
- return force_sig_info(info.si_signo, &info, current);
1848
+ return force_sig_info(&info);
17681849 }
17691850
17701851 #ifdef SEGV_PKUERR
17711852 int force_sig_pkuerr(void __user *addr, u32 pkey)
17721853 {
1773
- struct siginfo info;
1854
+ struct kernel_siginfo info;
17741855
17751856 clear_siginfo(&info);
17761857 info.si_signo = SIGSEGV;
....@@ -1778,7 +1859,7 @@
17781859 info.si_code = SEGV_PKUERR;
17791860 info.si_addr = addr;
17801861 info.si_pkey = pkey;
1781
- return force_sig_info(info.si_signo, &info, current);
1862
+ return force_sig_info(&info);
17821863 }
17831864 #endif
17841865
....@@ -1787,14 +1868,14 @@
17871868 */
17881869 int force_sig_ptrace_errno_trap(int errno, void __user *addr)
17891870 {
1790
- struct siginfo info;
1871
+ struct kernel_siginfo info;
17911872
17921873 clear_siginfo(&info);
17931874 info.si_signo = SIGTRAP;
17941875 info.si_errno = errno;
17951876 info.si_code = TRAP_HWBKPT;
17961877 info.si_addr = addr;
1797
- return force_sig_info(info.si_signo, &info, current);
1878
+ return force_sig_info(&info);
17981879 }
17991880
18001881 int kill_pgrp(struct pid *pid, int sig, int priv)
....@@ -1912,6 +1993,7 @@
19121993 {
19131994 struct pid *pid;
19141995
1996
+ WARN_ON(task->exit_state == 0);
19151997 pid = task_pid(task);
19161998 wake_up_all(&pid->wait_pidfd);
19171999 }
....@@ -1925,18 +2007,18 @@
19252007 */
19262008 bool do_notify_parent(struct task_struct *tsk, int sig)
19272009 {
1928
- struct siginfo info;
2010
+ struct kernel_siginfo info;
19292011 unsigned long flags;
19302012 struct sighand_struct *psig;
19312013 bool autoreap = false;
19322014 u64 utime, stime;
19332015
1934
- BUG_ON(sig == -1);
2016
+ WARN_ON_ONCE(sig == -1);
19352017
1936
- /* do_notify_parent_cldstop should have been called instead. */
1937
- 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));
19382020
1939
- BUG_ON(!tsk->ptrace &&
2021
+ WARN_ON_ONCE(!tsk->ptrace &&
19402022 (tsk->group_leader != tsk || !thread_group_empty(tsk)));
19412023
19422024 /* Wake up all pidfd waiters */
....@@ -2009,8 +2091,12 @@
20092091 if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN)
20102092 sig = 0;
20112093 }
2094
+ /*
2095
+ * Send with __send_signal as si_pid and si_uid are in the
2096
+ * parent's namespaces.
2097
+ */
20122098 if (valid_signal(sig) && sig)
2013
- __group_send_sig_info(sig, &info, tsk->parent);
2099
+ __send_signal(sig, &info, tsk->parent, PIDTYPE_TGID, false);
20142100 __wake_up_parent(tsk, tsk->parent);
20152101 spin_unlock_irqrestore(&psig->siglock, flags);
20162102
....@@ -2033,7 +2119,7 @@
20332119 static void do_notify_parent_cldstop(struct task_struct *tsk,
20342120 bool for_ptracer, int why)
20352121 {
2036
- struct siginfo info;
2122
+ struct kernel_siginfo info;
20372123 unsigned long flags;
20382124 struct task_struct *parent;
20392125 struct sighand_struct *sighand;
....@@ -2124,7 +2210,7 @@
21242210 * If we actually decide not to stop at all because the tracer
21252211 * is gone, we keep current->exit_code unless clear_code.
21262212 */
2127
-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)
21282214 __releases(&current->sighand->siglock)
21292215 __acquires(&current->sighand->siglock)
21302216 {
....@@ -2209,7 +2295,9 @@
22092295 do_notify_parent_cldstop(current, false, why);
22102296
22112297 read_unlock(&tasklist_lock);
2298
+ cgroup_enter_frozen();
22122299 freezable_schedule();
2300
+ cgroup_leave_frozen(true);
22132301 } else {
22142302 /*
22152303 * By the time we got the lock, our tracer went away.
....@@ -2252,7 +2340,7 @@
22522340
22532341 static void ptrace_do_notify(int signr, int exit_code, int why)
22542342 {
2255
- siginfo_t info;
2343
+ kernel_siginfo_t info;
22562344
22572345 clear_siginfo(&info);
22582346 info.si_signo = signr;
....@@ -2471,7 +2559,7 @@
24712559 freezable_schedule();
24722560 }
24732561
2474
-static int ptrace_signal(int signr, siginfo_t *info)
2562
+static int ptrace_signal(int signr, kernel_siginfo_t *info)
24752563 {
24762564 /*
24772565 * We do not check sig_kernel_stop(signr) but set this marker
....@@ -2512,11 +2600,31 @@
25122600
25132601 /* If the (new) signal is now blocked, requeue it. */
25142602 if (sigismember(&current->blocked, signr)) {
2515
- specific_send_sig_info(signr, info, current);
2603
+ send_signal(signr, info, current, PIDTYPE_PID);
25162604 signr = 0;
25172605 }
25182606
25192607 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
+ }
25202628 }
25212629
25222630 bool get_signal(struct ksignal *ksig)
....@@ -2527,6 +2635,18 @@
25272635
25282636 if (unlikely(current->task_works))
25292637 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
+ }
25302650
25312651 if (unlikely(uprobe_deny_signal()))
25322652 return false;
....@@ -2540,6 +2660,7 @@
25402660
25412661 relock:
25422662 spin_lock_irq(&sighand->siglock);
2663
+
25432664 /*
25442665 * Every stopped thread goes here after wakeup. Check to see if
25452666 * we should notify the parent, prepare_signal(SIGCONT) encodes
....@@ -2583,10 +2704,6 @@
25832704 trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
25842705 &sighand->action[SIGKILL - 1]);
25852706 recalc_sigpending();
2586
- current->jobctl &= ~JOBCTL_TRAP_FREEZE;
2587
- spin_unlock_irq(&sighand->siglock);
2588
- if (unlikely(cgroup_task_frozen(current)))
2589
- cgroup_leave_frozen(true);
25902707 goto fatal;
25912708 }
25922709
....@@ -2614,7 +2731,7 @@
26142731 */
26152732 if (unlikely(cgroup_task_frozen(current))) {
26162733 spin_unlock_irq(&sighand->siglock);
2617
- cgroup_leave_frozen(true);
2734
+ cgroup_leave_frozen(false);
26182735 goto relock;
26192736 }
26202737
....@@ -2708,8 +2825,10 @@
27082825 continue;
27092826 }
27102827
2711
- spin_unlock_irq(&sighand->siglock);
27122828 fatal:
2829
+ spin_unlock_irq(&sighand->siglock);
2830
+ if (unlikely(cgroup_task_frozen(current)))
2831
+ cgroup_leave_frozen(true);
27132832
27142833 /*
27152834 * Anything else is fatal, maybe with a core dump.
....@@ -2732,14 +2851,26 @@
27322851 }
27332852
27342853 /*
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
+ /*
27352862 * Death signals, no core dump.
27362863 */
27372864 do_group_exit(ksig->info.si_signo);
27382865 /* NOTREACHED */
27392866 }
27402867 spin_unlock_irq(&sighand->siglock);
2741
-
2868
+out:
27422869 ksig->sig = signr;
2870
+
2871
+ if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS))
2872
+ hide_si_addr_tag_bits(ksig);
2873
+
27432874 return ksig->sig > 0;
27442875 }
27452876
....@@ -2773,7 +2904,7 @@
27732904 void signal_setup_done(int failed, struct ksignal *ksig, int stepping)
27742905 {
27752906 if (failed)
2776
- force_sigsegv(ksig->sig, current);
2907
+ force_sigsegv(ksig->sig);
27772908 else
27782909 signal_delivered(ksig, stepping);
27792910 }
....@@ -2802,7 +2933,7 @@
28022933 /* Remove the signals this thread can handle. */
28032934 sigandsets(&retarget, &retarget, &t->blocked);
28042935
2805
- if (!signal_pending(t))
2936
+ if (!task_sigpending(t))
28062937 signal_wake_up(t, 0);
28072938
28082939 if (sigisemptyset(&retarget))
....@@ -2836,7 +2967,7 @@
28362967
28372968 cgroup_threadgroup_change_end(tsk);
28382969
2839
- if (!signal_pending(tsk))
2970
+ if (!task_sigpending(tsk))
28402971 goto out;
28412972
28422973 unblocked = tsk->blocked;
....@@ -2860,14 +2991,6 @@
28602991 }
28612992 }
28622993
2863
-EXPORT_SYMBOL(recalc_sigpending);
2864
-EXPORT_SYMBOL_GPL(dequeue_signal);
2865
-EXPORT_SYMBOL(flush_signals);
2866
-EXPORT_SYMBOL(force_sig);
2867
-EXPORT_SYMBOL(send_sig);
2868
-EXPORT_SYMBOL(send_sig_info);
2869
-EXPORT_SYMBOL(sigprocmask);
2870
-
28712994 /*
28722995 * System call entry points.
28732996 */
....@@ -2888,7 +3011,7 @@
28883011
28893012 static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset)
28903013 {
2891
- if (signal_pending(tsk) && !thread_group_empty(tsk)) {
3014
+ if (task_sigpending(tsk) && !thread_group_empty(tsk)) {
28923015 sigset_t newblocked;
28933016 /* A set of now blocked but previously unblocked signals. */
28943017 sigandnsets(&newblocked, newset, &current->blocked);
....@@ -2961,6 +3084,55 @@
29613084 __set_current_blocked(&newset);
29623085 return 0;
29633086 }
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
29643136
29653137 /**
29663138 * sys_rt_sigprocmask - change the list of currently blocked signals
....@@ -3071,27 +3243,48 @@
30713243 }
30723244 #endif
30733245
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
+
30743281 enum siginfo_layout siginfo_layout(unsigned sig, int si_code)
30753282 {
30763283 enum siginfo_layout layout = SIL_KILL;
30773284 if ((si_code > SI_USER) && (si_code < SI_KERNEL)) {
3078
- static const struct {
3079
- unsigned char limit, layout;
3080
- } filter[] = {
3081
- [SIGILL] = { NSIGILL, SIL_FAULT },
3082
- [SIGFPE] = { NSIGFPE, SIL_FAULT },
3083
- [SIGSEGV] = { NSIGSEGV, SIL_FAULT },
3084
- [SIGBUS] = { NSIGBUS, SIL_FAULT },
3085
- [SIGTRAP] = { NSIGTRAP, SIL_FAULT },
3086
-#if defined(SIGEMT) && defined(NSIGEMT)
3087
- [SIGEMT] = { NSIGEMT, SIL_FAULT },
3088
-#endif
3089
- [SIGCHLD] = { NSIGCHLD, SIL_CHLD },
3090
- [SIGPOLL] = { NSIGPOLL, SIL_POLL },
3091
- [SIGSYS] = { NSIGSYS, SIL_SYS },
3092
- };
3093
- if ((sig < ARRAY_SIZE(filter)) && (si_code <= filter[sig].limit)) {
3094
- layout = filter[sig].layout;
3285
+ if ((sig < ARRAY_SIZE(sig_sicodes)) &&
3286
+ (si_code <= sig_sicodes[sig].limit)) {
3287
+ layout = sig_sicodes[sig].layout;
30953288 /* Handle the exceptions */
30963289 if ((sig == SIGBUS) &&
30973290 (si_code >= BUS_MCEERR_AR) && (si_code <= BUS_MCEERR_AO))
....@@ -3116,106 +3309,243 @@
31163309 return layout;
31173310 }
31183311
3119
-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)
31203313 {
3121
- 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))
31223323 return -EFAULT;
31233324 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);
31243364 }
31253365
31263366 #ifdef CONFIG_COMPAT
3127
-int copy_siginfo_to_user32(struct compat_siginfo __user *to,
3128
- const struct siginfo *from)
3129
-#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)
31303379 {
3131
- return __copy_siginfo_to_user32(to, from, in_x32_syscall());
3132
-}
3133
-int __copy_siginfo_to_user32(struct compat_siginfo __user *to,
3134
- const struct siginfo *from, bool x32_ABI)
3135
-#endif
3136
-{
3137
- struct compat_siginfo new;
3138
- memset(&new, 0, sizeof(new));
3380
+ memset(to, 0, sizeof(*to));
31393381
3140
- new.si_signo = from->si_signo;
3141
- new.si_errno = from->si_errno;
3142
- 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;
31433385 switch(siginfo_layout(from->si_signo, from->si_code)) {
31443386 case SIL_KILL:
3145
- new.si_pid = from->si_pid;
3146
- new.si_uid = from->si_uid;
3387
+ to->si_pid = from->si_pid;
3388
+ to->si_uid = from->si_uid;
31473389 break;
31483390 case SIL_TIMER:
3149
- new.si_tid = from->si_tid;
3150
- new.si_overrun = from->si_overrun;
3151
- 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;
31523394 break;
31533395 case SIL_POLL:
3154
- new.si_band = from->si_band;
3155
- new.si_fd = from->si_fd;
3396
+ to->si_band = from->si_band;
3397
+ to->si_fd = from->si_fd;
31563398 break;
31573399 case SIL_FAULT:
3158
- new.si_addr = ptr_to_compat(from->si_addr);
3400
+ to->si_addr = ptr_to_compat(from->si_addr);
31593401 #ifdef __ARCH_SI_TRAPNO
3160
- new.si_trapno = from->si_trapno;
3402
+ to->si_trapno = from->si_trapno;
31613403 #endif
31623404 break;
31633405 case SIL_FAULT_MCEERR:
3164
- new.si_addr = ptr_to_compat(from->si_addr);
3406
+ to->si_addr = ptr_to_compat(from->si_addr);
31653407 #ifdef __ARCH_SI_TRAPNO
3166
- new.si_trapno = from->si_trapno;
3408
+ to->si_trapno = from->si_trapno;
31673409 #endif
3168
- new.si_addr_lsb = from->si_addr_lsb;
3410
+ to->si_addr_lsb = from->si_addr_lsb;
31693411 break;
31703412 case SIL_FAULT_BNDERR:
3171
- new.si_addr = ptr_to_compat(from->si_addr);
3413
+ to->si_addr = ptr_to_compat(from->si_addr);
31723414 #ifdef __ARCH_SI_TRAPNO
3173
- new.si_trapno = from->si_trapno;
3415
+ to->si_trapno = from->si_trapno;
31743416 #endif
3175
- new.si_lower = ptr_to_compat(from->si_lower);
3176
- 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);
31773419 break;
31783420 case SIL_FAULT_PKUERR:
3179
- new.si_addr = ptr_to_compat(from->si_addr);
3421
+ to->si_addr = ptr_to_compat(from->si_addr);
31803422 #ifdef __ARCH_SI_TRAPNO
3181
- new.si_trapno = from->si_trapno;
3423
+ to->si_trapno = from->si_trapno;
31823424 #endif
3183
- new.si_pkey = from->si_pkey;
3425
+ to->si_pkey = from->si_pkey;
31843426 break;
31853427 case SIL_CHLD:
3186
- new.si_pid = from->si_pid;
3187
- new.si_uid = from->si_uid;
3188
- new.si_status = from->si_status;
3189
-#ifdef CONFIG_X86_X32_ABI
3190
- if (x32_ABI) {
3191
- new._sifields._sigchld_x32._utime = from->si_utime;
3192
- new._sifields._sigchld_x32._stime = from->si_stime;
3193
- } else
3194
-#endif
3195
- {
3196
- new.si_utime = from->si_utime;
3197
- new.si_stime = from->si_stime;
3198
- }
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;
31993433 break;
32003434 case SIL_RT:
3201
- new.si_pid = from->si_pid;
3202
- new.si_uid = from->si_uid;
3203
- 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;
32043438 break;
32053439 case SIL_SYS:
3206
- new.si_call_addr = ptr_to_compat(from->si_call_addr);
3207
- new.si_syscall = from->si_syscall;
3208
- 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;
32093443 break;
32103444 }
3445
+}
32113446
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);
32123453 if (copy_to_user(to, &new, sizeof(struct compat_siginfo)))
32133454 return -EFAULT;
3214
-
32153455 return 0;
32163456 }
32173457
3218
-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,
32193549 const struct compat_siginfo __user *ufrom)
32203550 {
32213551 struct compat_siginfo from;
....@@ -3223,79 +3553,7 @@
32233553 if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo)))
32243554 return -EFAULT;
32253555
3226
- clear_siginfo(to);
3227
- to->si_signo = from.si_signo;
3228
- to->si_errno = from.si_errno;
3229
- to->si_code = from.si_code;
3230
- switch(siginfo_layout(from.si_signo, from.si_code)) {
3231
- case SIL_KILL:
3232
- to->si_pid = from.si_pid;
3233
- to->si_uid = from.si_uid;
3234
- break;
3235
- case SIL_TIMER:
3236
- to->si_tid = from.si_tid;
3237
- to->si_overrun = from.si_overrun;
3238
- to->si_int = from.si_int;
3239
- break;
3240
- case SIL_POLL:
3241
- to->si_band = from.si_band;
3242
- to->si_fd = from.si_fd;
3243
- break;
3244
- case SIL_FAULT:
3245
- to->si_addr = compat_ptr(from.si_addr);
3246
-#ifdef __ARCH_SI_TRAPNO
3247
- to->si_trapno = from.si_trapno;
3248
-#endif
3249
- break;
3250
- case SIL_FAULT_MCEERR:
3251
- to->si_addr = compat_ptr(from.si_addr);
3252
-#ifdef __ARCH_SI_TRAPNO
3253
- to->si_trapno = from.si_trapno;
3254
-#endif
3255
- to->si_addr_lsb = from.si_addr_lsb;
3256
- break;
3257
- case SIL_FAULT_BNDERR:
3258
- to->si_addr = compat_ptr(from.si_addr);
3259
-#ifdef __ARCH_SI_TRAPNO
3260
- to->si_trapno = from.si_trapno;
3261
-#endif
3262
- to->si_lower = compat_ptr(from.si_lower);
3263
- to->si_upper = compat_ptr(from.si_upper);
3264
- break;
3265
- case SIL_FAULT_PKUERR:
3266
- to->si_addr = compat_ptr(from.si_addr);
3267
-#ifdef __ARCH_SI_TRAPNO
3268
- to->si_trapno = from.si_trapno;
3269
-#endif
3270
- to->si_pkey = from.si_pkey;
3271
- break;
3272
- case SIL_CHLD:
3273
- to->si_pid = from.si_pid;
3274
- to->si_uid = from.si_uid;
3275
- to->si_status = from.si_status;
3276
-#ifdef CONFIG_X86_X32_ABI
3277
- if (in_x32_syscall()) {
3278
- to->si_utime = from._sifields._sigchld_x32._utime;
3279
- to->si_stime = from._sifields._sigchld_x32._stime;
3280
- } else
3281
-#endif
3282
- {
3283
- to->si_utime = from.si_utime;
3284
- to->si_stime = from.si_stime;
3285
- }
3286
- break;
3287
- case SIL_RT:
3288
- to->si_pid = from.si_pid;
3289
- to->si_uid = from.si_uid;
3290
- to->si_int = from.si_int;
3291
- break;
3292
- case SIL_SYS:
3293
- to->si_call_addr = compat_ptr(from.si_call_addr);
3294
- to->si_syscall = from.si_syscall;
3295
- to->si_arch = from.si_arch;
3296
- break;
3297
- }
3298
- return 0;
3556
+ return post_copy_siginfo_from_user32(to, &from);
32993557 }
33003558 #endif /* CONFIG_COMPAT */
33013559
....@@ -3305,8 +3563,8 @@
33053563 * @info: if non-null, the signal's siginfo is returned here
33063564 * @ts: upper bound on process time suspension
33073565 */
3308
-static int do_sigtimedwait(const sigset_t *which, siginfo_t *info,
3309
- const struct timespec *ts)
3566
+static int do_sigtimedwait(const sigset_t *which, kernel_siginfo_t *info,
3567
+ const struct timespec64 *ts)
33103568 {
33113569 ktime_t *to = NULL, timeout = KTIME_MAX;
33123570 struct task_struct *tsk = current;
....@@ -3314,9 +3572,9 @@
33143572 int sig, ret = 0;
33153573
33163574 if (ts) {
3317
- if (!timespec_valid(ts))
3575
+ if (!timespec64_valid(ts))
33183576 return -EINVAL;
3319
- timeout = timespec_to_ktime(*ts);
3577
+ timeout = timespec64_to_ktime(*ts);
33203578 to = &timeout;
33213579 }
33223580
....@@ -3364,12 +3622,13 @@
33643622 * @sigsetsize: size of sigset_t type
33653623 */
33663624 SYSCALL_DEFINE4(rt_sigtimedwait, const sigset_t __user *, uthese,
3367
- siginfo_t __user *, uinfo, const struct timespec __user *, uts,
3625
+ siginfo_t __user *, uinfo,
3626
+ const struct __kernel_timespec __user *, uts,
33683627 size_t, sigsetsize)
33693628 {
33703629 sigset_t these;
3371
- struct timespec ts;
3372
- siginfo_t info;
3630
+ struct timespec64 ts;
3631
+ kernel_siginfo_t info;
33733632 int ret;
33743633
33753634 /* XXX: Don't preclude handling different sized sigset_t's. */
....@@ -3380,7 +3639,7 @@
33803639 return -EFAULT;
33813640
33823641 if (uts) {
3383
- if (copy_from_user(&ts, uts, sizeof(ts)))
3642
+ if (get_timespec64(&ts, uts))
33843643 return -EFAULT;
33853644 }
33863645
....@@ -3394,14 +3653,47 @@
33943653 return ret;
33953654 }
33963655
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
+
33973689 #ifdef CONFIG_COMPAT
3398
-COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese,
3690
+COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait_time64, compat_sigset_t __user *, uthese,
33993691 struct compat_siginfo __user *, uinfo,
3400
- struct compat_timespec __user *, uts, compat_size_t, sigsetsize)
3692
+ struct __kernel_timespec __user *, uts, compat_size_t, sigsetsize)
34013693 {
34023694 sigset_t s;
3403
- struct timespec t;
3404
- siginfo_t info;
3695
+ struct timespec64 t;
3696
+ kernel_siginfo_t info;
34053697 long ret;
34063698
34073699 if (sigsetsize != sizeof(sigset_t))
....@@ -3411,7 +3703,38 @@
34113703 return -EFAULT;
34123704
34133705 if (uts) {
3414
- 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))
34153738 return -EFAULT;
34163739 }
34173740
....@@ -3425,8 +3748,9 @@
34253748 return ret;
34263749 }
34273750 #endif
3751
+#endif
34283752
3429
-static inline void prepare_kill_siginfo(int sig, struct siginfo *info)
3753
+static inline void prepare_kill_siginfo(int sig, struct kernel_siginfo *info)
34303754 {
34313755 clear_siginfo(info);
34323756 info->si_signo = sig;
....@@ -3443,7 +3767,7 @@
34433767 */
34443768 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
34453769 {
3446
- struct siginfo info;
3770
+ struct kernel_siginfo info;
34473771
34483772 prepare_kill_siginfo(sig, &info);
34493773
....@@ -3471,7 +3795,7 @@
34713795 return true;
34723796 }
34733797
3474
-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)
34753799 {
34763800 #ifdef CONFIG_COMPAT
34773801 /*
....@@ -3483,13 +3807,16 @@
34833807 return copy_siginfo_from_user32(
34843808 kinfo, (struct compat_siginfo __user *)info);
34853809 #endif
3486
- return copy_from_user(kinfo, info, sizeof(siginfo_t));
3810
+ return copy_siginfo_from_user(kinfo, info);
34873811 }
34883812
34893813 static struct pid *pidfd_to_pid(const struct file *file)
34903814 {
3491
- if (file->f_op == &pidfd_fops)
3492
- return file->private_data;
3815
+ struct pid *pid;
3816
+
3817
+ pid = pidfd_pid(file);
3818
+ if (!IS_ERR(pid))
3819
+ return pid;
34933820
34943821 return tgid_pidfd_to_pid(file);
34953822 }
....@@ -3518,7 +3845,7 @@
35183845 int ret;
35193846 struct fd f;
35203847 struct pid *pid;
3521
- siginfo_t kinfo;
3848
+ kernel_siginfo_t kinfo;
35223849
35233850 /* Enforce flags be set to 0 until we add an extension. */
35243851 if (flags)
....@@ -3565,7 +3892,7 @@
35653892 }
35663893
35673894 static int
3568
-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)
35693896 {
35703897 struct task_struct *p;
35713898 int error = -ESRCH;
....@@ -3596,7 +3923,7 @@
35963923
35973924 static int do_tkill(pid_t tgid, pid_t pid, int sig)
35983925 {
3599
- struct siginfo info;
3926
+ struct kernel_siginfo info;
36003927
36013928 clear_siginfo(&info);
36023929 info.si_signo = sig;
....@@ -3643,7 +3970,7 @@
36433970 return do_tkill(0, pid, sig);
36443971 }
36453972
3646
-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)
36473974 {
36483975 /* Not even root can pretend to send signals from the kernel.
36493976 * Nor can they impersonate a kill()/tgkill(), which adds source info.
....@@ -3651,8 +3978,6 @@
36513978 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
36523979 (task_pid_vnr(current) != pid))
36533980 return -EPERM;
3654
-
3655
- info->si_signo = sig;
36563981
36573982 /* POSIX.1b doesn't mention process groups. */
36583983 return kill_proc_info(sig, info, pid);
....@@ -3667,9 +3992,10 @@
36673992 SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
36683993 siginfo_t __user *, uinfo)
36693994 {
3670
- siginfo_t info;
3671
- if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
3672
- return -EFAULT;
3995
+ kernel_siginfo_t info;
3996
+ int ret = __copy_siginfo_from_user(sig, &info, uinfo);
3997
+ if (unlikely(ret))
3998
+ return ret;
36733999 return do_rt_sigqueueinfo(pid, sig, &info);
36744000 }
36754001
....@@ -3679,15 +4005,15 @@
36794005 int, sig,
36804006 struct compat_siginfo __user *, uinfo)
36814007 {
3682
- siginfo_t info;
3683
- int ret = copy_siginfo_from_user32(&info, uinfo);
4008
+ kernel_siginfo_t info;
4009
+ int ret = __copy_siginfo_from_user32(sig, &info, uinfo);
36844010 if (unlikely(ret))
36854011 return ret;
36864012 return do_rt_sigqueueinfo(pid, sig, &info);
36874013 }
36884014 #endif
36894015
3690
-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)
36914017 {
36924018 /* This is only valid for single tasks */
36934019 if (pid <= 0 || tgid <= 0)
....@@ -3700,19 +4026,16 @@
37004026 (task_pid_vnr(current) != pid))
37014027 return -EPERM;
37024028
3703
- info->si_signo = sig;
3704
-
37054029 return do_send_specific(tgid, pid, sig, info);
37064030 }
37074031
37084032 SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig,
37094033 siginfo_t __user *, uinfo)
37104034 {
3711
- siginfo_t info;
3712
-
3713
- if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
3714
- return -EFAULT;
3715
-
4035
+ kernel_siginfo_t info;
4036
+ int ret = __copy_siginfo_from_user(sig, &info, uinfo);
4037
+ if (unlikely(ret))
4038
+ return ret;
37164039 return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
37174040 }
37184041
....@@ -3723,10 +4046,10 @@
37234046 int, sig,
37244047 struct compat_siginfo __user *, uinfo)
37254048 {
3726
- siginfo_t info;
3727
-
3728
- if (copy_siginfo_from_user32(&info, uinfo))
3729
- return -EFAULT;
4049
+ kernel_siginfo_t info;
4050
+ int ret = __copy_siginfo_from_user32(sig, &info, uinfo);
4051
+ if (unlikely(ret))
4052
+ return ret;
37304053 return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
37314054 }
37324055 #endif
....@@ -3771,6 +4094,22 @@
37714094 spin_lock_irq(&p->sighand->siglock);
37724095 if (oact)
37734096 *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;
37744113
37754114 sigaction_compat_abi(act, oact);
37764115
....@@ -4117,7 +4456,7 @@
41174456
41184457 if (act) {
41194458 old_sigset_t mask;
4120
- if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
4459
+ if (!access_ok(act, sizeof(*act)) ||
41214460 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
41224461 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
41234462 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
....@@ -4132,7 +4471,7 @@
41324471 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
41334472
41344473 if (!ret && oact) {
4135
- if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
4474
+ if (!access_ok(oact, sizeof(*oact)) ||
41364475 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
41374476 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
41384477 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
....@@ -4154,7 +4493,7 @@
41544493 compat_uptr_t handler, restorer;
41554494
41564495 if (act) {
4157
- if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
4496
+ if (!access_ok(act, sizeof(*act)) ||
41584497 __get_user(handler, &act->sa_handler) ||
41594498 __get_user(restorer, &act->sa_restorer) ||
41604499 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
....@@ -4172,7 +4511,7 @@
41724511 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
41734512
41744513 if (!ret && oact) {
4175
- if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
4514
+ if (!access_ok(oact, sizeof(*oact)) ||
41764515 __put_user(ptr_to_compat(old_ka.sa.sa_handler),
41774516 &oact->sa_handler) ||
41784517 __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
....@@ -4309,12 +4648,78 @@
43094648 return NULL;
43104649 }
43114650
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
+
43124720 void __init signals_init(void)
43134721 {
4314
- /* If this check fails, the __ARCH_SI_PREAMBLE_SIZE value is wrong! */
4315
- BUILD_BUG_ON(__ARCH_SI_PREAMBLE_SIZE
4316
- != offsetof(struct siginfo, _sifields._pad));
4317
- BUILD_BUG_ON(sizeof(struct siginfo) != SI_MAX_SIZE);
4722
+ siginfo_buildtime_checks();
43184723
43194724 sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC);
43204725 }