Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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 1944119

Summary: exportfs: unable to unexport root
Product: Red Hat Enterprise Linux 8 Reporter: Roberto Bergantinos <rbergant>
Component: nfs-utilsAssignee: Steve Dickson <steved>
Status: CLOSED ERRATA QA Contact: Yongcheng Yang <yoyang>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.3CC: ajmitchell, dwysocha, ssahsrab, steved, xzhou, yieli, yoyang
Target Milestone: rcKeywords: Patch, Reproducer, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Unspecified   
Whiteboard:
Fixed In Version: nfs-utils-2.3.3-42.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1958975 1975049 (view as bug list) Environment:
Last Closed: 2021-11-09 19:40:03 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:
Bug Depends On:    
Bug Blocks: 1958975    

Description Roberto Bergantinos 2021-03-29 10:42:47 UTC
Description of problem:

If root is exported, we're unable to unexport it individually :

[root@rhel8 ~]# exportfs -s
/opt/mydir  172.23.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
/opt/mydir/subdir  172.23.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
/opt/mydir  *(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/opt/mydir/subdir  *(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

[root@rhel8 ~]# exportfs -i -o rw,sync 172.23.1.247:/ 

[root@rhel8 ~]# exportfs -s
/  172.23.1.247(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
/opt/mydir/subdir  172.23.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
/opt/mydir  172.23.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
/opt/mydir/subdir  *(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/opt/mydir  *(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

[root@rhel8 ~]# exportfs -v -u 172.23.1.247:/
exportfs: Could not find '172.23.1.247:/' to unexport.

- exportfs -au works
- exporting a bind mount of root & unexport it works

I think problem is here :

355 static void
356 unexportfs_parsed(char *hname, char *path, int verbose)
357 {
...
369         /*
370          * It's possible the specified path ends with a '/'. But
371          * the entry from exportlist won't has the trailing '/',
372          * so need to deal with it.
373         */
374         size_t nlen = strlen(path);
375         while (path[nlen - 1] == '/')  <<--- [*]
376                 nlen--;                      
377 
378         for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
379                 if (strlen(exp->m_export.e_path) != nlen)
380                         continue;
381                 if (path && strncmp(path, exp->m_export.e_path, nlen))
382                         continue;

while removing the trailing "/" from the path, for root case, we'll leave nlen at 0,
so we will loop through exportlist without finding "/".

quick patch :

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 262dd19a..40813fb8 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -383,7 +383,7 @@ unexportfs_parsed(char *hname, char *path, int verbose)
         * so need to deal with it.
        */
        size_t nlen = strlen(path);
-       while (path[nlen - 1] == '/')
+       while ((path[nlen - 1] == '/') && (nlen > 1))
                nlen--;
 
        for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {

seems to work :

[root@f-rawhide exportfs]# ./exportfs -i -o rw,sync *:/
[root@f-rawhide exportfs]# ./exportfs -s
/  *(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[root@f-rawhide exportfs]# ./exportfs -v -u *:/
unexporting *:/
[root@f-rawhide exportfs]# ./exportfs -s
[root@f-rawhide exportfs]#



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


How reproducible: 100%


Steps to Reproduce:
1. see above
2.
3.

Actual results: not able to indivually unexport root


Expected results: able to indivually unexport root


Additional info:

Comment 1 Yongcheng Yang 2021-03-30 04:28:57 UTC
(In reply to Roberto Bergantinos from comment #0)
> I think problem is here :
> 
> 355 static void
> 356 unexportfs_parsed(char *hname, char *path, int verbose)
> 357 {
> ...
> 369         /*
> 370          * It's possible the specified path ends with a '/'. But
> 371          * the entry from exportlist won't has the trailing '/',
> 372          * so need to deal with it.
> 373         */
> 374         size_t nlen = strlen(path);
> 375         while (path[nlen - 1] == '/')  <<--- [*]
> 376                 nlen--;                      
..
> while removing the trailing "/" from the path, for root case, we'll leave
> nlen at 0,
> so we will loop through exportlist without finding "/".

Yeah, that's the problem! Thanks a lot for the report!

Would you mind sending this patch to upstream "Linux NFS Mailing list <linux-nfs.org>" and cc "Steve Dickson <steved>".

IMO we cannot make it 8.4 now and it has been there for 5 years. Let's defer it to 8.5 for now.

Comment 2 Roberto Bergantinos 2021-03-30 08:15:12 UTC
> 
> Would you mind sending this patch to upstream "Linux NFS Mailing list
> <linux-nfs.org>" and cc "Steve Dickson <steved>".

hi Yongcheng

  yeah I sent the patch yesterday

  thanks for taking a look !

rgds
roberto

Comment 10 Steve Dickson 2021-05-10 14:12:13 UTC
commit ac266e2edc4f40eef810d52c72657b645e4010db
Author: Ondrej Mosnacek <omosnace>
Date:   Tue Apr 6 15:57:37 2021 -0400

    exportfs: fix unexporting of '/'

Comment 11 Dave Wysochanski 2021-05-10 14:18:33 UTC
RHEL7 clone - https://bugzilla.redhat.com/show_bug.cgi?id=1958975

Comment 16 Yongcheng Yang 2021-05-11 05:53:40 UTC
Verified on nfs-utils-2.3.3-42.el8.
~~~~~~~~
[23:24:24 root@ ~~]# exportfs -s
/  localhost(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[23:24:24 root@ ~~]# exportfs -v -u localhost:/
unexporting localhost:/
[23:24:24 root@ ~~]# exportfs -s
[23:24:24 root@ ~~]# 

Compared with nfs-utils-2.3.3-41.el8
~~~~~~~~
[11:42:27 root@ ~~]# exportfs -s
/  localhost(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[11:42:27 root@ ~~]# exportfs -v -u localhost:/
exportfs: Could not find 'localhost:/' to unexport.
[11:42:27 root@ ~~]# exportfs -s
/  localhost(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
[11:42:27 root@ ~~]# exportfs -ua

P.s. clear the unneeded needinfo flag.

Comment 18 errata-xmlrpc 2021-11-09 19:40:03 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 (nfs-utils 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-2021:4403