patch-1.3.96 linux/net/socket.c

Next file: linux/scripts/lxdialog/menubox.c
Previous file: linux/net/ipv4/tcp.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.95/linux/net/socket.c linux/net/socket.c
@@ -1137,8 +1137,9 @@
 	if(msg_sys.msg_iovlen>MAX_IOVEC)
 		return -EINVAL;
 
-	err=verify_iovec(&msg_sys,iov,address, VERIFY_READ);
-	if(err<0)
+	/* This will also move the address data into kernel space */
+	err = verify_iovec(&msg_sys, iov, address, VERIFY_READ);
+	if (err < 0)
 		return err;
 	total_len=err;
 
@@ -1153,13 +1154,19 @@
 {
 	struct socket *sock;
 	struct file *file;
-	char address[MAX_SOCK_ADDR];
 	struct iovec iov[MAX_IOVEC];
 	struct msghdr msg_sys;
 	int err;
 	int total_len;
-	int addr_len;
 	int len;
+
+	/* kernel mode address */
+	char addr[MAX_SOCK_ADDR];
+	int addr_len;
+
+	/* user mode address pointers */
+	struct sockaddr *uaddr;
+	int *uaddr_len;
 	
 	if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 		return(-EBADF);
@@ -1172,9 +1179,17 @@
 	memcpy_fromfs(&msg_sys,msg,sizeof(struct msghdr));
 	if(msg_sys.msg_iovlen>MAX_IOVEC)
 		return -EINVAL;
-	err=verify_iovec(&msg_sys,iov,address, VERIFY_WRITE);
+
+	/*
+	 * save the user-mode address (verify_iovec will change the
+	 * kernel msghdr to use the kernel address space)
+	 */
+	uaddr = msg_sys.msg_name;
+	uaddr_len = &msg->msg_namelen;
+	err=verify_iovec(&msg_sys,iov,addr, VERIFY_WRITE);
 	if(err<0)
 		return err;
+
 	total_len=err;
 	
 	if(sock->ops->recvmsg==NULL)
@@ -1182,11 +1197,12 @@
 	len=sock->ops->recvmsg(sock, &msg_sys, total_len, (file->f_flags&O_NONBLOCK), flags, &addr_len);
 	if(len<0)
 		return len;
-	/*
-	 *	Fixme: writing actual length into original msghdr.
-	 */
-	if(msg_sys.msg_name!=NULL && (err=move_addr_to_user(address,addr_len, msg_sys.msg_name, &msg_sys.msg_namelen))<0)
-		return err;
+
+	if (uaddr != NULL) {
+		err = move_addr_to_user(addr, addr_len, uaddr, uaddr_len);
+		if (err)
+			return err;
+	}
 	return len;
 }
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this