git: 42f2fa9953da - main - sockets: don't call dom_dispose() on a listening socket

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Mon, 09 May 2022 17:55:10 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=42f2fa9953da13678b30942afc84e7e9fdd7c43e

commit 42f2fa9953da13678b30942afc84e7e9fdd7c43e
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-05-09 17:42:57 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2022-05-09 17:42:57 +0000

    sockets: don't call dom_dispose() on a listening socket
    
    sorflush() already did the right thing, so only sofree() needed
    a fix.  Turn check into assertion in our only dom_dispose method.
    
    Reviewed by:            markj
    Differential revision:  https://reviews.freebsd.org/D35124
---
 sys/kern/uipc_socket.c | 2 +-
 sys/kern/uipc_usrreq.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 029f7c8387ca..299610477068 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1195,7 +1195,7 @@ sofree(struct socket *so)
 		so->so_dtor(so);
 
 	VNET_SO_ASSERT(so);
-	if (pr->pr_flags & PR_RIGHTS) {
+	if ((pr->pr_flags & PR_RIGHTS) && !SOLISTENING(so)) {
 		MPASS(pr->pr_domain->dom_dispose != NULL);
 		(*pr->pr_domain->dom_dispose)(so);
 	}
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 3ce7ddcd7f17..d56922c6fa3a 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -2769,12 +2769,13 @@ unp_dispose(struct socket *so)
 {
 	struct unpcb *unp;
 
+	MPASS(!SOLISTENING(so));
+
 	unp = sotounpcb(so);
 	UNP_LINK_WLOCK();
 	unp->unp_gcflag |= UNPGC_IGNORE_RIGHTS;
 	UNP_LINK_WUNLOCK();
-	if (!SOLISTENING(so))
-		unp_dispose_mbuf(so->so_rcv.sb_mb);
+	unp_dispose_mbuf(so->so_rcv.sb_mb);
 }
 
 static void