Bug 168158 - [zfs] incorrect parsing of sharenfs options in zfs (fsshare.c)
Summary: [zfs] incorrect parsing of sharenfs options in zfs (fsshare.c)
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: Rick Macklem
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-20 08:30 UTC by Martin Birgmeier
Modified: 2024-10-11 15:12 UTC (History)
6 users (show)

See Also:


Attachments
Patch to support hyphenated host names in sharenfs zfs property. (571 bytes, patch)
2015-06-29 17:40 UTC, eborisch+FreeBSD
no flags Details | Diff
fix ZFS sharenfs for DNS names with '-' in them (497 bytes, patch)
2024-08-08 23:45 UTC, Rick Macklem
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Birgmeier 2012-05-20 08:30:01 UTC
The function translate_opts() in cddl/compat/opensolaris/misc/fsshare.c incorrectly transforms nfs export options. Specifically, it unconditionally separates the input string along hyphens, thereby making it impossible to have a hyphen in a host name (which is allowed, cf. http://tools.ietf.org/html/rfc952 and http://tools.ietf.org/html/rfc1123).

I am not sure whether this parsing is needed at all, as the resultant string, which is parsed by mountd(8), in its unaltered form seems to be compatible with the syntax expected by the latter. In fact, one could simply require that the string used for the sharenfs option is mountd(8) compatible and do away with the translate_opts() function entirely.

In a related vein, it is absolutely necessary to be able to specify multiple export lines for a single mount point, thereby allowing to assign different permissions to different clients. This has already been proposed a long while ago in http://www.freebsd.org/cgi/query-pr.cgi?pr=147881 but never been implemented. May I use that PR to suggest that this feature be added at the same time as fixing the bug described here.

Fix: 

Correct translate_opts() in cddl/compat/opensolaris/misc/fsshare.c (or get rid of it altogether).

As a workaround, I am currently using IP addresses in lieu of the affectd host names. I need to use both IPv4 and IPv6 addresses of the same host, as my network runs both IPv4 and IPv6.
How-To-Repeat: Try to execute

    zfs set sharenfs=test-host <zfs volume>

and then do a

    zfs list -o name,sharenfs <zfs colume>
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2012-05-21 09:32:13 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Over to maintainer(s).
Comment 2 Robert 2015-01-28 15:06:35 UTC
Hi, 

I just run into this exact bug with:
  FreeBSD 10.0-RELEASE-p12 FreeBSD 10.0-RELEASE-p12

What is the current status on this, is the "sharenfs" property overall simply not recommended nor used in production? (I also found this bug on the tracker: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=147881)

I have read people recommending to just use /etc/exports instead, but most posts a quite old so I'm not sure what's recommended today.

Regards, Robert
Comment 3 eborisch+FreeBSD 2015-06-29 17:40:05 UTC
Created attachment 158168 [details]
Patch to support hyphenated host names in sharenfs zfs property.

Simple patch that only ignores leading hyphens in options.

With this change:

    '-ro,a-server -alldirs' -> '-ro a-server -alldirs'

instead of (current behavior):

    '-ro,a-server -alldirs' -> '-ro a server -alldirs'

Changed by removing '-' from strsep() call, and handling (skipping) hyphen if first character immediately after strsep() call.

All test cases listed immediately prior to the code still work; I'm not aware of any supported forms that are broken by this change.
Comment 4 max 2017-03-02 12:12:26 UTC
FreeBSD 11.0-STABLE, and still the same.

Will the patch by eborisch be included?

If I want to include it, do I have to rebuild the whole kernel, or is it enough to rebuild zfs.ko?
Comment 5 Martin Birgmeier 2017-03-02 18:29:33 UTC
Now that this probably starts moving again, may I humbly suggest to use my patch instead for the reasons cited in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=176449#c7

-- Martin
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:43:15 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 7 gerrit.kuehn 2024-07-24 15:14:16 UTC
I just ran across this problem (not able to set hostnames with hyphen/dash using zfs set sharenfs=...) with a recent FreeBSD 14.1. Is there are chance that this will be fixed?
Comment 8 Rick Macklem freebsd_committer freebsd_triage 2024-08-08 23:45:54 UTC
Created attachment 252620 [details]
fix ZFS sharenfs for DNS names with '-' in them

Here is the same patch at Martin's, but for
current sources.
I will try and get it pulled into OpenZFS.
(I'm doing this now, but for future reference,
anyone can do a OpenZFS pull request. All you
need is a github login.)
Comment 9 Rick Macklem freebsd_committer freebsd_triage 2024-09-14 01:51:08 UTC
I have made the pull request for the patch on OpenZFS.
I have no idea if/when it will happen.
Comment 10 Rick Macklem freebsd_committer freebsd_triage 2024-09-17 23:47:59 UTC
Just fyi, the patch has now been pulled into
OpenZFS. It should end up in FreeBSD's main, etc
when the next cycle of downstream pulls occur.
Comment 11 Martin Birgmeier 2024-09-18 06:51:45 UTC
Rick, thank you for your efforts. Good things take time! :-)

-- Martin
Comment 12 Rick Macklem freebsd_committer freebsd_triage 2024-10-11 15:12:07 UTC
The patch has now been pulled down
into FreeBSD's main. I'll close this
patch once it is MFC'd.