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 1711210 - rpc.mountd leaks memory
Summary: rpc.mountd leaks memory
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: nfs-utils
Version: 7.6
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Steve Dickson
QA Contact: Yongcheng Yang
URL:
Whiteboard:
Depends On:
Blocks: 1711360 1712202 1713360
TreeView+ depends on / blocked
 
Reported: 2019-05-17 08:30 UTC by Kenneth D'souza
Modified: 2019-08-06 13:11 UTC (History)
8 users (show)

Fixed In Version: nfs-utils-1.3.0-0.65.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1712202 1713360 (view as bug list)
Environment:
Last Closed: 2019-08-06 13:11:50 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
valgrind output (23.86 KB, text/plain)
2019-05-17 08:30 UTC, Kenneth D'souza
no flags Details
Reproducer script (1.08 KB, application/x-shellscript)
2019-05-17 08:31 UTC, Kenneth D'souza
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 4201291 0 Troubleshoot None Why does memory leak occur in rpc.mountd? 2019-06-29 12:44:08 UTC
Red Hat Product Errata RHBA-2019:2268 0 None None None 2019-08-06 13:11:59 UTC

Description Kenneth D'souza 2019-05-17 08:30:51 UTC
Created attachment 1569970 [details]
valgrind output

Description of problem:
rpc.mountd leaks memory 

Version-Release number of selected component (if applicable):
# rpm -qa | grep -i nfs-utils
nfs-utils-1.3.0-0.61.el7.x86_64
nfs-utils-debuginfo-1.3.0-0.61.el7.x86_64


How reproducible:
Always

Steps to Reproduce:
1. Run the attached reproducer script.
2. Checks leaks through valgrind
3.

Actual results:
Memory usage increases overtime.

Expected results:
No memory leaks.

Additional info:

Comment 2 Kenneth D'souza 2019-05-17 08:31:33 UTC
Created attachment 1569971 [details]
Reproducer script

Comment 13 Frank Sorenson 2019-05-22 15:28:34 UTC
Note: the script exercises the leaks numerous times, and it's really not necessary to leak more than once in order to demonstrate whether the leak has been fixed or not.

I believe it should be sufficient to run the exportfs with 'fsid=...' once


Additional leaks:

        # exportfs -v -i -omp=/some/longer/path \*:/mnt

which leaks (strlen(mp) + 1) bytes from this allocation of ep->e_mountpoint:

                } else if (strcmp(opt, "mountpoint")==0 ||
                           strcmp(opt, "mp") == 0 ||
                           strncmp(opt, "mountpoint=", 11)==0 ||
                           strncmp(opt, "mp=", 3) == 0) {
                        char * mp = strchr(opt, '=');
                        if (mp)
                                ep->e_mountpoint = strdup(mp+1);  <<<<<<<<

==00:00:00:24.636 10815== 18 bytes in 1 blocks are definitely lost in loss record 14 of 37
==00:00:00:24.636 10815==    at 0x4C29BEB: malloc+114 (vg_replace_malloc.c:299)
==00:00:00:24.636 10815==    by 0x573B0C9: strdup+25 (strdup.c:42)
==00:00:00:24.636 10815==    by 0x11730F: parseopts.isra.3+2895 (exports.c:649)
==00:00:00:24.636 10815==    by 0x11787C: getexportent+476 (exports.c:182)
==00:00:00:24.636 10815==    by 0x115049: xtab_read+89 (xtab.c:44)
==00:00:00:24.636 10815==    by 0x10E54B: auth_reload+155 (auth.c:107)
==00:00:00:24.636 10815==    by 0x10E65F: auth_init+15 (auth.c:51)
==00:00:00:24.636 10815==    by 0x10D01D: main+1821 (mountd.c:902)
==00:00:00:24.636 10815==    by 0x56D13D4: __libc_start_main+244 (libc-start.c:266)
==00:00:00:24.636 10815==    by 0x10D3CA: ??? (in /root/rpmbuild/BUILD/nfs-utils-1.3.0/utils/mountd/mountd)


and:
        # exportfs -v -i -omp \*:/mnt
which leaks 1 byte from the allocation in the 'else' clause:
                        if (mp)
                                ep->e_mountpoint = strdup(mp+1);
                        else
                                ep->e_mountpoint = strdup(""); <<<<<<<<

==00:00:00:19.838 9975== 1 bytes in 1 blocks are definitely lost in loss record 2 of 34
==00:00:00:19.838 9975==    at 0x4C2BB46: calloc+138 (vg_replace_malloc.c:711)
==00:00:00:19.838 9975==    by 0x1174EF: parseopts.isra.3+3375 (exports.c:651)
==00:00:00:19.838 9975==    by 0x11787C: getexportent+476 (exports.c:182)
==00:00:00:19.838 9975==    by 0x115049: xtab_read+89 (xtab.c:44)
==00:00:00:19.838 9975==    by 0x10E54B: auth_reload+155 (auth.c:107)
==00:00:00:19.838 9975==    by 0x10E65F: auth_init+15 (auth.c:51)
==00:00:00:19.838 9975==    by 0x10D01D: main+1821 (mountd.c:902)
==00:00:00:19.838 9975==    by 0x56D13D4: __libc_start_main+244 (libc-start.c:266)
==00:00:00:19.838 9975==    by 0x10D3CA: ??? (in /root/rpmbuild/BUILD/nfs-utils-1.3.0/utils/mountd/mountd)


        # exportfs -v -i -orefer=/some_path \*:/mnt
which leaks (strlen(refer) + 1) from this allocation:
                } else if (strncmp(opt, "refer=", 6) == 0) {
                        ep->e_fslocmethod = FSLOC_REFER;
                        ep->e_fslocdata = strdup(opt+6);  <<<<<<<<

==00:00:00:46.441 12188== 11 bytes in 1 blocks are definitely lost in loss record 6 of 35
==00:00:00:46.441 12188==    at 0x4C29BEB: malloc+114 (vg_replace_malloc.c:299)
==00:00:00:46.441 12188==    by 0x573B0C9: strdup+25 (strdup.c:42)
==00:00:00:46.441 12188==    by 0x1174D4: parseopts.isra.3+3348 (exports.c:664)
==00:00:00:46.441 12188==    by 0x11787C: getexportent+476 (exports.c:182)
==00:00:00:46.441 12188==    by 0x115049: xtab_read+89 (xtab.c:44)
==00:00:00:46.441 12188==    by 0x10E54B: auth_reload+155 (auth.c:107)
==00:00:00:46.441 12188==    by 0x10E65F: auth_init+15 (auth.c:51)
==00:00:00:46.441 12188==    by 0x10D01D: main+1821 (mountd.c:902)

Comment 14 nikhil kshirsagar 2019-05-22 15:44:12 UTC
Agreed, e_fslocdata and e_mountpoint leak too. 

If e_squids and e_sqgids are leaking too, might make more sense simply calling exportent_release() to free up everything, coz we have that function in export.c, 

void
exportent_release(struct exportent *eep)
{
        xfree(eep->e_squids);
        xfree(eep->e_sqgids);
        free(eep->e_mountpoint);
        free(eep->e_fslocdata);
        free(eep->e_uuid);
        xfree(eep->e_hostname);
}

(and maybe change exportent_release to check for NULL before freeing and then setting it to null)


As of now, the patch we are planning to submit upstream for hostname and uuid fixes looks like, (for steve's reference),


static int
xtab_read(char *xtab, char *lockfn, int is_export)
{

    /* is_export == 0  => reading /proc/fs/nfs/exports - we know these things are exported to kernel
     * is_export == 1  => reading /var/lib/nfs/etab - these things are allowed to be exported
     */
        struct exportent        *xp;
        nfs_export              *exp;
        int                     lockid;

        if ((lockid = xflock(lockfn, "r")) < 0)
                return 0;
        setexportent(xtab, "r");
        if (is_export == 1)
                v4root_needed = 1;
        while ((xp = getexportent(is_export==0, 0)) != NULL) {
                if (!(exp = export_lookup(xp->e_hostname, xp->e_path, is_export != 1)) &&
                    !(exp = export_create(xp, is_export!=1)))
                {
                    if(xp->e_hostname) {
                        free(xp->e_hostname);
                        xp->e_hostname=NULL;
                    }
                    if(xp->e_uuid) {
                        free(xp->e_uuid);
                        xp->e_uuid=NULL;
                    }

                    continue;
                }
                switch (is_export) {
                case 0:
                        exp->m_exported = 1;
                        break;
                case 1:
                        exp->m_xtabent = 1;
                        exp->m_mayexport = 1;
                        if ((xp->e_flags & NFSEXP_FSID) && xp->e_fsid == 0)
                                v4root_needed = 0;
                        break;
                }
                if(xp->e_hostname) {
                    free(xp->e_hostname);
                    xp->e_hostname=NULL;
                }
                if(xp->e_uuid) {
                    free(xp->e_uuid);
                    xp->e_uuid=NULL;
                }


        }
        endexportent();
        xfunlock(lockid);

        return 0;
}


And in exports.c , the last part of getexportent() is,

...
...
        ee.e_hostname = xstrdup(hostname);

        if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0) {
                if(ee.e_hostname)
                {
                    xfree(ee.e_hostname);
                    ee.e_hostname=NULL;
                }
                if(ee.e_uuid)
                {
                    xfree(ee.e_uuid);
                    ee.e_uuid=NULL;
                }
                return NULL;
        }
        /* resolve symlinks */
        if (realpath(ee.e_path, rpath) != NULL) {
                rpath[sizeof (rpath) - 1] = '\0';
                strncpy(ee.e_path, rpath, sizeof (ee.e_path) - 1);
                ee.e_path[sizeof (ee.e_path) - 1] = '\0';
        }
        return &ee;
}


This seems to work to at least fix the hostname and uuid ones.

Comment 17 Steve Dickson 2019-05-23 14:24:06 UTC
The upstream commit

commit 50ef80739d9e1e0df6616289ef2ff626a94666ee
Author: Steve Dickson <steved>
Date:   Thu May 23 09:24:49 2019 -0400

    rpc.mountd: Fix e_hostname and e_uuid leaks
    
    strdup of exportent uuid and hostname in getexportent() ends up leaking
    memory. Free the memory before getexportent() is called again from xtab_read()

Comment 22 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.