Bug 2138317

Summary: clnt_raw.c: possibly null pointer dereference in clnt_raw_freeres()
Product: Red Hat Enterprise Linux 9 Reporter: Zhi Li <yieli>
Component: libtirpcAssignee: Steve Dickson <steved>
Status: CLOSED ERRATA QA Contact: Zhi Li <yieli>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.2CC: xzhou
Target Milestone: rcKeywords: Patch, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libtirpc-1.3.3-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 08:19:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Zhi Li 2022-10-28 05:28:57 UTC
Description of problem:

Possibly null pointer dereference in clnt_raw_freeres() of /root/libtirpc-1.3.3/src/clnt_raw.c

 240 /* ARGSUSED */
 241 static bool_t
 242 clnt_raw_freeres(cl, xdr_res, res_ptr)
 243         CLIENT *cl;
 244         xdrproc_t xdr_res;
 245         void *res_ptr;
 246 {
 247         struct clntraw_private *clp = clntraw_private;
 248         XDR *xdrs = &clp->xdr_stream;    // << pointer clp could be NULL here
 249         bool_t rval;
 250
 251         mutex_lock(&clntraw_lock);
 252         if (clp == NULL) {
 253                 rval = (bool_t) RPC_FAILED;
 254                 mutex_unlock(&clntraw_lock);
 255                 return (rval);
 256         }
 257         mutex_unlock(&clntraw_lock);
 258         xdrs->x_op = XDR_FREE;
 259         return ((*xdr_res)(xdrs, res_ptr));
 260 }

captured from clang-static-analyzer

Since the mutex clntraw_lock exists in multiple functions, and the valid structure of clntraw_private is allocated in clnt_raw_create(), who shares the same mutex with clnt_raw_freeres(), if that function is invoked before clnt_raw_create() in parallel or serial manner, the dereference of clp could lead to a null pointer reference.

  76 /*
  77  * Create a client handle for memory based rpc.
  78  */
  79 CLIENT *
  80 clnt_raw_create(prog, vers)
  81         rpcprog_t prog;
  82         rpcvers_t vers;
  83 {
  84         struct clntraw_private *clp;
  85         struct rpc_msg call_msg;
  86         XDR *xdrs;
  87         CLIENT  *client;
  88
  89         mutex_lock(&clntraw_lock);
  90         clp = clntraw_private;
  91         if (clp == NULL) {
  92                 clp = (struct clntraw_private *)calloc(1, sizeof (*clp)); // clntraw_private allocated here
  93                 if (clp == NULL) {
  94                         mutex_unlock(&clntraw_lock);
  95                         return NULL;
  96                 }
  97                 if (__rpc_rawcombuf == NULL)
  98                         __rpc_rawcombuf =
  99                             (char *)calloc(UDPMSGSIZE, sizeof (char));
 100                 clp->_raw_buf = __rpc_rawcombuf;
 101                 clntraw_private = clp;
 102         }
 103         xdrs = &clp->xdr_stream;
 104         client = &clp->client_object;
-- snip --


Version-Release number of selected component (if applicable):
libtirpc-1.1.3.el9

Comment 1 Steve Dickson 2022-10-28 18:31:27 UTC
commit 4a2d85c64110ee9e21a8c4f9dafd6b0ae621506d
Author: Zhi Li <yieli>
Date:   Fri Oct 28 14:19:04 2022 -0400

    clnt_raw.c: fix a possible null pointer dereference

Comment 6 errata-xmlrpc 2023-05-09 08:19:31 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (libtirpc bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2506