[parisc-linux-cvs] linux-2.5 tausq

Randolph Chung Randolph Chung <randolph@tausq.org>
Sun, 30 Mar 2003 18:31:21 -0800


> fix compat_sys_setsockopt with SO_ATTACH_FILTER

Index: net/compat.c
===================================================================
RCS file: /var/cvs/linux-2.5/net/compat.c,v
retrieving revision 1.3
diff -u -p -r1.3 compat.c
--- net/compat.c	25 Mar 2003 03:20:26 -0000	1.3
+++ net/compat.c	30 Mar 2003 02:47:23 -0000
@@ -496,6 +496,8 @@ static int do_set_attach_filter(int fd, 
 	struct sock_fprog kfprog;
 	mm_segment_t old_fs;
 	compat_uptr_t uptr;
+	struct sock_filter *kfilter;
+	unsigned int fsize;
 	int ret;
 
 	if (!access_ok(VERIFY_READ, fprog32, sizeof(*fprog32)) ||
@@ -504,6 +506,18 @@ static int do_set_attach_filter(int fd, 
 		return -EFAULT;
 
 	kfprog.filter = compat_ptr(uptr);
+	fsize = kfprog.len * sizeof(struct sock_filter);
+
+	kfilter = (struct sock_filter *)kmalloc(fsize, GFP_KERNEL);
+	if (kfilter == NULL)
+		return -ENOMEM;
+
+	if (copy_from_user(kfilter, kfprog.filter, fsize)) {
+		kfree(kfilter);
+		return -EFAULT;
+	}
+
+	kfprog.filter = kfilter;
 	/*
 	 * Since struct sock_filter is architecure independent,
 	 * we can just do the access_ok check and pass the
@@ -518,6 +532,7 @@ static int do_set_attach_filter(int fd, 
 	ret = sys_setsockopt(fd, level, optname,
 			     (char *)&kfprog, sizeof(kfprog));
 	set_fs(old_fs);
+	kfree(kfilter);
 
 	return ret;
 }

-- 
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/