hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/kernel/signal.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/kernel/signal.c
34 *
....@@ -44,6 +45,8 @@
4445 #include <linux/posix-timers.h>
4546 #include <linux/livepatch.h>
4647 #include <linux/cgroup.h>
48
+#include <linux/audit.h>
49
+#include <linux/oom.h>
4750
4851 #define CREATE_TRACE_POINTS
4952 #include <trace/events/signal.h>
....@@ -53,8 +56,9 @@
5356 #include <asm/unistd.h>
5457 #include <asm/siginfo.h>
5558 #include <asm/cacheflush.h>
56
-#include "audit.h" /* audit_signal_info() */
5759
60
+#undef CREATE_TRACE_POINTS
61
+#include <trace/hooks/signal.h>
5862 /*
5963 * SLAB caches for signal bits.
6064 */
....@@ -185,6 +189,7 @@
185189 clear_thread_flag(TIF_SIGPENDING);
186190
187191 }
192
+EXPORT_SYMBOL(recalc_sigpending);
188193
189194 void calculate_sigpending(void)
190195 {
....@@ -352,7 +357,7 @@
352357 * @task has %JOBCTL_STOP_PENDING set and is participating in a group stop.
353358 * Group stop states are cleared and the group stop count is consumed if
354359 * %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.
356361 *
357362 * CONTEXT:
358363 * Must be called with @task->sighand->siglock held.
....@@ -481,6 +486,7 @@
481486 flush_sigqueue(&t->signal->shared_pending);
482487 spin_unlock_irqrestore(&t->sighand->siglock, flags);
483488 }
489
+EXPORT_SYMBOL(flush_signals);
484490
485491 #ifdef CONFIG_POSIX_TIMERS
486492 static void __flush_itimer_signals(struct sigpending *pending)
....@@ -562,7 +568,7 @@
562568 return !tsk->ptrace;
563569 }
564570
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,
566572 bool *resched_timer)
567573 {
568574 struct sigqueue *q, *first = NULL;
....@@ -608,7 +614,7 @@
608614 }
609615
610616 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)
612618 {
613619 int sig = next_signal(pending, mask);
614620
....@@ -623,7 +629,7 @@
623629 *
624630 * All callers have to hold the siglock.
625631 */
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)
627633 {
628634 bool resched_timer = false;
629635 int signr;
....@@ -699,8 +705,9 @@
699705 #endif
700706 return signr;
701707 }
708
+EXPORT_SYMBOL_GPL(dequeue_signal);
702709
703
-static int dequeue_synchronous_signal(siginfo_t *info)
710
+static int dequeue_synchronous_signal(kernel_siginfo_t *info)
704711 {
705712 struct task_struct *tsk = current;
706713 struct sigpending *pending = &tsk->pending;
....@@ -716,7 +723,7 @@
716723 * Return the first synchronous signal in the queue.
717724 */
718725 list_for_each_entry(q, &pending->list, list) {
719
- /* Synchronous signals have a postive si_code */
726
+ /* Synchronous signals have a positive si_code */
720727 if ((q->info.si_code > SI_USER) &&
721728 (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK)) {
722729 sync = q;
....@@ -791,12 +798,12 @@
791798 }
792799 }
793800
794
-static inline int is_si_special(const struct siginfo *info)
801
+static inline int is_si_special(const struct kernel_siginfo *info)
795802 {
796
- return info <= SEND_SIG_FORCED;
803
+ return info <= SEND_SIG_PRIV;
797804 }
798805
799
-static inline bool si_fromuser(const struct siginfo *info)
806
+static inline bool si_fromuser(const struct kernel_siginfo *info)
800807 {
801808 return info == SEND_SIG_NOINFO ||
802809 (!is_si_special(info) && SI_FROMUSER(info));
....@@ -821,7 +828,7 @@
821828 * Bad permissions for sending the signal
822829 * - the caller must hold the RCU read lock
823830 */
824
-static int check_kill_permission(int sig, struct siginfo *info,
831
+static int check_kill_permission(int sig, struct kernel_siginfo *info,
825832 struct task_struct *t)
826833 {
827834 struct pid *sid;
....@@ -848,6 +855,7 @@
848855 */
849856 if (!sid || sid == task_session(current))
850857 break;
858
+ fallthrough;
851859 default:
852860 return -EPERM;
853861 }
....@@ -946,7 +954,7 @@
946954 /*
947955 * The first thread which returns from do_signal_stop()
948956 * will take ->siglock, notice SIGNAL_CLD_MASK, and
949
- * notify its parent. See get_signal_to_deliver().
957
+ * notify its parent. See get_signal().
950958 */
951959 signal_set_stop_flags(signal, why | SIGNAL_STOP_CONTINUED);
952960 signal->group_stop_count = 0;
....@@ -979,7 +987,7 @@
979987 if (task_is_stopped_or_traced(p))
980988 return false;
981989
982
- return task_curr(p) || !signal_pending(p);
990
+ return task_curr(p) || !task_sigpending(p);
983991 }
984992
985993 static void complete_signal(int sig, struct task_struct *p, enum pid_type type)
....@@ -1063,29 +1071,8 @@
10631071 return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
10641072 }
10651073
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)
10891076 {
10901077 struct sigpending *pending;
10911078 struct sigqueue *q;
....@@ -1095,8 +1082,7 @@
10951082 assert_spin_locked(&t->sighand->siglock);
10961083
10971084 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))
11001086 goto ret;
11011087
11021088 pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending;
....@@ -1111,10 +1097,9 @@
11111097
11121098 result = TRACE_SIGNAL_DELIVERED;
11131099 /*
1114
- * fast-pathed signals for kernel-internal things like SIGSTOP
1115
- * or SIGKILL.
1100
+ * Skip useless siginfo allocation for SIGKILL and kernel threads.
11161101 */
1117
- if (info == SEND_SIG_FORCED)
1102
+ if ((sig == SIGKILL) || (t->flags & PF_KTHREAD))
11181103 goto out_set;
11191104
11201105 /*
....@@ -1142,7 +1127,11 @@
11421127 q->info.si_code = SI_USER;
11431128 q->info.si_pid = task_tgid_nr_ns(current,
11441129 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();
11461135 break;
11471136 case (unsigned long) SEND_SIG_PRIV:
11481137 clear_siginfo(&q->info);
....@@ -1154,30 +1143,24 @@
11541143 break;
11551144 default:
11561145 copy_siginfo(&q->info, info);
1157
- if (from_ancestor_ns)
1158
- q->info.si_pid = 0;
11591146 break;
11601147 }
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;
11811164 }
11821165
11831166 out_set:
....@@ -1204,17 +1187,62 @@
12041187 return ret;
12051188 }
12061189
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,
12081213 enum pid_type type)
12091214 {
1210
- int from_ancestor_ns = 0;
1215
+ /* Should SIGKILL or SIGSTOP be received by a pid namespace init? */
1216
+ bool force = false;
12111217
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;
12161227
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);
12181246 }
12191247
12201248 static void print_fatal_signal(int signr)
....@@ -1251,23 +1279,17 @@
12511279 __setup("print-fatal-signals=", setup_print_fatal_signals);
12521280
12531281 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)
12551283 {
12561284 return send_signal(sig, info, p, PIDTYPE_TGID);
12571285 }
12581286
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,
12661288 enum pid_type type)
12671289 {
12681290 unsigned long flags;
12691291 int ret = -ESRCH;
1270
-
1292
+ trace_android_vh_do_send_sig_info(sig, current, p);
12711293 if (lock_task_sighand(p, &flags)) {
12721294 ret = send_signal(sig, info, p, type);
12731295 unlock_task_sighand(p, &flags);
....@@ -1287,12 +1309,13 @@
12871309 * We don't want to have recursive SIGSEGV's etc, for example,
12881310 * that is why we also clear SIGNAL_UNKILLABLE.
12891311 */
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)
12921314 {
12931315 unsigned long int flags;
12941316 int ret, blocked, ignored;
12951317 struct k_sigaction *action;
1318
+ int sig = info->si_signo;
12961319
12971320 spin_lock_irqsave(&t->sighand->siglock, flags);
12981321 action = &t->sighand->action[sig-1];
....@@ -1311,10 +1334,15 @@
13111334 */
13121335 if (action->sa.sa_handler == SIG_DFL && !t->ptrace)
13131336 t->signal->flags &= ~SIGNAL_UNKILLABLE;
1314
- ret = specific_send_sig_info(sig, info, t);
1337
+ ret = send_signal(sig, info, t, PIDTYPE_PID);
13151338 spin_unlock_irqrestore(&t->sighand->siglock, flags);
13161339
13171340 return ret;
1341
+}
1342
+
1343
+int force_sig_info(struct kernel_siginfo *info)
1344
+{
1345
+ return force_sig_info_to_task(info, current);
13181346 }
13191347
13201348 /*
....@@ -1364,7 +1392,7 @@
13641392 * must see ->sighand == NULL.
13651393 */
13661394 spin_lock_irqsave(&sighand->siglock, *flags);
1367
- if (likely(sighand == tsk->sighand))
1395
+ if (likely(sighand == rcu_access_pointer(tsk->sighand)))
13681396 break;
13691397 spin_unlock_irqrestore(&sighand->siglock, *flags);
13701398 }
....@@ -1376,8 +1404,8 @@
13761404 /*
13771405 * send signal info to all the members of a group
13781406 */
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)
13811409 {
13821410 int ret;
13831411
....@@ -1385,8 +1413,17 @@
13851413 ret = check_kill_permission(sig, info, p);
13861414 rcu_read_unlock();
13871415
1388
- if (!ret && sig)
1416
+ if (!ret && sig) {
13891417 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
+ }
13901427
13911428 return ret;
13921429 }
....@@ -1396,7 +1433,7 @@
13961433 * control characters do (^C, ^Z etc)
13971434 * - the caller must hold at least a readlock on tasklist_lock
13981435 */
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)
14001437 {
14011438 struct task_struct *p = NULL;
14021439 int retval, success;
....@@ -1411,7 +1448,7 @@
14111448 return success ? 0 : retval;
14121449 }
14131450
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)
14151452 {
14161453 int error = -ESRCH;
14171454 struct task_struct *p;
....@@ -1433,7 +1470,7 @@
14331470 }
14341471 }
14351472
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)
14371474 {
14381475 int error;
14391476 rcu_read_lock();
....@@ -1453,16 +1490,47 @@
14531490 uid_eq(cred->uid, pcred->uid);
14541491 }
14551492
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)
14591520 {
1460
- int ret = -EINVAL;
1521
+ struct kernel_siginfo info;
14611522 struct task_struct *p;
14621523 unsigned long flags;
1524
+ int ret = -EINVAL;
14631525
14641526 if (!valid_signal(sig))
14651527 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;
14661534
14671535 rcu_read_lock();
14681536 p = pid_task(pid, PIDTYPE_PID);
....@@ -1470,17 +1538,17 @@
14701538 ret = -ESRCH;
14711539 goto out_unlock;
14721540 }
1473
- if (si_fromuser(info) && !kill_as_cred_perm(cred, p)) {
1541
+ if (!kill_as_cred_perm(cred, p)) {
14741542 ret = -EPERM;
14751543 goto out_unlock;
14761544 }
1477
- ret = security_task_kill(p, info, sig, cred);
1545
+ ret = security_task_kill(p, &info, sig, cred);
14781546 if (ret)
14791547 goto out_unlock;
14801548
14811549 if (sig) {
14821550 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);
14841552 unlock_task_sighand(p, &flags);
14851553 } else
14861554 ret = -ESRCH;
....@@ -1489,7 +1557,7 @@
14891557 rcu_read_unlock();
14901558 return ret;
14911559 }
1492
-EXPORT_SYMBOL_GPL(kill_pid_info_as_cred);
1560
+EXPORT_SYMBOL_GPL(kill_pid_usb_asyncio);
14931561
14941562 /*
14951563 * kill_something_info() interprets pid in interesting ways just like kill(2).
....@@ -1498,16 +1566,12 @@
14981566 * is probably wrong. Should make it like BSD or SYSV.
14991567 */
15001568
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)
15021570 {
15031571 int ret;
15041572
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);
15111575
15121576 /* -INT_MIN is undefined. Exclude this case to avoid a UBSAN warning */
15131577 if (pid == INT_MIN)
....@@ -1542,7 +1606,7 @@
15421606 * These are for backward compatibility with the rest of the kernel source.
15431607 */
15441608
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)
15461610 {
15471611 /*
15481612 * Make sure legacy kernel users don't send in bad values
....@@ -1553,6 +1617,7 @@
15531617
15541618 return do_send_sig_info(sig, info, p, PIDTYPE_PID);
15551619 }
1620
+EXPORT_SYMBOL(send_sig_info);
15561621
15571622 #define __si_special(priv) \
15581623 ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO)
....@@ -1562,11 +1627,21 @@
15621627 {
15631628 return send_sig_info(sig, __si_special(priv), p);
15641629 }
1630
+EXPORT_SYMBOL(send_sig);
15651631
1566
-void force_sig(int sig, struct task_struct *p)
1632
+void force_sig(int sig)
15671633 {
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);
15691643 }
1644
+EXPORT_SYMBOL(force_sig);
15701645
15711646 /*
15721647 * When things go south during signal handling, we
....@@ -1574,23 +1649,25 @@
15741649 * the problem was already a SIGSEGV, we'll want to
15751650 * make sure we don't even try to deliver the signal..
15761651 */
1577
-void force_sigsegv(int sig, struct task_struct *p)
1652
+void force_sigsegv(int sig)
15781653 {
1654
+ struct task_struct *p = current;
1655
+
15791656 if (sig == SIGSEGV) {
15801657 unsigned long flags;
15811658 spin_lock_irqsave(&p->sighand->siglock, flags);
15821659 p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;
15831660 spin_unlock_irqrestore(&p->sighand->siglock, flags);
15841661 }
1585
- force_sig(SIGSEGV, p);
1662
+ force_sig(SIGSEGV);
15861663 }
15871664
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
15891666 ___ARCH_SI_TRAPNO(int trapno)
15901667 ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
15911668 , struct task_struct *t)
15921669 {
1593
- struct siginfo info;
1670
+ struct kernel_siginfo info;
15941671
15951672 clear_siginfo(&info);
15961673 info.si_signo = sig;
....@@ -1605,7 +1682,16 @@
16051682 info.si_flags = flags;
16061683 info.si_isr = isr;
16071684 #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);
16091695 }
16101696
16111697 int send_sig_fault(int sig, int code, void __user *addr
....@@ -1613,7 +1699,7 @@
16131699 ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
16141700 , struct task_struct *t)
16151701 {
1616
- struct siginfo info;
1702
+ struct kernel_siginfo info;
16171703
16181704 clear_siginfo(&info);
16191705 info.si_signo = sig;
....@@ -1631,9 +1717,9 @@
16311717 return send_sig_info(info.si_signo, &info, t);
16321718 }
16331719
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)
16351721 {
1636
- struct siginfo info;
1722
+ struct kernel_siginfo info;
16371723
16381724 WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR));
16391725 clear_siginfo(&info);
....@@ -1642,12 +1728,12 @@
16421728 info.si_code = code;
16431729 info.si_addr = addr;
16441730 info.si_addr_lsb = lsb;
1645
- return force_sig_info(info.si_signo, &info, t);
1731
+ return force_sig_info(&info);
16461732 }
16471733
16481734 int send_sig_mceerr(int code, void __user *addr, short lsb, struct task_struct *t)
16491735 {
1650
- struct siginfo info;
1736
+ struct kernel_siginfo info;
16511737
16521738 WARN_ON((code != BUS_MCEERR_AO) && (code != BUS_MCEERR_AR));
16531739 clear_siginfo(&info);
....@@ -1662,7 +1748,7 @@
16621748
16631749 int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper)
16641750 {
1665
- struct siginfo info;
1751
+ struct kernel_siginfo info;
16661752
16671753 clear_siginfo(&info);
16681754 info.si_signo = SIGSEGV;
....@@ -1671,13 +1757,13 @@
16711757 info.si_addr = addr;
16721758 info.si_lower = lower;
16731759 info.si_upper = upper;
1674
- return force_sig_info(info.si_signo, &info, current);
1760
+ return force_sig_info(&info);
16751761 }
16761762
16771763 #ifdef SEGV_PKUERR
16781764 int force_sig_pkuerr(void __user *addr, u32 pkey)
16791765 {
1680
- struct siginfo info;
1766
+ struct kernel_siginfo info;
16811767
16821768 clear_siginfo(&info);
16831769 info.si_signo = SIGSEGV;
....@@ -1685,7 +1771,7 @@
16851771 info.si_code = SEGV_PKUERR;
16861772 info.si_addr = addr;
16871773 info.si_pkey = pkey;
1688
- return force_sig_info(info.si_signo, &info, current);
1774
+ return force_sig_info(&info);
16891775 }
16901776 #endif
16911777
....@@ -1694,14 +1780,14 @@
16941780 */
16951781 int force_sig_ptrace_errno_trap(int errno, void __user *addr)
16961782 {
1697
- struct siginfo info;
1783
+ struct kernel_siginfo info;
16981784
16991785 clear_siginfo(&info);
17001786 info.si_signo = SIGTRAP;
17011787 info.si_errno = errno;
17021788 info.si_code = TRAP_HWBKPT;
17031789 info.si_addr = addr;
1704
- return force_sig_info(info.si_signo, &info, current);
1790
+ return force_sig_info(&info);
17051791 }
17061792
17071793 int kill_pgrp(struct pid *pid, int sig, int priv)
....@@ -1818,6 +1904,7 @@
18181904 {
18191905 struct pid *pid;
18201906
1907
+ WARN_ON(task->exit_state == 0);
18211908 pid = task_pid(task);
18221909 wake_up_all(&pid->wait_pidfd);
18231910 }
....@@ -1831,18 +1918,18 @@
18311918 */
18321919 bool do_notify_parent(struct task_struct *tsk, int sig)
18331920 {
1834
- struct siginfo info;
1921
+ struct kernel_siginfo info;
18351922 unsigned long flags;
18361923 struct sighand_struct *psig;
18371924 bool autoreap = false;
18381925 u64 utime, stime;
18391926
1840
- BUG_ON(sig == -1);
1927
+ WARN_ON_ONCE(sig == -1);
18411928
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));
18441931
1845
- BUG_ON(!tsk->ptrace &&
1932
+ WARN_ON_ONCE(!tsk->ptrace &&
18461933 (tsk->group_leader != tsk || !thread_group_empty(tsk)));
18471934
18481935 /* Wake up all pidfd waiters */
....@@ -1915,8 +2002,12 @@
19152002 if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN)
19162003 sig = 0;
19172004 }
2005
+ /*
2006
+ * Send with __send_signal as si_pid and si_uid are in the
2007
+ * parent's namespaces.
2008
+ */
19182009 if (valid_signal(sig) && sig)
1919
- __group_send_sig_info(sig, &info, tsk->parent);
2010
+ __send_signal(sig, &info, tsk->parent, PIDTYPE_TGID, false);
19202011 __wake_up_parent(tsk, tsk->parent);
19212012 spin_unlock_irqrestore(&psig->siglock, flags);
19222013
....@@ -1939,7 +2030,7 @@
19392030 static void do_notify_parent_cldstop(struct task_struct *tsk,
19402031 bool for_ptracer, int why)
19412032 {
1942
- struct siginfo info;
2033
+ struct kernel_siginfo info;
19432034 unsigned long flags;
19442035 struct task_struct *parent;
19452036 struct sighand_struct *sighand;
....@@ -2030,7 +2121,7 @@
20302121 * If we actually decide not to stop at all because the tracer
20312122 * is gone, we keep current->exit_code unless clear_code.
20322123 */
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)
20342125 __releases(&current->sighand->siglock)
20352126 __acquires(&current->sighand->siglock)
20362127 {
....@@ -2168,7 +2259,7 @@
21682259
21692260 static void ptrace_do_notify(int signr, int exit_code, int why)
21702261 {
2171
- siginfo_t info;
2262
+ kernel_siginfo_t info;
21722263
21732264 clear_siginfo(&info);
21742265 info.si_signo = signr;
....@@ -2387,7 +2478,7 @@
23872478 freezable_schedule();
23882479 }
23892480
2390
-static int ptrace_signal(int signr, siginfo_t *info)
2481
+static int ptrace_signal(int signr, kernel_siginfo_t *info)
23912482 {
23922483 /*
23932484 * We do not check sig_kernel_stop(signr) but set this marker
....@@ -2428,11 +2519,31 @@
24282519
24292520 /* If the (new) signal is now blocked, requeue it. */
24302521 if (sigismember(&current->blocked, signr)) {
2431
- specific_send_sig_info(signr, info, current);
2522
+ send_signal(signr, info, current, PIDTYPE_PID);
24322523 signr = 0;
24332524 }
24342525
24352526 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
+ }
24362547 }
24372548
24382549 bool get_signal(struct ksignal *ksig)
....@@ -2443,6 +2554,18 @@
24432554
24442555 if (unlikely(current->task_works))
24452556 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
+ }
24462569
24472570 if (unlikely(uprobe_deny_signal()))
24482571 return false;
....@@ -2456,6 +2579,7 @@
24562579
24572580 relock:
24582581 spin_lock_irq(&sighand->siglock);
2582
+
24592583 /*
24602584 * Every stopped thread goes here after wakeup. Check to see if
24612585 * we should notify the parent, prepare_signal(SIGCONT) encodes
....@@ -2499,10 +2623,6 @@
24992623 trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
25002624 &sighand->action[SIGKILL - 1]);
25012625 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);
25062626 goto fatal;
25072627 }
25082628
....@@ -2530,7 +2650,7 @@
25302650 */
25312651 if (unlikely(cgroup_task_frozen(current))) {
25322652 spin_unlock_irq(&sighand->siglock);
2533
- cgroup_leave_frozen(true);
2653
+ cgroup_leave_frozen(false);
25342654 goto relock;
25352655 }
25362656
....@@ -2624,8 +2744,10 @@
26242744 continue;
26252745 }
26262746
2627
- spin_unlock_irq(&sighand->siglock);
26282747 fatal:
2748
+ spin_unlock_irq(&sighand->siglock);
2749
+ if (unlikely(cgroup_task_frozen(current)))
2750
+ cgroup_leave_frozen(true);
26292751
26302752 /*
26312753 * Anything else is fatal, maybe with a core dump.
....@@ -2648,14 +2770,26 @@
26482770 }
26492771
26502772 /*
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
+ /*
26512781 * Death signals, no core dump.
26522782 */
26532783 do_group_exit(ksig->info.si_signo);
26542784 /* NOTREACHED */
26552785 }
26562786 spin_unlock_irq(&sighand->siglock);
2657
-
2787
+out:
26582788 ksig->sig = signr;
2789
+
2790
+ if (!(ksig->ka.sa.sa_flags & SA_EXPOSE_TAGBITS))
2791
+ hide_si_addr_tag_bits(ksig);
2792
+
26592793 return ksig->sig > 0;
26602794 }
26612795
....@@ -2689,7 +2823,7 @@
26892823 void signal_setup_done(int failed, struct ksignal *ksig, int stepping)
26902824 {
26912825 if (failed)
2692
- force_sigsegv(ksig->sig, current);
2826
+ force_sigsegv(ksig->sig);
26932827 else
26942828 signal_delivered(ksig, stepping);
26952829 }
....@@ -2718,7 +2852,7 @@
27182852 /* Remove the signals this thread can handle. */
27192853 sigandsets(&retarget, &retarget, &t->blocked);
27202854
2721
- if (!signal_pending(t))
2855
+ if (!task_sigpending(t))
27222856 signal_wake_up(t, 0);
27232857
27242858 if (sigisemptyset(&retarget))
....@@ -2752,7 +2886,7 @@
27522886
27532887 cgroup_threadgroup_change_end(tsk);
27542888
2755
- if (!signal_pending(tsk))
2889
+ if (!task_sigpending(tsk))
27562890 goto out;
27572891
27582892 unblocked = tsk->blocked;
....@@ -2776,14 +2910,6 @@
27762910 }
27772911 }
27782912
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
-
27872913 /*
27882914 * System call entry points.
27892915 */
....@@ -2804,7 +2930,7 @@
28042930
28052931 static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset)
28062932 {
2807
- if (signal_pending(tsk) && !thread_group_empty(tsk)) {
2933
+ if (task_sigpending(tsk) && !thread_group_empty(tsk)) {
28082934 sigset_t newblocked;
28092935 /* A set of now blocked but previously unblocked signals. */
28102936 sigandnsets(&newblocked, newset, &current->blocked);
....@@ -2877,6 +3003,55 @@
28773003 __set_current_blocked(&newset);
28783004 return 0;
28793005 }
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
28803055
28813056 /**
28823057 * sys_rt_sigprocmask - change the list of currently blocked signals
....@@ -2987,27 +3162,48 @@
29873162 }
29883163 #endif
29893164
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
+
29903200 enum siginfo_layout siginfo_layout(unsigned sig, int si_code)
29913201 {
29923202 enum siginfo_layout layout = SIL_KILL;
29933203 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;
30113207 /* Handle the exceptions */
30123208 if ((sig == SIGBUS) &&
30133209 (si_code >= BUS_MCEERR_AR) && (si_code <= BUS_MCEERR_AO))
....@@ -3032,106 +3228,243 @@
30323228 return layout;
30333229 }
30343230
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)
30363232 {
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))
30383242 return -EFAULT;
30393243 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);
30403283 }
30413284
30423285 #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)
30463298 {
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));
30553300
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;
30593304 switch(siginfo_layout(from->si_signo, from->si_code)) {
30603305 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;
30633308 break;
30643309 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;
30683313 break;
30693314 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;
30723317 break;
30733318 case SIL_FAULT:
3074
- new.si_addr = ptr_to_compat(from->si_addr);
3319
+ to->si_addr = ptr_to_compat(from->si_addr);
30753320 #ifdef __ARCH_SI_TRAPNO
3076
- new.si_trapno = from->si_trapno;
3321
+ to->si_trapno = from->si_trapno;
30773322 #endif
30783323 break;
30793324 case SIL_FAULT_MCEERR:
3080
- new.si_addr = ptr_to_compat(from->si_addr);
3325
+ to->si_addr = ptr_to_compat(from->si_addr);
30813326 #ifdef __ARCH_SI_TRAPNO
3082
- new.si_trapno = from->si_trapno;
3327
+ to->si_trapno = from->si_trapno;
30833328 #endif
3084
- new.si_addr_lsb = from->si_addr_lsb;
3329
+ to->si_addr_lsb = from->si_addr_lsb;
30853330 break;
30863331 case SIL_FAULT_BNDERR:
3087
- new.si_addr = ptr_to_compat(from->si_addr);
3332
+ to->si_addr = ptr_to_compat(from->si_addr);
30883333 #ifdef __ARCH_SI_TRAPNO
3089
- new.si_trapno = from->si_trapno;
3334
+ to->si_trapno = from->si_trapno;
30903335 #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);
30933338 break;
30943339 case SIL_FAULT_PKUERR:
3095
- new.si_addr = ptr_to_compat(from->si_addr);
3340
+ to->si_addr = ptr_to_compat(from->si_addr);
30963341 #ifdef __ARCH_SI_TRAPNO
3097
- new.si_trapno = from->si_trapno;
3342
+ to->si_trapno = from->si_trapno;
30983343 #endif
3099
- new.si_pkey = from->si_pkey;
3344
+ to->si_pkey = from->si_pkey;
31003345 break;
31013346 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;
31153352 break;
31163353 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;
31203357 break;
31213358 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;
31253362 break;
31263363 }
3364
+}
31273365
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);
31283372 if (copy_to_user(to, &new, sizeof(struct compat_siginfo)))
31293373 return -EFAULT;
3130
-
31313374 return 0;
31323375 }
31333376
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,
31353468 const struct compat_siginfo __user *ufrom)
31363469 {
31373470 struct compat_siginfo from;
....@@ -3139,79 +3472,7 @@
31393472 if (copy_from_user(&from, ufrom, sizeof(struct compat_siginfo)))
31403473 return -EFAULT;
31413474
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);
32153476 }
32163477 #endif /* CONFIG_COMPAT */
32173478
....@@ -3221,8 +3482,8 @@
32213482 * @info: if non-null, the signal's siginfo is returned here
32223483 * @ts: upper bound on process time suspension
32233484 */
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)
32263487 {
32273488 ktime_t *to = NULL, timeout = KTIME_MAX;
32283489 struct task_struct *tsk = current;
....@@ -3230,9 +3491,9 @@
32303491 int sig, ret = 0;
32313492
32323493 if (ts) {
3233
- if (!timespec_valid(ts))
3494
+ if (!timespec64_valid(ts))
32343495 return -EINVAL;
3235
- timeout = timespec_to_ktime(*ts);
3496
+ timeout = timespec64_to_ktime(*ts);
32363497 to = &timeout;
32373498 }
32383499
....@@ -3280,12 +3541,13 @@
32803541 * @sigsetsize: size of sigset_t type
32813542 */
32823543 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,
32843546 size_t, sigsetsize)
32853547 {
32863548 sigset_t these;
3287
- struct timespec ts;
3288
- siginfo_t info;
3549
+ struct timespec64 ts;
3550
+ kernel_siginfo_t info;
32893551 int ret;
32903552
32913553 /* XXX: Don't preclude handling different sized sigset_t's. */
....@@ -3296,7 +3558,7 @@
32963558 return -EFAULT;
32973559
32983560 if (uts) {
3299
- if (copy_from_user(&ts, uts, sizeof(ts)))
3561
+ if (get_timespec64(&ts, uts))
33003562 return -EFAULT;
33013563 }
33023564
....@@ -3310,14 +3572,47 @@
33103572 return ret;
33113573 }
33123574
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
+
33133608 #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,
33153610 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)
33173612 {
33183613 sigset_t s;
3319
- struct timespec t;
3320
- siginfo_t info;
3614
+ struct timespec64 t;
3615
+ kernel_siginfo_t info;
33213616 long ret;
33223617
33233618 if (sigsetsize != sizeof(sigset_t))
....@@ -3327,7 +3622,38 @@
33273622 return -EFAULT;
33283623
33293624 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))
33313657 return -EFAULT;
33323658 }
33333659
....@@ -3341,8 +3667,9 @@
33413667 return ret;
33423668 }
33433669 #endif
3670
+#endif
33443671
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)
33463673 {
33473674 clear_siginfo(info);
33483675 info->si_signo = sig;
....@@ -3359,7 +3686,7 @@
33593686 */
33603687 SYSCALL_DEFINE2(kill, pid_t, pid, int, sig)
33613688 {
3362
- struct siginfo info;
3689
+ struct kernel_siginfo info;
33633690
33643691 prepare_kill_siginfo(sig, &info);
33653692
....@@ -3387,7 +3714,7 @@
33873714 return true;
33883715 }
33893716
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)
33913718 {
33923719 #ifdef CONFIG_COMPAT
33933720 /*
....@@ -3399,13 +3726,16 @@
33993726 return copy_siginfo_from_user32(
34003727 kinfo, (struct compat_siginfo __user *)info);
34013728 #endif
3402
- return copy_from_user(kinfo, info, sizeof(siginfo_t));
3729
+ return copy_siginfo_from_user(kinfo, info);
34033730 }
34043731
34053732 static struct pid *pidfd_to_pid(const struct file *file)
34063733 {
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;
34093739
34103740 return tgid_pidfd_to_pid(file);
34113741 }
....@@ -3434,7 +3764,7 @@
34343764 int ret;
34353765 struct fd f;
34363766 struct pid *pid;
3437
- siginfo_t kinfo;
3767
+ kernel_siginfo_t kinfo;
34383768
34393769 /* Enforce flags be set to 0 until we add an extension. */
34403770 if (flags)
....@@ -3481,7 +3811,7 @@
34813811 }
34823812
34833813 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)
34853815 {
34863816 struct task_struct *p;
34873817 int error = -ESRCH;
....@@ -3512,7 +3842,7 @@
35123842
35133843 static int do_tkill(pid_t tgid, pid_t pid, int sig)
35143844 {
3515
- struct siginfo info;
3845
+ struct kernel_siginfo info;
35163846
35173847 clear_siginfo(&info);
35183848 info.si_signo = sig;
....@@ -3559,7 +3889,7 @@
35593889 return do_tkill(0, pid, sig);
35603890 }
35613891
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)
35633893 {
35643894 /* Not even root can pretend to send signals from the kernel.
35653895 * Nor can they impersonate a kill()/tgkill(), which adds source info.
....@@ -3567,8 +3897,6 @@
35673897 if ((info->si_code >= 0 || info->si_code == SI_TKILL) &&
35683898 (task_pid_vnr(current) != pid))
35693899 return -EPERM;
3570
-
3571
- info->si_signo = sig;
35723900
35733901 /* POSIX.1b doesn't mention process groups. */
35743902 return kill_proc_info(sig, info, pid);
....@@ -3583,9 +3911,10 @@
35833911 SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
35843912 siginfo_t __user *, uinfo)
35853913 {
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;
35893918 return do_rt_sigqueueinfo(pid, sig, &info);
35903919 }
35913920
....@@ -3595,15 +3924,15 @@
35953924 int, sig,
35963925 struct compat_siginfo __user *, uinfo)
35973926 {
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);
36003929 if (unlikely(ret))
36013930 return ret;
36023931 return do_rt_sigqueueinfo(pid, sig, &info);
36033932 }
36043933 #endif
36053934
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)
36073936 {
36083937 /* This is only valid for single tasks */
36093938 if (pid <= 0 || tgid <= 0)
....@@ -3616,19 +3945,16 @@
36163945 (task_pid_vnr(current) != pid))
36173946 return -EPERM;
36183947
3619
- info->si_signo = sig;
3620
-
36213948 return do_send_specific(tgid, pid, sig, info);
36223949 }
36233950
36243951 SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig,
36253952 siginfo_t __user *, uinfo)
36263953 {
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;
36323958 return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
36333959 }
36343960
....@@ -3639,10 +3965,10 @@
36393965 int, sig,
36403966 struct compat_siginfo __user *, uinfo)
36413967 {
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;
36463972 return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
36473973 }
36483974 #endif
....@@ -3687,6 +4013,22 @@
36874013 spin_lock_irq(&p->sighand->siglock);
36884014 if (oact)
36894015 *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;
36904032
36914033 sigaction_compat_abi(act, oact);
36924034
....@@ -4033,7 +4375,7 @@
40334375
40344376 if (act) {
40354377 old_sigset_t mask;
4036
- if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
4378
+ if (!access_ok(act, sizeof(*act)) ||
40374379 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
40384380 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
40394381 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
....@@ -4048,7 +4390,7 @@
40484390 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
40494391
40504392 if (!ret && oact) {
4051
- if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
4393
+ if (!access_ok(oact, sizeof(*oact)) ||
40524394 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
40534395 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
40544396 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
....@@ -4070,7 +4412,7 @@
40704412 compat_uptr_t handler, restorer;
40714413
40724414 if (act) {
4073
- if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
4415
+ if (!access_ok(act, sizeof(*act)) ||
40744416 __get_user(handler, &act->sa_handler) ||
40754417 __get_user(restorer, &act->sa_restorer) ||
40764418 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
....@@ -4088,7 +4430,7 @@
40884430 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
40894431
40904432 if (!ret && oact) {
4091
- if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
4433
+ if (!access_ok(oact, sizeof(*oact)) ||
40924434 __put_user(ptr_to_compat(old_ka.sa.sa_handler),
40934435 &oact->sa_handler) ||
40944436 __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
....@@ -4225,12 +4567,78 @@
42254567 return NULL;
42264568 }
42274569
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
+
42284639 void __init signals_init(void)
42294640 {
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();
42344642
42354643 sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC);
42364644 }