Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1991, 1992 Linus Torvalds |
Martin Michlmayr | dda73d0 | 2006-02-18 15:21:30 +0000 | [diff] [blame] | 7 | * Copyright (C) 1994 - 2000, 2006 Ralf Baechle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
Harvey Hunt | d1e63c9 | 2016-06-17 16:03:45 +0100 | [diff] [blame] | 9 | * Copyright (C) 2016, Imagination Technologies Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
Deepa Dinamani | 0d55303 | 2018-03-13 21:03:25 -0700 | [diff] [blame] | 11 | #include <linux/compat.h> |
Harvey Hunt | d1e63c9 | 2016-06-17 16:03:45 +0100 | [diff] [blame] | 12 | #include <linux/compiler.h> |
| 13 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/signal.h> |
| 16 | #include <linux/syscalls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 18 | #include <asm/compat-signal.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
Harvey Hunt | d1e63c9 | 2016-06-17 16:03:45 +0100 | [diff] [blame] | 20 | #include <asm/unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Franck Bui-Huu | 36a1f2c2 | 2007-02-05 15:24:22 +0100 | [diff] [blame] | 22 | #include "signal-common.h" |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* 32-bit compatibility types */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | typedef unsigned int __sighandler32_t; |
| 27 | typedef void (*vfptr_t)(void); |
| 28 | |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 29 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * Atomically swap in the new signal mask, and wait for a signal. |
| 31 | */ |
| 32 | |
Al Viro | 1910f4a | 2012-12-25 16:25:18 -0500 | [diff] [blame] | 33 | asmlinkage int sys32_sigsuspend(compat_sigset_t __user *uset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Al Viro | 1910f4a | 2012-12-25 16:25:18 -0500 | [diff] [blame] | 35 | return compat_sys_rt_sigsuspend(uset, sizeof(compat_sigset_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Al Viro | aa58480 | 2012-12-25 18:55:27 -0500 | [diff] [blame] | 38 | SYSCALL_DEFINE3(32_sigaction, long, sig, const struct compat_sigaction __user *, act, |
| 39 | struct compat_sigaction __user *, oact) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
| 41 | struct k_sigaction new_ka, old_ka; |
| 42 | int ret; |
| 43 | int err = 0; |
| 44 | |
| 45 | if (act) { |
| 46 | old_sigset_t mask; |
Ralf Baechle | 77c728c | 2005-03-04 19:36:51 +0000 | [diff] [blame] | 47 | s32 handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Linus Torvalds | 96d4f26 | 2019-01-03 18:57:57 -0800 | [diff] [blame] | 49 | if (!access_ok(act, sizeof(*act))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | return -EFAULT; |
Ralf Baechle | 77c728c | 2005-03-04 19:36:51 +0000 | [diff] [blame] | 51 | err |= __get_user(handler, &act->sa_handler); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 52 | new_ka.sa.sa_handler = (void __user *)(s64)handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 54 | err |= __get_user(mask, &act->sa_mask.sig[0]); |
| 55 | if (err) |
| 56 | return -EFAULT; |
| 57 | |
| 58 | siginitset(&new_ka.sa.sa_mask, mask); |
| 59 | } |
| 60 | |
| 61 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 62 | |
| 63 | if (!ret && oact) { |
Linus Torvalds | 96d4f26 | 2019-01-03 18:57:57 -0800 | [diff] [blame] | 64 | if (!access_ok(oact, sizeof(*oact))) |
Martin Michlmayr | 6254944 | 2006-02-18 20:06:32 +0000 | [diff] [blame] | 65 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 67 | err |= __put_user((u32)(u64)old_ka.sa.sa_handler, |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 68 | &oact->sa_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig); |
Martin Michlmayr | 6254944 | 2006-02-18 20:06:32 +0000 | [diff] [blame] | 70 | err |= __put_user(0, &oact->sa_mask.sig[1]); |
| 71 | err |= __put_user(0, &oact->sa_mask.sig[2]); |
| 72 | err |= __put_user(0, &oact->sa_mask.sig[3]); |
| 73 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | return -EFAULT; |
| 75 | } |
| 76 | |
| 77 | return ret; |
| 78 | } |