From 6d06bc688eb5a9f9e389b69c388d591a40edc422 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Sun, 9 Jan 2022 07:09:22 +0200 Subject: [PATCH] libc clnt_com_create: relock rpcsoc_lock earlier when port is obtained from portmapper Otherwise on mapper failure we goto error handler which expect rpscoc_lock owned, but we do not. PR: 261051 Reported by: RyanCai Sponsored by: The FreeBSD Foundation MFC after: 1 week --- 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 */