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
This commit is contained in:
Mateusz Guzik 2018-11-21 22:25:05 +00:00
parent a627b4629d
commit f218ac5087
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=340749

View File

@ -530,6 +530,7 @@ uipc_attach(struct socket *so, int proto, struct thread *td)
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);
}