blob: 59b8965433c2fdb2f8337de49680ca6a50b09dde [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Michlmayrdda73d02006-02-18 15:21:30 +00007 * Copyright (C) 1994 - 2000, 2006 Ralf Baechle
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
Harvey Huntd1e63c92016-06-17 16:03:45 +01009 * Copyright (C) 2016, Imagination Technologies Ltd.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
Deepa Dinamani0d553032018-03-13 21:03:25 -070011#include <linux/compat.h>
Harvey Huntd1e63c92016-06-17 16:03:45 +010012#include <linux/compiler.h>
13#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel.h>
15#include <linux/signal.h>
16#include <linux/syscalls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Ralf Baechle431dc802007-02-13 00:05:11 +000018#include <asm/compat-signal.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080019#include <linux/uaccess.h>
Harvey Huntd1e63c92016-06-17 16:03:45 +010020#include <asm/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Franck Bui-Huu36a1f2c22007-02-05 15:24:22 +010022#include "signal-common.h"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/* 32-bit compatibility types */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026typedef unsigned int __sighandler32_t;
27typedef void (*vfptr_t)(void);
28
Franck Bui-Huu9432a9b2007-02-05 15:24:25 +010029/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * Atomically swap in the new signal mask, and wait for a signal.
31 */
32
Al Viro1910f4a2012-12-25 16:25:18 -050033asmlinkage int sys32_sigsuspend(compat_sigset_t __user *uset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Al Viro1910f4a2012-12-25 16:25:18 -050035 return compat_sys_rt_sigsuspend(uset, sizeof(compat_sigset_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
Al Viroaa584802012-12-25 18:55:27 -050038SYSCALL_DEFINE3(32_sigaction, long, sig, const struct compat_sigaction __user *, act,
39 struct compat_sigaction __user *, oact)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
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 Baechle77c728c2005-03-04 19:36:51 +000047 s32 handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds96d4f262019-01-03 18:57:57 -080049 if (!access_ok(act, sizeof(*act)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return -EFAULT;
Ralf Baechle77c728c2005-03-04 19:36:51 +000051 err |= __get_user(handler, &act->sa_handler);
Atsushi Nemoto9bbf28a32006-02-01 01:41:09 +090052 new_ka.sa.sa_handler = (void __user *)(s64)handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 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 Torvalds96d4f262019-01-03 18:57:57 -080064 if (!access_ok(oact, sizeof(*oact)))
Martin Michlmayr62549442006-02-18 20:06:32 +000065 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
67 err |= __put_user((u32)(u64)old_ka.sa.sa_handler,
Ralf Baechle70342282013-01-22 12:59:30 +010068 &oact->sa_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
Martin Michlmayr62549442006-02-18 20:06:32 +000070 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 Torvalds1da177e2005-04-16 15:20:36 -070074 return -EFAULT;
75 }
76
77 return ret;
78}