Skip to content

Commit 4cd2e0e

Browse files
committed
signal: Introduce copy_siginfo_from_user and use it's return value
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" <ebiederm@xmission.com>
1 parent f283801 commit 4cd2e0e

3 files changed

Lines changed: 22 additions & 16 deletions

File tree

‎include/linux/signal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static inline void clear_siginfo(struct siginfo *info)
2222
}
2323

2424
int copy_siginfo_to_user(struct siginfo __user *to, const struct siginfo *from);
25+
int copy_siginfo_from_user(struct siginfo *to, const struct siginfo __user *from);
2526

2627
enum siginfo_layout {
2728
SIL_KILL,

‎kernel/ptrace.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -919,9 +919,8 @@ int ptrace_request(struct task_struct *child, long request,
919919
break;
920920

921921
case PTRACE_SETSIGINFO:
922-
if (copy_from_user(&siginfo, datavp, sizeof siginfo))
923-
ret = -EFAULT;
924-
else
922+
ret = copy_siginfo_from_user(&siginfo, datavp);
923+
if (!ret)
925924
ret = ptrace_setsiginfo(child, &siginfo);
926925
break;
927926

@@ -1215,10 +1214,9 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
12151214
break;
12161215

12171216
case PTRACE_SETSIGINFO:
1218-
if (copy_siginfo_from_user32(
1219-
&siginfo, (struct compat_siginfo __user *) datap))
1220-
ret = -EFAULT;
1221-
else
1217+
ret = copy_siginfo_from_user32(
1218+
&siginfo, (struct compat_siginfo __user *) datap);
1219+
if (!ret)
12221220
ret = ptrace_setsiginfo(child, &siginfo);
12231221
break;
12241222
#ifdef CONFIG_HAVE_ARCH_TRACEHOOK

‎kernel/signal.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,13 @@ int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
28962896
return 0;
28972897
}
28982898

2899+
int copy_siginfo_from_user(siginfo_t *to, const siginfo_t __user *from)
2900+
{
2901+
if (copy_from_user(to, from, sizeof(struct siginfo)))
2902+
return -EFAULT;
2903+
return 0;
2904+
}
2905+
28992906
#ifdef CONFIG_COMPAT
29002907
int copy_siginfo_to_user32(struct compat_siginfo __user *to,
29012908
const struct siginfo *from)
@@ -3323,8 +3330,9 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
33233330
siginfo_t __user *, uinfo)
33243331
{
33253332
siginfo_t info;
3326-
if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
3327-
return -EFAULT;
3333+
int ret = copy_siginfo_from_user(&info, uinfo);
3334+
if (unlikely(ret))
3335+
return ret;
33283336
return do_rt_sigqueueinfo(pid, sig, &info);
33293337
}
33303338

@@ -3365,10 +3373,9 @@ SYSCALL_DEFINE4(rt_tgsigqueueinfo, pid_t, tgid, pid_t, pid, int, sig,
33653373
siginfo_t __user *, uinfo)
33663374
{
33673375
siginfo_t info;
3368-
3369-
if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
3370-
return -EFAULT;
3371-
3376+
int ret = copy_siginfo_from_user(&info, uinfo);
3377+
if (unlikely(ret))
3378+
return ret;
33723379
return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
33733380
}
33743381

@@ -3380,9 +3387,9 @@ COMPAT_SYSCALL_DEFINE4(rt_tgsigqueueinfo,
33803387
struct compat_siginfo __user *, uinfo)
33813388
{
33823389
siginfo_t info;
3383-
3384-
if (copy_siginfo_from_user32(&info, uinfo))
3385-
return -EFAULT;
3390+
int ret = copy_siginfo_from_user32(&info, uinfo);
3391+
if (unlikely(ret))
3392+
return ret;
33863393
return do_rt_tgsigqueueinfo(tgid, pid, sig, &info);
33873394
}
33883395
#endif

0 commit comments

Comments
 (0)