nfs4: fix referrals on mounts that use IPv6 addrs
Subsystems (2)
PATCH 1/1 nfs4: fix referrals on mounts that use IPv6 addrs
All referrals (IPv4 addr, IPv6 addr, and DNS) are broken on mounts of IPv6 addresses, because validation code uses a path that is parsed from the dev_name ("<server>:<path>") by splitting on the first colon and colons are used in IPv6 addrs.
This patch ignores colons within IPv6 addresses that are escaped by '[' and ']'.
---
This depends on commit 2f8e4bd91488f286e83e8abb14683102efaafb05 "nfs: Enclose hostname in brackets when needed in nfs_do_root_mount".
fs/nfs/nfs4namespace.c | 35 ++++++++++++++++++++++++++++++++--- 1 files changed, 32 insertions(+), 3 deletions(-)
fs/nfs/nfs4namespace.c +32 -3
@@ -52,6 +52,35 @@ Elong: }/* +* parse the path component of an nfs path ("<server>:<path>"). +* nfspath - the "<server>:<path>" string +* end - pointer to end of devname component of 'nfspath' +* returns NULL on failure +*/ +static inline char *nfs_parse_path_component (char *nfspath,char *end) +{ +bool ipv6_esc = false; +char *p; + +/* find first colon not in IPv6 addr */ +for (p = nfspath; p < end && *p; p++) { +switch (*p) { +case '[' : + ipv6_esc = true; +break ; +case ']' : + ipv6_esc = false; +break ; +case ':' : +if (!ipv6_esc) +return (p +1 ); +break ; + } + } +return NULL ; +} + +/* * Determine the mount path as a string */ static char *nfs4_path (struct dentry *dentry,char *buffer,ssize_t buflen)
@@ -59,9 +88,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)char *limit;char *path =nfs_path (&limit, dentry, buffer, buflen);if (!IS_ERR (path)) { -char *colon =strchr (path,':' ); -if (colon && colon < limit) - path = colon +1 ; +char *path_component =nfs_parse_path_component (path, limit); +if (path_component) +return path_component; }return path; }
Signature · 1 line
1.7.4.4
Weston Andros Adamson wrote:
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 9c8eca3..307743d 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c @@ -52,6 +52,35 @@ Elong: }
/*
+ * parse the path component of an nfs path ("<server>:<path>").
+ * nfspath - the "<server>:<path>" string
+ * end - pointer to end of devname component of 'nfspath'
+ * returns NULL on failure
+ */
The comment seems odd to me. You're not parsing the path component, you're parsing the nfspath to return the path. And the term "devname component" hasn't been defined anywhere. How about this:
Return the path component of an nfs path ("<server>:<path>").
nfspath - the "<server>:<path>" string
end - pointer to end of nfspath
returns NULL on failure
T24gVHVlLCAyMDEyLTA0LTI0IGF0IDEwOjU3IC0wNDAwLCBXZXN0b24gQW5kcm9zIEFkYW1zb24g d3JvdGU6DQo+IEFsbCByZWZlcnJhbHMgKElQdjQgYWRkciwgSVB2NiBhZGRyLCBhbmQgRE5TKSBh cmUgYnJva2VuIG9uIG1vdW50cyBvZg0KPiBJUHY2IGFkZHJlc3NlcywgYmVjYXVzZSB2YWxpZGF0 aW9uIGNvZGUgdXNlcyBhIHBhdGggdGhhdCBpcyBwYXJzZWQNCj4gZnJvbSB0aGUgZGV2X25hbWUg KCI8c2VydmVyPjo8cGF0aD4iKSBieSBzcGxpdHRpbmcgb24gdGhlIGZpcnN0IGNvbG9uIGFuZA0K PiBjb2xvbnMgYXJlIHVzZWQgaW4gSVB2NiBhZGRycy4NCj4gVGhpcyBwYXRjaCBpZ25vcmVzIGNv bG9ucyB3aXRoaW4gSVB2NiBhZGRyZXNzZXMgdGhhdCBhcmUgZXNjYXBlZCBieSAnWycgYW5kICdd Jy4NCj4gDQo+IFNpZ25lZC1vZmYtYnk6IFdlc3RvbiBBbmRyb3MgQWRhbXNvbiA8ZHJvc0BuZXRh cHAuY29tPg0KPiAtLS0NCj4gDQo+IFRoaXMgZGVwZW5kcyBvbiBjb21taXQgMmY4ZTRiZDkxNDg4 ZjI4NmU4M2U4YWJiMTQ2ODMxMDJlZmFhZmIwNQ0KPiAibmZzOiBFbmNsb3NlIGhvc3RuYW1lIGlu IGJyYWNrZXRzIHdoZW4gbmVlZGVkIGluIG5mc19kb19yb290X21vdW50Ii4NCj4gDQo+ICBmcy9u ZnMvbmZzN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 33 lines · Trond
Quoted 20 lines · Weston Andros Adamson
All referrals (IPv4 addr, IPv6 addr, and DNS) are broken on mounts of IPv6 addresses, because validation code uses a path that is parsed from the
dev_name("<server>:<path>") by splitting on the first colon and colons are used in IPv6 addrs.
This patch ignores colons within IPv6 addresses that are escaped by '[' and ']'.Signed-off-by Weston Andros Adamson <[email protected]>---
This depends on commit
2f8e4bd91488f286e83e8abb14683102efaafb05"nfs: Enclose hostname in brackets when needed innfs_do_root_mount".
fs/nfs/nfs4namespace.c| 35 ++++++++++++++++++++++++++++++++---1 files changed, 32 insertions(+), 3 deletions(-)fs/nfs/nfs4namespace.c +0
-0fs/nfs/nfs4namespace.c Elong: · line 60
Quoted 9 lines
fs/nfs/nfs4namespace.c +6
-0@@ -52,6 +52,35 @@ Elong: }/* +* parse the path component of an nfs path ("<server>:<path>"). +* nfspath - the "<server>:<path>" string +* end - pointer to end of devname component of 'nfspath' +* returns NULL on failure +*/ +static inline char *nfs_parse_path_component (char *nfspath,char *end)Nit: this is really parsing the server name component of the devname.
Quoted 2 lines
Also, please make the 'end' argument 'const char *', and drop the 'inline' declaration.
OK.
Quoted 16 lines
fs/nfs/nfs4namespace.c Elong: · line 69
Quoted 10 lines
fs/nfs/nfs4namespace.c +9
-0+{ +bool ipv6_esc = false; +char *p; + +/* find first colon not in IPv6 addr */ +for (p = nfspath; p < end && *p; p++) { +switch (*p) { +case '[' : + ipv6_esc = true;Note that if p != nfspath, then we have a problem. The '[' _must_ be the first character in the server name, and there _must_ be a matching ']' at the end.
So how about optimising this using something along the lines of:
Quoted 11 lines
p = nfspath;
/* Handle escaped hostnames */
if (*p == '[') {
p = strchr(p, ']');
if (p == NULL)
return NULL;
}
p = strchr(p, ':');
if (p != NULL)
p++;
return p;OK, I'll change it to be more strict. Note that your suggestion doesn't enforce that the matching ']' is at the end of the hostname (next char ':').
Quoted 23 lines
Quoted 23 lines
fs/nfs/nfs4namespace.c +13
-3+break ; +case ':' : +if (!ipv6_esc) +return (p +1 ); +break ; + } + } +return NULL ; +} + +/* * Determine the mount path as a string */ static char *nfs4_path (struct dentry *dentry,char *buffer,ssize_t buflen)@@ -59,9 +88,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)char *limit;char *path =nfs_path (&limit, dentry, buffer, buflen);if (!IS_ERR (path)) { -char *colon =strchr (path,':' ); -if (colon && colon < limit) - path = colon +1 ; +char *path_component =nfs_parse_path_component (path, limit); +if (path_component)
Quoted 8 lines
fs/nfs/nfs4namespace.c static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen) · line 96
Quoted 4 lines
fs/nfs/nfs4namespace.c +1
-0+return path_component; }return path; }So this fixes the problem of parsing the devname, but how about the issue of setting the correct devname if the server supplies an IPv6 address as the hostname?
That is covered by the patch you sent me (commit 2f8e4bd91488f286e83e8abb14683102efaafb05). I thought you'd just use that patch - it's what I tested with.
-dros
Quoted 16 lines · Jim Rees
Weston Andros Adamson wrote:
diff --git
a/fs/nfs/nfs4namespace.cb/fs/nfs/nfs4namespace.cindex 9c8eca3..307743d 100644
---a/fs/nfs/nfs4namespace.c
+++b/fs/nfs/nfs4namespace.c
@@ -52,6 +52,35 @@ Elong:
}/*
+ * parse the path component of an nfs path ("<server>:<path>").
+ * nfspath - the "<server>:<path>" string
+ * end - pointer to end of devname component of 'nfspath'
+ * returns NULL on failure
+ */
Quoted 5 lines
The comment seems odd to me. You're not parsing the path component, you're parsing the nfspath to return the path. And the term "devname component" hasn't been defined anywhere. How about this:
Return the path component of an nfs path ("<server>:<path>").
Yeah, OK.
Quoted 2 lines
nfspath - the "<server>:<path>" string
end - pointer to end of nfspath
Well, that's not really true. "end" comes from the call to nfs_path() and points to the end of the devname component of the nfs_path, i.e.:
if "[fc00::10]:/export" is mounted:
[fc00::10]:/export/foo/bar
^end
Quoted 1 line
returns NULL on failure
-dros