Skip to content

Commit

Permalink
signal: Introduce copy_siginfo_from_user and use it's return value
Browse files Browse the repository at this point in the history
In preparation for using a smaller version of siginfo in the kernel
introduce copy_siginfo_from_user and use it when siginfo is copied from
userspace.

Make the pattern for using copy_siginfo_from_user and
copy_siginfo_from_user32 to capture the return value and return that
value on error.

This is a necessary prerequisite for using a smaller siginfo
in the kernel than the kernel exports to userspace.

Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed Oct 3, 2018
1 parent f283801 commit 4cd2e0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/linux/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static inline void clear_siginfo(struct siginfo *info)
}

int copy_siginfo_to_user(struct siginfo __user *to, const struct siginfo *from);
int copy_siginfo_from_user(struct siginfo *to, const struct siginfo __user *from);

enum siginfo_layout {
SIL_KILL,
Expand Down
12 changes: 5 additions & 7 deletions kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,8 @@ int ptrace_request(struct task_struct *child, long request,
break;

case PTRACE_SETSIGINFO:
if (copy_from_user(&siginfo, datavp, sizeof siginfo))
ret = -EFAULT;
else
ret = copy_siginfo_from_user(&siginfo, datavp);
if (!ret)
ret = ptrace_setsiginfo(child, &siginfo);
break;

Expand Down Expand Up @@ -1215,10 +1214,9 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
break;

case PTRACE_SETSIGINFO:
if (copy_siginfo_from_user32(
&siginfo, (struct compat_siginfo __user *) datap))
ret = -EFAULT;
else
ret = copy_siginfo_from_user32(
&siginfo, (struct compat_siginfo __user *) datap);
if (!ret)
ret = ptrace_setsiginfo(child, &siginfo);
break;
#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
Expand Down
25 changes: 16 additions & 9 deletions kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,13 @@ int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
return 0;
}

int copy_siginfo_from_user(siginfo_t *to, const siginfo_t __user *from)
{
if (copy_from_user(to, from, sizeof(struct siginfo)))
return -EFAULT;
return 0;
}

#ifdef CONFIG_COMPAT
int copy_siginfo_to_user32(struct compat_siginfo __user *to,
const struct siginfo *from)
Expand Down Expand Up @@ -3323,8 +3330,9 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
siginfo_t __user *, uinfo)
{
siginfo_t info;
if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
return -EFAULT;
int ret = copy_siginfo_from_user(&info, uinfo);
if (unlikely(ret))
return ret;
return do_rt_sigqueueinfo(pid, sig, &info);
}

Expand Down Expand Up @@ -3365,10 +3373,9 @@ SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig,
siginfo_t __user *, uinfo)
{
siginfo_t info;

if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
return -EFAULT;

int ret = copy_siginfo_from_user(&info, uinfo);
if (unlikely(ret))
return ret;
return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
}

Expand All @@ -3380,9 +3387,9 @@ COMPAT_SYSCALL_DEFINE4(rt_tgsigqueueinfo,
struct compat_siginfo __user *, uinfo)
{
siginfo_t info;

if (copy_siginfo_from_user32(&info, uinfo))
return -EFAULT;
int ret = copy_siginfo_from_user32(&info, uinfo);
if (unlikely(ret))
return ret;
return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
}
#endif
Expand Down

0 comments on commit 4cd2e0e

Please sign in to comment.