unix: Fix uipc_peeraddr() to handle self-connected sockets

Reported by:	syzbot+c2da2dbae5fe006556bc@syzkaller.appspotmail.com
Reported by:	syzbot+b4d6b093b1d78bfa859b@syzkaller.appspotmail.com
Fixes:		e8f6e5b2d9 ("unix: Fix locking in uipc_peeraddr()")
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mark Johnston 2023-06-21 14:20:16 -04:00
parent 586164cc09
commit 712079d381

View File

@ -890,16 +890,16 @@ uipc_peeraddr(struct socket *so, struct sockaddr **nam)
unp2 = unp_pcb_lock_peer(unp);
if (unp2 != NULL) {
if (unp2->unp_addr != NULL)
sa = (struct sockaddr *) unp2->unp_addr;
sa = (struct sockaddr *)unp2->unp_addr;
else
sa = &sun_noname;
bcopy(sa, *nam, sa->sa_len);
UNP_PCB_UNLOCK(unp2);
unp_pcb_unlock_pair(unp, unp2);
} else {
sa = &sun_noname;
bcopy(sa, *nam, sa->sa_len);
UNP_PCB_UNLOCK(unp);
}
UNP_PCB_UNLOCK(unp);
return (0);
}