RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1624542 - Fix use-after-free in rpc.statd monitor list when insertion fails for existing entry
Summary: Fix use-after-free in rpc.statd monitor list when insertion fails for existin...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: nfs-utils
Version: 7.5
Hardware: Unspecified
OS: Unspecified
medium
unspecified
Target Milestone: rc
: ---
Assignee: Steve Dickson
QA Contact: Yongcheng Yang
URL:
Whiteboard:
Depends On:
Blocks: 1577173
TreeView+ depends on / blocked
 
Reported: 2018-09-01 05:12 UTC by Frank Sorenson
Modified: 2021-12-10 17:16 UTC (History)
4 users (show)

Fixed In Version: nfs-utils-1.3.0-0.62.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-08-06 13:11:50 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
patch to fix statd use-after-free (821 bytes, text/plain)
2018-09-01 05:12 UTC, Frank Sorenson
no flags Details
reproducer for bz1624542 (1.22 KB, application/x-shellscript)
2018-09-03 17:32 UTC, Frank Sorenson
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2019:2268 0 None None None 2019-08-06 13:11:59 UTC

Description Frank Sorenson 2018-09-01 05:12:44 UTC
Created attachment 1480181 [details]
patch to fix statd use-after-free

Description of problem:

If nsm_insert_monitored_host() fails while saving the record to stable storage, we currently just free the entry and return with error.  This can lead to a use-after-free, causing rpc.statd to crash.

We can't just assume the entry was new. Existing records must be removed from the list before being freed.


Version-Release number of selected component (if applicable):

all


How reproducible:

easy


Steps to Reproduce:

using the test program nsm_client:

# /tmp/nsm_client mon client1 1
# /tmp/nsm_client mon client2 1

chown -R root:root /var/lib/nfs/statd/sm{,.bak}

# /tmp/nsm_client mon client1 2


Actual results:

use-after-free; potential crash of statd


Expected results:

entry is removed from the list


Additional info:

the entry is allocated in nlist_new:

notify_list *
nlist_new(char *my_name, char *mon_name, int state)
{
        notify_list     *new;
 
        new = (notify_list *) xmalloc(sizeof(notify_list));


the entry is freed after nsm_insert_monitored_host() fails:
sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
...
        /*
         * Now, Create file on stable storage for host, first deleting any
         * existing records on file.
         */
        nsm_delete_monitored_host(dnsname, mon_name, my_name, 0);
 
        if (!nsm_insert_monitored_host(dnsname,
                                (struct sockaddr *)(char *)&my_addr, argp)) {
                nlist_free(NULL, clnt);
                goto failure;
        }

however, note that an existing entry will not be removed from the list, just freed.


this memory may be accessed again while walking the list:

sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
...
        clnt = rtnl;
 
        while ((clnt = nlist_gethost(clnt, mon_name, 0))) {
                if (statd_matchhostname(NL_MY_NAME(clnt), my_name) &&
                    NL_MY_PROC(clnt) == id->my_proc &&
                    NL_MY_PROG(clnt) == id->my_prog &&
                    NL_MY_VERS(clnt) == id->my_vers) {
                        if (memcmp(NL_PRIV(clnt), argp->priv, SM_PRIV_SIZE)) {

Comment 3 Frank Sorenson 2018-09-03 17:32:20 UTC
Created attachment 1480593 [details]
reproducer for bz1624542

reproducer; requires nsm_client test program from nfs-utils source

Comment 4 Frank Sorenson 2018-09-06 17:50:11 UTC
committed to upstream nfs-utils

commit 86604e2bd536ea48832dd0bf3d95b15de4de2733 (HEAD -> master, origin/master, origin/HEAD)
Author: Steve Dickson <steved>
Date:   2018-09-06 10:22:11 -0400

    statd: fix use-after-free in monitor list if insertion fails
    
    If nsm_insert_monitored_host() fails while saving the record to
    stable storage, we can't just assume the entry was new. Existing
    records must be removed from the list before being freed.
    
    Reviewed-by: Chuck Lever <chuck.lever>
    Signed-off-by: Frank Sorenson <sorenson>
    Signed-off-by: Steve Dickson <steved>

Comment 10 Yongcheng Yang 2019-04-03 01:32:21 UTC
Have verified in nfs-utils-1.3.0-0.63.el7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://beaker.engineering.redhat.com/recipes/6693240
-----------------------------------------------------
[08:19:11 root@ ~~]# ./repro.sh
doing initial 'monitor' calls
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.1
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.2
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.3
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.4
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.5
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.6
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.7
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.8
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.9
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.10
SM_MON request successful, state: 3

changing directory ownership to root
attempting to 'monitor' with new cookie
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.10
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.9
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.8
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.7
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.6
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.5
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.4
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.3
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.2
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.1
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.6.redhat.com) to monitor 192.168.123.1
SM_MON request failed, state: -1
rpc.statd is still running
^^^^^^^^^^^^^^^^^^^^^^^^^^^ PASS (Expected 0, got 0)
----------------------------------------------------

Compared with previous nfs-utils-1.3.0-0.61.el7
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://beaker.engineering.redhat.com/recipes/6693242
-----------------------------------------------------
[08:38:52 root@ ~~]# ./repro.sh
doing initial 'monitor' calls
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.1
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.2
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.3
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.4
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.5
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.6
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.7
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.8
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.9
SM_MON request successful, state: 3
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.10
SM_MON request successful, state: 3

changing directory ownership to root
attempting to 'monitor' with new cookie
RPC:0
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.10
SM_MON request failed, state: -1
RPC:0
Calling 127.0.0.1 (as rhel-7.7.redhat.com) to monitor 192.168.123.9
sm_mon_1: RPC: Unable to receive; errno = Connection refused
rpc.statd has died
^^^^^^^^^^^^^^^^^^^ FAIL - Should not crash the rpc.statd (Expected 0, got 1)
--------------------------------------------------------------------------

Moving to VERIFIED for now.

Comment 12 errata-xmlrpc 2019-08-06 13:11:50 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, 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-2019:2268


Note You need to log in before you can comment on or make changes to this bug.