svn commit: r340749 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Wed Nov 21 22:25:06 UTC 2018


Author: mjg
Date: Wed Nov 21 22:25:05 2018
New Revision: 340749
URL: https://svnweb.freebsd.org/changeset/base/340749

Log:
  uipc_usrreq: fix inode number assignment
  
  The code was incrementing a global variable in an unsafe manner.
  Two different threads stating two different sockets could have resulted
  in the same inode numbers assigned to both.
  
  Creation is protected with a global lock, move the assigment there.
  Since inode numbers are 64-bit now drop the check for overflows.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/uipc_usrreq.c

Modified: head/sys/kern/uipc_usrreq.c
==============================================================================
--- head/sys/kern/uipc_usrreq.c	Wed Nov 21 22:16:10 2018	(r340748)
+++ head/sys/kern/uipc_usrreq.c	Wed Nov 21 22:25:05 2018	(r340749)
@@ -530,6 +530,7 @@ uipc_attach(struct socket *so, int proto, struct threa
 		UNP_LINK_WLOCK();
 
 	unp->unp_gencnt = ++unp_gencnt;
+	unp->unp_ino = ++unp_ino;
 	unp_count++;
 	switch (so->so_type) {
 	case SOCK_STREAM:
@@ -1302,12 +1303,8 @@ uipc_sense(struct socket *so, struct stat *sb)
 	KASSERT(unp != NULL, ("uipc_sense: unp == NULL"));
 
 	sb->st_blksize = so->so_snd.sb_hiwat;
-	UNP_PCB_LOCK(unp);
 	sb->st_dev = NODEV;
-	if (unp->unp_ino == 0)
-		unp->unp_ino = (++unp_ino == 0) ? ++unp_ino : unp_ino;
 	sb->st_ino = unp->unp_ino;
-	UNP_PCB_UNLOCK(unp);
 	return (0);
 }
 


More information about the svn-src-all mailing list