All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] Resolving symlinks ignores rootdir setting
@ 2022-01-14 12:36 Chris Chilvers
  2022-01-14 15:10 ` J. Bruce Fields
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Chilvers @ 2022-01-14 12:36 UTC (permalink / raw)
  To: linux-nfs

I was testing using the rootdir setting in nfs.config to allow using export
paths that would normally conflict with local systems directories with NFS v3.

The idea was to support re-exporting a source NFS server such as NetApp that
might exports arbitrary paths such as /home without overwriting the /home
directory on the NFS server, and even support exporting a root directory similar
to NFS v4.

While testing I ran into an issue where the NFS server would fail to start.
During start up, the NFS server would log the error:

  $ systemctl status nfs-server.service
  systemd[1]: Starting NFS server and services...
  exportfs[2307]: exportfs: Failed to stat /srv/nfs/usr/bin: No such
file or directory
  systemd[1]: nfs-server.service: Control process exited, code=exited,
status=1/FAILURE

  $ cat nfs.config
  [exports]
  rootdir=/srv/nfs

  $ cat /etc/exports
  /         10.0.0.0/8(rw,sync,wdelay,no_root_squash,no_all_squash,no_subtree_check,sec=sys,secure,fsid=0,nohide)
  /assets   10.0.0.0/8(rw,sync,wdelay,no_root_squash,no_all_squash,no_subtree_check,sec=sys,secure,fsid=10,nohide)
  /bin      10.0.0.0/8(rw,sync,wdelay,no_root_squash,no_all_squash,no_subtree_check,sec=sys,secure,fsid=30,nohide)
  /software 10.0.0.0/8(rw,sync,wdelay,no_root_squash,no_all_squash,no_subtree_check,sec=sys,secure,fsid=40,nohide)

If I create the directory /srv/nfs/usr/bin then the NFS server will start.
Listing the actual exports shows that a different path was exported compared to
the path from /etc/exports.

  $ exportfs -s
  / 10.0.0.0/8(sync,wdelay,nohide,no_subtree_check,fsid=0,sec=sys,rw,secure,no_root_squash,no_all_squ>
  /assets 10.0.0.0/8(sync,wdelay,nohide,no_subtree_check,fsid=10,sec=sys,rw,secure,no_root_squash,no_>
  /usr/bin 10.0.0.0/8(sync,wdelay,nohide,no_subtree_check,fsid=30,sec=sys,rw,secure,no_root_squash,no>
  /software 10.0.0.0/8(sync,wdelay,nohide,no_subtree_check,fsid=40,sec=sys,rw,secure,no_root_squash,n>

To test this further I create a symlink from /software to /usr/lib. Once again
the server failed to start because it could not find /srv/nfs/usr/lib.

Reading through the source, I think the issue is in the getexportent function in
support/nfs/exports.c.

    /* 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';
    }

It appears this function does not take into account the rootdir property when
resolving e_path.

This was tested on Ubuntu 20.04 with the 5.11.8-051108-generic kernel. nfs-utils
version is 2.5.3.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-17 22:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-14 12:36 [bug report] Resolving symlinks ignores rootdir setting Chris Chilvers
2022-01-14 15:10 ` J. Bruce Fields
2022-01-14 15:57   ` Chris Chilvers
2022-01-17 22:37     ` J. Bruce Fields

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.