Please review. Generic changes required for siginfo_t compat on 64-bit arches.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 53 lines · Carlos O'Donell
----------------------------------------
Linux Kernel -siginfo_tcompat changes
----------------------------------------The Linuxthreads implementation of posix-threads uses
rt_sigqueueinfo. This is broken for 64-bit kernels running 32-bit userspace. It requires that kernel check for a compat task and properly copy thesiginfo_tout of userspace.This change adds the requires compat checks in generic places, and uses the previously implemented
is_compat_taskmacro to remove this code when there is no possibility of a compat task.----------------------------------------
include/linux/compat_siginfo.hCleanup and make more consistent with compat_* types. Make
__ARCH_SI_UID_Tthe correct compat type.
kernel/compat_signal.c(
compat_copy_siginfo_to_user)Always copy the first three words, the kernel uses these and we might need them later. Only copy the _sifields._pad when the structure is from userspace.
(
compat_copy_siginfo_from_user)A brand new function that is going to be used by
ptrace_getsiginfoandsys_rt_sigqueueinfo, since both functions readsiginfo_tfrom userspace. This function copies up asiginfo_tto the proper kernel size.
kernel/signal.c(
copy_siginfo_from_user)If the task is compat use the compat version e.g.
compat_copy_siginfo_from_user, else fall back to usingcopy_from_user.(
copy_siginfo_to_user)Move the compat check to the start of the function, that way we don't duplicate the access check.
(
sys_rt_sigqueueinfo)Call
copy_siginfo_from_userto load asiginfo_tfrom userspace.
Quoted 6 lines
kernel/ptrace.c(
ptrace_getsiginfo)Call
copy_siginfo_from_userto load asiginfo_tfrom userspace.
The log message says it all. We have working posix-timers with 64-bit kernels, by virtue of a working rt_sigqueueinfo. I wonder if this fixes more things on 64-bit boxes.
Index: include/linux/compat_siginfo.h
===================================================================
RCS file: /var/cvs/linux-2.6/include/linux/compat_siginfo.h,v retrieving revision 1.3
retrieving revision 1.4
include/linux/compat_siginfo.h +5 -3
@@ -33,12 +33,13 @@ typedef union compat_sigval {* struct siginfo that is before the union. */ #ifndef __ARCH_SI_COMPAT_PREAMBLE_SIZE -#define __ARCH_SI_COMPAT_PREAMBLE_SIZE (3 * sizeof(int)) +#define __ARCH_SI_COMPAT_PREAMBLE_SIZE (3 * sizeof(compat_int_t))#endif #define SI_COMPAT_MAX_SIZE 128#ifndef SI_COMPAT_PAD_SIZE -#define SI_COMPAT_PAD_SIZE ((SI_COMPAT_MAX_SIZE - __ARCH_SI_COMPAT_PREAMBLE_SIZE) / sizeof(int)) +#define SI_COMPAT_PAD_SIZE \ + ((SI_COMPAT_MAX_SIZE - __ARCH_SI_COMPAT_PREAMBLE_SIZE) / sizeof(compat_int_t))#endif /* 32-bit view of si.uid_t */
@@ -72,7 +73,7 @@ typedef struct compat_siginfo {struct {compat_timer_t _tid;/* timer id */ compat_int_t _overrun;/* overrun count */ -char _pad[sizeof ( __ARCH_SI_UID_T) -sizeof (int )]; +char _pad[sizeof (__ARCH_SI_COMPAT_UID_T) -sizeof (compat_int_t)];compat_sigval_t _sigval;/* same as below */ compat_int_t _sys_private;/* not to be passed to user */ } _timer;
@@ -164,6 +165,7 @@ static inline void compat_copy_siginfo(s#endif /* !HAVE_ARCH_COMPAT_COPY_SIGINFO */ extern int compat_copy_siginfo_to_user (compat_siginfo_t __user *to,struct siginfo *from); +extern int compat_copy_siginfo_from_user (struct siginfo *to,compat_siginfo_t __user *from);#endif /* CONFIG_COMPAT */ #endif /* _ASM_GENERIC_COMPAT_SIGINFO_H */
Index: kernel/compat_signal.c
===================================================================
RCS file: /var/cvs/linux-2.6/kernel/compat_signal.c,v retrieving revision 1.3
retrieving revision 1.4
kernel/compat_signal.c +86 -5
109 lines not on this page · raw message
Index: kernel/ptrace.c
===================================================================
RCS file: /var/cvs/linux-2.6/kernel/ptrace.c,v
retrieving revision 1.4
retrieving revision 1.5
kernel/ptrace.c +1 -1
@@ -290,7 +290,7 @@ static int ptrace_setsiginfo(struct task {if (child->last_siginfo ==NULL )return -EINVAL ; -if (copy_from_user (child->last_siginfo, data,sizeof (siginfo_t)) !=0 ) +if (copy_siginfo_from_user (child->last_siginfo, data) !=0 )return -EFAULT ;return 0 ; }
Index: kernel/signal.c
===================================================================
RCS file: /var/cvs/linux-2.6/kernel/signal.c,v
retrieving revision 1.18
retrieving revision 1.19
kernel/signal.c +18 -6
@@ -2018,11 +2018,28 @@ sys_rt_sigpending(sigset_t __user *set,return do_sigpending (set, sigsetsize); } +#ifndef HAVE_ARCH_COPY_SIGINFO_FROM_USER + +int copy_siginfo_from_user (siginfo_t *to,siginfo_t __user *from) +{ +if (is_compat_task (current)) +return compat_copy_siginfo_from_user (to,(compat_siginfo_t __user *)from); + +return copy_from_user (&to, from,sizeof (siginfo_t)); +} + +#endif +#ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER int copy_siginfo_to_user (siginfo_t __user *to,siginfo_t *from) {int err; + +/* Use compat_siginfo_t with 32-bit signals */ +if (is_compat_task (current)){ +return compat_copy_siginfo_to_user ((compat_siginfo_t __user *)to,from); + }if (!access_ok (VERIFY_WRITE , to,sizeof (siginfo_t)))return -EFAULT ;
@@ -2030,11 +2047,6 @@ int copy_siginfo_to_user(siginfo_t __usereturn __copy_to_user (to, from,sizeof (siginfo_t)) ? -EFAULT :0 ; -/* Use compat_siginfo_t with 32-bit signals */ -if (is_compat_task (current)){ -return compat_copy_siginfo_to_user ((compat_siginfo_t __user *)to,from); - } -/* * If you change siginfo_t structure, please be sure * this code is fixed accordingly.
@@ -2271,7 +2283,7 @@ sys_rt_sigqueueinfo(int pid, int sig, si {siginfo_t info; -if (copy_from_user (&info, uinfo,sizeof (siginfo_t))) +if (copy_siginfo_from_user (&info, uinfo))return -EFAULT ;/* Not even root can pretend to send signals from the kernel.