git: 07d32ede469d - stable/13 - 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 00:51:50 UTC
The branch stable/13 has been updated by kib:

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

commit 07d32ede469ddc85b7e92921b4a9f1eeb4dbd66f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-01-09 05:09:22 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-01-15 00:51:13 +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 */