git: ac82aa1bf742 - stable/12 - libc clnt_com_create: relock rpcsoc_lock earlier when port is obtained from portmapper

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sat, 15 Jan 2022 12:58:28 UTC
The branch stable/12 has been updated by kib:

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

commit ac82aa1bf742def55998d27e98496b46c18cfcd5
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-01-09 05:09:22 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-01-15 12:57:40 +0000

    libc clnt_com_create: relock rpcsoc_lock earlier when port is obtained from portmapper
    
    PR:     261051
    
    (cherry picked from commit 6d06bc688eb5a9f9e389b69c388d591a40edc422)
---
 lib/libc/rpc/rpc_soc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/libc/rpc/rpc_soc.c b/lib/libc/rpc/rpc_soc.c
index 1e5cd86d7ed4..ae23442e9a16 100644
--- a/lib/libc/rpc/rpc_soc.c
+++ b/lib/libc/rpc/rpc_soc.c
@@ -120,11 +120,11 @@ clnt_com_create(struct sockaddr_in *raddr, rpcprog_t prog, rpcvers_t vers, int *
 		proto = strcmp(tp, "udp") == 0 ? IPPROTO_UDP : IPPROTO_TCP;
 		sport = pmap_getport(raddr, (u_long)prog, (u_long)vers,
 		    proto);
+		mutex_lock(&rpcsoc_lock);	/* pmap_getport is recursive */
 		if (sport == 0) {
 			goto err;
 		}
 		raddr->sin_port = htons(sport);
-		mutex_lock(&rpcsoc_lock);	/* pmap_getport is recursive */
 	}
 
 	/* Transform sockaddr_in to netbuf */