Skip to contentSkip to conversation

yet another sparse-detected bug fix

DISCUSSION David Mosberger 3 participants 5 messages Oct 4, 2004 – Oct 5, 2004

lore
Share & tools
lore
#0 lore raw

Arun,

copy_siginfo_from_user32() directly dereferences a user-pointer, which is a no-no. At that point, to->si_code already has been initialized so I think we can just use to->si_code instead. Compile-tested (only) patch attached.

Signed-off-by [email protected]

=== arch/ia64/ia32/ia32_signal.c 1.30 vs edited ==--- 1.30/arch/ia64/ia32/ia32_signal.c 2004-09-21 12:36:02 -07:00
+++ edited/arch/ia64/ia32/ia32_signal.c 2004-10-04 07:38:03 -07:00
@@ -78,10 +78,10 @@
err |= __get_user(to->si_errno, &from->si_errno); err |= __get_user(to->si_code, &from->si_code);

- if (from->si_code < 0)
+ if (to->si_code < 0)
err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
else {
- switch (from->si_code >> 16) {
+ switch (to->si_code >> 16) {
case __SI_CHLD >> 16:
err |= __get_user(to->si_utime, &from->si_utime);
err |= __get_user(to->si_stime, &from->si_stime);

#1 lore raw

On 10/4/2004 8:45 AM, David Mosberger wrote:

Hi David,

Quoted 8 lines

Arun,

copy_siginfo_from_user32() directly dereferences a user-pointer, which is a no-no. At that point, to->si_code already has been initialized so I think we can just use to->si_code instead. Compile-tested (only) patch attached.

Signed-off-by [email protected]

I've been meaning to run sparse myself. But it wasn't very effective the last time I tried because of the missing __user annotations.

Please review the attached patches that add the missing annotations so that we can make it easy to spot these errors in the future.

-Arun

Index: linux-2.6-cvs/include/asm-ia64/uaccess.h
===================================================================
RCS file: /home/adsharma/disk2/cvs/linux-2.5/include/asm-ia64/uaccess.h,v retrieving revision 1.19

include/asm-ia64/uaccess.h +25 -16
diff -u -r1.19 uaccess.h
@@ -67,7 +67,7 @@
 #define access_ok(type, addr, size)	__access_ok((addr), (size), get_fs())
 
 static inline int
-verify_area (int type, const void *addr, unsigned long size)
+verify_area (int type, const void __user *addr, unsigned long size)
 {
 	return access_ok(type, addr, size) ? 0 : -EFAULT;
 }
@@ -185,7 +185,7 @@
  */
 #define __do_get_user(check, x, ptr, size, segment)					\
 ({											\
-	const __typeof__(*(ptr)) *__gu_ptr = (ptr);					\
+	const __typeof__(*(ptr)) __user *__gu_ptr = (ptr);				\
 	__typeof__ (size) __gu_size = (size);						\
 	long __gu_err = -EFAULT, __gu_val = 0;						\
 											\
@@ -213,7 +213,7 @@
 #define __do_put_user(check, x, ptr, size, segment)					\
 ({											\
 	__typeof__ (x) __pu_x = (x);							\
-	__typeof__ (*(ptr)) *__pu_ptr = (ptr);						\
+	__typeof__ (*(ptr)) __user *__pu_ptr = (ptr);					\
 	__typeof__ (size) __pu_size = (size);						\
 	long __pu_err = -EFAULT;							\
 											\
@@ -240,31 +240,40 @@
 #define __copy_from_user(to, from, n)	__copy_user((to), (from), (n))
 #define __copy_to_user_inatomic __copy_to_user
 #define __copy_from_user_inatomic __copy_from_user
-#define copy_to_user(to, from, n)	__copy_tofrom_user((to), (from), (n), 1)
-#define copy_from_user(to, from, n)	__copy_tofrom_user((to), (from), (n), 0)
 
-#define __copy_tofrom_user(to, from, n, check_to)					\
+#define copy_to_user(to, from, n)							\
 ({											\
-	void *__cu_to = (to);								\
+	void __user *__cu_to = (to);							\
 	const void *__cu_from = (from);							\
 	long __cu_len = (n);								\
 											\
-	if (__access_ok((long) ((check_to) ? __cu_to : __cu_from), __cu_len, get_fs()))	\
-		__cu_len = __copy_user(__cu_to, __cu_from, __cu_len);			\
+	if (__access_ok((long) __cu_to, __cu_len, get_fs()))				\
+		__cu_len = __copy_user((void *) __cu_to, __cu_from, __cu_len);		\
+	__cu_len;									\
+})
+
+#define copy_from_user(to, from, n)							\
+({											\
+	void *__cu_to = (to);								\
+	const void __user *__cu_from = (from);						\
+	long __cu_len = (n);								\
+											\
+	if (__access_ok((long) __cu_from, __cu_len, get_fs()))				\
+		__cu_len = __copy_user(__cu_to, (const void *) __cu_from, __cu_len);	\
 	__cu_len;									\
 })
 
 #define __copy_in_user(to, from, size)	__copy_user((to), (from), (size))
 
 static inline unsigned long
-copy_in_user (void *to, const void *from, unsigned long n)
+copy_in_user (void *to, const void __user *from, unsigned long n)
 {
 	if (likely(access_ok(VERIFY_READ, from, n) && access_ok(VERIFY_WRITE, to, n)))
 		n = __copy_user(to, from, n);
 	return n;
 }
 
-extern unsigned long __do_clear_user (void *, unsigned long);
+extern unsigned long __do_clear_user (void __user *, unsigned long);
 
 #define __clear_user(to, n)		__do_clear_user(to, n)
 
@@ -281,11 +290,11 @@
  * Returns: -EFAULT if exception before terminator, N if the entire buffer filled, else
  * strlen.
  */
-extern long __strncpy_from_user (char *to, const char *from, long to_len);
+extern long __strncpy_from_user (char *to, const char __user *from, long to_len);
 
 #define strncpy_from_user(to, from, n)					\
 ({									\
-	const char * __sfu_from = (from);				\
+	const char __user * __sfu_from = (from);				\
 	long __sfu_ret = -EFAULT;					\
 	if (__access_ok((long) __sfu_from, 0, get_fs()))		\
 		__sfu_ret = __strncpy_from_user((to), __sfu_from, (n));	\
@@ -293,11 +302,11 @@
 })
 
 /* Returns: 0 if bad, string length+1 (memory size) of string if ok */
-extern unsigned long __strlen_user (const char *);
+extern unsigned long __strlen_user (const char __user *);
 
 #define strlen_user(str)				\
 ({							\
-	const char *__su_str = (str);			\
+	const char __user *__su_str = (str);			\
 	unsigned long __su_ret = 0;			\
 	if (__access_ok((long) __su_str, 0, get_fs()))	\
 		__su_ret = __strlen_user(__su_str);	\
@@ -309,7 +318,7 @@
  * (N), a value greater than N if the limit would be exceeded, else
  * strlen.
  */
-extern unsigned long __strnlen_user (const char *, long);
+extern unsigned long __strnlen_user (const char __user *, long);
 
 #define strnlen_user(str, len)					\
 ({								\

Index: linux-2.6-cvs/arch/ia64/ia32/ia32_ldt.c
===================================================================
RCS file: /home/adsharma/disk2/cvs/linux-2.5/arch/ia64/ia32/ia32_ldt.c,v retrieving revision 1.5

arch/ia64/ia32/ia32_ldt.c +1 -1
diff -u -r1.5 ia32_ldt.c
@@ -126,7 +126,7 @@
 }
 
 asmlinkage int
-sys32_modify_ldt (int func, unsigned int ptr, unsigned int bytecount)
+sys32_modify_ldt (int func, unsigned int __user ptr, unsigned int bytecount)
 {
 	int ret = -ENOSYS;
 

Index: linux-2.6-cvs/arch/ia64/ia32/ia32_signal.c
===================================================================
RCS file: /home/adsharma/disk2/cvs/linux-2.5/arch/ia64/ia32/ia32_signal.c,v retrieving revision 1.22

arch/ia64/ia32/ia32_signal.c +18 -18
diff -u -r1.22 ia32_signal.c
@@ -66,7 +66,7 @@
 };
 
 int
-copy_siginfo_from_user32 (siginfo_t *to, siginfo_t32 *from)
+copy_siginfo_from_user32 (siginfo_t *to, siginfo_t32 __user *from)
 {
 	unsigned long tmp;
 	int err;
@@ -110,7 +110,7 @@
 }
 
 int
-copy_siginfo_to_user32 (siginfo_t32 *to, siginfo_t *from)
+copy_siginfo_to_user32 (siginfo_t32 __user *to, siginfo_t *from)
 {
 	unsigned int addr;
 	int err;
@@ -202,7 +202,7 @@
  */
 
 static int
-save_ia32_fpstate_live (struct _fpstate_ia32 *save)
+save_ia32_fpstate_live (struct _fpstate_ia32 __user *save)
 {
 	struct task_struct *tsk = current;
 	struct pt_regs *ptp;
@@ -310,7 +310,7 @@
 }
 
 static int
-restore_ia32_fpstate_live (struct _fpstate_ia32 *save)
+restore_ia32_fpstate_live (struct _fpstate_ia32 __user *save)
 {
 	struct task_struct *tsk = current;
 	struct pt_regs *ptp;
@@ -453,7 +453,7 @@
 }
 
 asmlinkage long
-ia32_rt_sigsuspend (compat_sigset_t *uset, unsigned int sigsetsize, struct sigscratch *scr)
+ia32_rt_sigsuspend (compat_sigset_t __user *uset, unsigned int sigsetsize, struct sigscratch *scr)
 {
 	extern long ia64_do_signal (sigset_t *oldset, struct sigscratch *scr, long in_syscall);
 	sigset_t oldset, set;
@@ -512,8 +512,8 @@
 }
 
 asmlinkage long
-sys32_rt_sigaction (int sig, struct sigaction32 *act,
-		    struct sigaction32 *oact, unsigned int sigsetsize)
+sys32_rt_sigaction (int sig, struct sigaction32 __user *act,
+		    struct sigaction32 __user *oact, unsigned int sigsetsize)
 {
 	struct k_sigaction new_ka, old_ka;
 	unsigned int handler, restorer;
@@ -547,7 +547,7 @@
 
 
 asmlinkage long
-sys32_rt_sigprocmask (int how, compat_sigset_t *set, compat_sigset_t *oset, unsigned int sigsetsize)
+sys32_rt_sigprocmask (int how, compat_sigset_t __user *set, compat_sigset_t __user *oset, unsigned int sigsetsize)
 {
 	mm_segment_t old_fs = get_fs();
 	sigset_t s;
@@ -574,8 +574,8 @@
 }
 
 asmlinkage long
-sys32_rt_sigtimedwait (compat_sigset_t *uthese, siginfo_t32 *uinfo,
-		struct compat_timespec *uts, unsigned int sigsetsize)
+sys32_rt_sigtimedwait (compat_sigset_t __user *uthese, siginfo_t32 __user *uinfo,
+		struct compat_timespec __user *uts, unsigned int sigsetsize)
 {
 	extern int copy_siginfo_to_user32 (siginfo_t32 *, siginfo_t *);
 	mm_segment_t old_fs = get_fs();
@@ -600,7 +600,7 @@
 }
 
 asmlinkage long
-sys32_rt_sigqueueinfo (int pid, int sig, siginfo_t32 *uinfo)
+sys32_rt_sigqueueinfo (int pid, int sig, siginfo_t32 __user *uinfo)
 {
 	mm_segment_t old_fs = get_fs();
 	siginfo_t info;
@@ -615,7 +615,7 @@
 }
 
 asmlinkage long
-sys32_sigaction (int sig, struct old_sigaction32 *act, struct old_sigaction32 *oact)
+sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
 {
 	struct k_sigaction new_ka, old_ka;
 	unsigned int handler, restorer;
@@ -648,7 +648,7 @@
 }
 
 static int
-setup_sigcontext_ia32 (struct sigcontext_ia32 *sc, struct _fpstate_ia32 *fpstate,
+setup_sigcontext_ia32 (struct sigcontext_ia32 __user *sc, struct _fpstate_ia32 __user *fpstate,
 		       struct pt_regs *regs, unsigned long mask)
 {
 	int  err = 0;
@@ -705,7 +705,7 @@
 }
 
 static int
-restore_sigcontext_ia32 (struct pt_regs *regs, struct sigcontext_ia32 *sc, int *peax)
+restore_sigcontext_ia32 (struct pt_regs *regs, struct sigcontext_ia32 __user *sc, int *peax)
 {
 	unsigned int err = 0;
 
@@ -830,7 +830,7 @@
 setup_frame_ia32 (int sig, struct k_sigaction *ka, sigset_t *set, struct pt_regs * regs)
 {
 	struct exec_domain *ed = current_thread_info()->exec_domain;
-	struct sigframe_ia32 *frame;
+	struct sigframe_ia32 __user *frame;
 	int err = 0;
 
 	frame = get_sigframe(ka, regs, sizeof(*frame));
@@ -896,7 +896,7 @@
 		     sigset_t *set, struct pt_regs * regs)
 {
 	struct exec_domain *ed = current_thread_info()->exec_domain;
-	struct rt_sigframe_ia32 *frame;
+	struct rt_sigframe_ia32 __user *frame;
 	int err = 0;
 
 	frame = get_sigframe(ka, regs, sizeof(*frame));
@@ -982,7 +982,7 @@
 {
 	struct pt_regs *regs = (struct pt_regs *) &stack;
 	unsigned long esp = (unsigned int) regs->r12;
-	struct sigframe_ia32 *frame = (struct sigframe_ia32 *)(esp - 8);
+	struct sigframe_ia32 __user *frame = (struct sigframe_ia32 *)(esp - 8);
 	sigset_t set;
 	int eax;
 
@@ -1015,7 +1015,7 @@
 {
 	struct pt_regs *regs = (struct pt_regs *) &stack;
 	unsigned long esp = (unsigned int) regs->r12;
-	struct rt_sigframe_ia32 *frame = (struct rt_sigframe_ia32 *)(esp - 4);
+	struct rt_sigframe_ia32 __user *frame = (struct rt_sigframe_ia32 *)(esp - 4);
 	sigset_t set;
 	stack_t st;
 	int eax;

Index: linux-2.6-cvs/arch/ia64/ia32/sys_ia32.c
===================================================================
RCS file: /home/adsharma/disk2/cvs/linux-2.5/arch/ia64/ia32/sys_ia32.c,v retrieving revision 1.72

arch/ia64/ia32/sys_ia32.c +38 -38

302 lines not on this page · raw message

#2 lore raw
In reply to David Mosberger
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Arun Sharma

Arun> On 10/4/2004 8:45 AM, David Mosberger wrote:
Arun> Hi David,

Quoted 8 lines
Quoted 8 lines

Arun,

copy_siginfo_from_user32() directly dereferences a user-pointer, which is a no-no. At that point, to->si_code already has been initialized so I think we can just use to->si_code instead. Compile-tested (only) patch attached.

Signed-off-by [email protected]

Arun> I've been meaning to run sparse myself. But it wasn't very effective the last time I tried because of the missing __user annotations.

Arun> Please review the attached patches that add the missing Arun> annotations so that we can make it easy to spot these errors Arun> in the future.

I'm confused. I posted a sparse-enablement patch yesterday. Was there something wrong with that one?

	--david
#3 lore raw
In reply to David Mosberger
Quoted 2 lines

I'm confused. I posted a sparse-enablement patch yesterday. Was there something wrong with that one?

I can't tell ... I haven't seen it (none of the sparse patches that I've received match the diffstat that you sent for it today ... and I checked the "marc.theaimsgroup.com" archive too, it isn't there either). Please resend.

-Tony

#4 lore raw
In reply to David Mosberger
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Tony

I'm confused. I posted a sparse-enablement patch yesterday. Was there something wrong with that one?

Tony> I can't tell ... I haven't seen it (none of the sparse patches Tony> that I've received match the diffstat that you sent for it Tony> today ... and I checked the "marc.theaimsgroup.com" archive Tony> too, it isn't there either). Please resend.

Something seems to be silently dropping mails with large patches. Mine was just a bit over 100KB, so this seems plausible. I'm just not sure whether it's vger or something in between.

Anyhow, I split up the patches and sent them separately anyhow since I think they're in good enough shape that we can at least think about merging them.

	--david