patch-2.1.43 linux/net/socket.c

Next file: linux/net/sysctl_net.c
Previous file: linux/net/rose/af_rose.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.42/linux/net/socket.c linux/net/socket.c
@@ -212,7 +212,7 @@
 		file->f_flags = O_RDWR;
 		file->f_inode = inode;
 		if (inode) 
-			inode->i_count++;
+			atomic_inc(&inode->i_count);
 		file->f_pos = 0;
 	}
 	return fd;
@@ -797,6 +797,7 @@
 	int len;
 
 	lock_kernel();
+restart:
   	if ((sock = sockfd_lookup(fd, &err))!=NULL)
   	{
 		if (!(newsock = sock_alloc())) 
@@ -834,7 +835,13 @@
 	
 		if (upeer_sockaddr)
 		{
-			newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 1);
+			/* Handle the race where the accept works and we
+			   then getname after it has closed again */
+			if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 1)<0)
+			{
+				sys_close(err);
+				goto restart;
+			}
 			move_addr_to_user(address,len, upeer_sockaddr, upeer_addrlen);
 		}
 out:

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov