Skip to contentSkip to conversation

Please review. Generic changes required for siginfo_t compat on 64-bit arches.

parisc-linux Carlos O'Donell 1 participant 1 message Apr 30, 2004 1 message not in the archive ptrace support

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 53 lines · Carlos O'Donell

----------------------------------------
Linux Kernel - siginfo_t compat 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 the siginfo_t out of userspace.

This change adds the requires compat checks in generic places, and uses the previously implemented is_compat_task macro to remove this code when there is no possibility of a compat task.

----------------------------------------
include/linux/compat_siginfo.h

Cleanup and make more consistent with compat_* types. Make __ARCH_SI_UID_T the 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_getsiginfo and sys_rt_sigqueueinfo, since both functions read siginfo_t from userspace. This function copies up a siginfo_t to 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 using copy_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_user to load a siginfo_t from userspace.

Quoted 6 lines

kernel/ptrace.c

(ptrace_getsiginfo)

Call copy_siginfo_from_user to load a siginfo_t from 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
diff -u -p -r1.3 -r1.4
@@ -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
diff -u -p -r1.4 -r1.5
@@ -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
diff -u -p -r1.18 -r1.19
@@ -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 __use
 		return __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.