Commit 849badb7 authored by Stephen Rothwell's avatar Stephen Rothwell Committed by Linus Torvalds

[PATCH] consolidate arch specific copy_siginfo_to_user

This patch moves a version of copy_siginfo_to_user that is common to
ten of our architectures into the gerneic code and allows the other
architectures to override it.  I suspect more of the remaining
architectures will be able to use it as well once it is fixed (patch
to follow).
parent 052508d3
......@@ -51,42 +51,6 @@ static const unsigned long retcodes[4] = {
asmlinkage int do_signal(sigset_t *oldset, struct pt_regs * regs, int syscall);
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
int err = -EFAULT;;
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
goto out;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
out:
return err;
}
/*
* atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -30,41 +30,6 @@
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
/*
* Atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -190,41 +190,6 @@ struct rt_sigframe
};
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
static unsigned char fpu_version = 0; /* version number of fpu, set by setup_frame */
static inline int restore_fpu_state(struct sigcontext *sc)
......
......@@ -37,41 +37,6 @@ extern asmlinkage int (*restore_fp_context)(struct sigcontext *sc);
extern asmlinkage void syscall_trace(void);
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
/*
* Atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -62,41 +62,6 @@ extern void sigreturn_exit(struct pt_regs *);
int do_signal(sigset_t *oldset, struct pt_regs *regs);
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
/*
* Atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -65,41 +65,6 @@ int do_signal(sigset_t *oldset, struct pt_regs *regs);
extern long sys_wait4(pid_t pid, unsigned int *stat_addr,
int options, /*unsigned long*/ struct rusage *ru);
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
/*
* Atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -49,41 +49,6 @@ typedef struct
asmlinkage int FASTCALL(do_signal(struct pt_regs *regs, sigset_t *oldset));
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
/*
* Atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -49,41 +49,6 @@ typedef struct
asmlinkage int FASTCALL(do_signal(struct pt_regs *regs, sigset_t *oldset));
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
/*
* Atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -34,41 +34,6 @@
asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset);
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
/*
* Atomically swap in the new signal mask, and wait for a signal.
*/
......
......@@ -39,41 +39,6 @@ void ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
void ia32_setup_frame(int sig, struct k_sigaction *ka,
sigset_t *set, struct pt_regs * regs);
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
asmlinkage long
sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, struct pt_regs regs)
{
......
......@@ -227,6 +227,7 @@ extern inline void copy_siginfo(siginfo_t *to, siginfo_t *from)
memcpy(to, from, 4*sizeof(int) + sizeof(from->_sifields._sigchld));
}
#define HAVE_ARCH_COPY_SIGINFO_TO_USER
extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
#endif /* __KERNEL__ */
......
......@@ -226,6 +226,7 @@ extern inline void copy_siginfo(siginfo_t *to, siginfo_t *from)
memcpy(to, from, 3*sizeof(int) + sizeof(from->_sifields._sigchld));
}
#define HAVE_ARCH_COPY_SIGINFO_TO_USER
extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
#endif /* __KERNEL__ */
......
......@@ -271,6 +271,7 @@ copy_siginfo (siginfo_t *to, siginfo_t *from)
memcpy(to, from, 3*sizeof(int) + sizeof(from->_sifields._sigchld));
}
#define HAVE_ARCH_COPY_SIGINFO_TO_USER
extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
extern int copy_siginfo_from_user(siginfo_t *to, siginfo_t *from);
......
......@@ -248,6 +248,7 @@ extern inline void copy_siginfo(siginfo_t *to, siginfo_t *from)
memcpy(to, from, 3*sizeof(int) + sizeof(from->_sifields._sigchld));
}
#define HAVE_ARCH_COPY_SIGINFO_TO_USER
extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
#endif /* __KERNEL__ */
......
......@@ -228,6 +228,7 @@ extern inline void copy_siginfo(siginfo_t *to, siginfo_t *from)
memcpy(to, from, 3*sizeof(int) + sizeof(from->_sifields._sigchld));
}
#define HAVE_ARCH_COPY_SIGINFO_TO_USER
extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
#endif /* __KERNEL__ */
......
......@@ -236,6 +236,7 @@ extern inline void copy_siginfo(siginfo_t *to, siginfo_t *from)
memcpy(to, from, 3*sizeof(int) + sizeof(from->_sifields._sigchld));
}
#define HAVE_ARCH_COPY_SIGINFO_TO_USER
extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
#endif /* __KERNEL__ */
......
......@@ -311,6 +311,7 @@ extern inline void copy_siginfo(siginfo_t *to, siginfo_t *from)
memcpy(to, from, 4*sizeof(int) + sizeof(from->_sifields._sigchld));
}
#define HAVE_ARCH_COPY_SIGINFO_TO_USER
extern int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from);
extern int copy_siginfo_to_user32(siginfo_t32 *to, siginfo_t *from);
......
......@@ -16,6 +16,7 @@
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <asm/siginfo.h>
/*
* SLAB caches for signal bits.
......@@ -932,6 +933,45 @@ sys_rt_sigpending(sigset_t *set, size_t sigsetsize)
return do_sigpending(set, sigsetsize);
}
#ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER
int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
{
if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
return -EFAULT;
if (from->si_code < 0)
return __copy_to_user(to, from, sizeof(siginfo_t));
else {
int err;
/* If you change siginfo_t structure, please be sure
this code is fixed accordingly.
It should never copy any pad contained in the structure
to avoid security leaks, but must copy the generic
3 ints plus the relevant union member. */
err = __put_user(from->si_signo, &to->si_signo);
err |= __put_user(from->si_errno, &to->si_errno);
err |= __put_user((short)from->si_code, &to->si_code);
/* First 32bits of unions are always present. */
err |= __put_user(from->si_pid, &to->si_pid);
switch (from->si_code >> 16) {
case __SI_FAULT >> 16:
break;
case __SI_CHLD >> 16:
err |= __put_user(from->si_utime, &to->si_utime);
err |= __put_user(from->si_stime, &to->si_stime);
err |= __put_user(from->si_status, &to->si_status);
default:
err |= __put_user(from->si_uid, &to->si_uid);
break;
/* case __SI_RT: This is not generated by the kernel as of now. */
}
return err;
}
}
#endif
asmlinkage long
sys_rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo,
const struct timespec *uts, size_t sigsetsize)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment