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 in nfs_do_root_mount".
fs/nfs/nfs4namespace.c | 35 ++++++++++++++++++++++++++++++++---
1 files changed, 32 insertions(+), 3 deletions(-)
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
+ */
+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;
}
--
1.7.4.4
T24gVHVlLCAyMDEyLTA0LTI0IGF0IDEwOjU3IC0wNDAwLCBXZXN0b24gQW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o+ICAJY2hhciAqbGltaXQ7DQo+ICAJY2hhciAqcGF0aCA9IG5mc19wYXRo
KCZsaW1pdCwgZGVudHJ5LCBidWZmZXIsIGJ1Zmxlbik7DQo+ICAJaWYgKCFJU19FUlIocGF0aCkp
IHsNCj4gLQkJY2hhciAqY29sb24gPSBzdHJjaHIocGF0aCwgJzonKTsNCj4gLQkJaWYgKGNvbG9u
ICYmIGNvbG9uIDwgbGltaXQpDQo+IC0JCQlwYXRoID0gY29sb24gKyAxOw0KPiArCQljaGFyICpw
YXRoX2NvbXBvbmVudCA9IG5mc19wYXJzZV9wYXRoX2NvbXBvbmVudChwYXRoLCBsaW1pdCk7DQo+
ICsJCWlmIChwYXRoX2NvbXBvbmVudCkNCj4gKwkJCXJldHVybiBwYXRoX2NvbXBvbmVudDsNCj4g
IAl9DQo+ICAJcmV0dXJuIHBhdGg7DQo+ICB9DQoNClNvIHRoaXMgZml4ZXMgdGhlIHByb2JsZW0g
b2YgcGFyc2luZyB0aGUgZGV2bmFtZSwgYnV0IGhvdyBhYm91dCB0aGUNCmlzc3VlIG9mIHNldHRp
bmcgdGhlIGNvcnJlY3QgZGV2bmFtZSBpZiB0aGUgc2VydmVyIHN1cHBsaWVzIGFuIElQdjYNCmFk
ZHJlc3MgYXMgdGhlIGhvc3RuYW1lPw0KDQotLSANClRyb25kIE15a2xlYnVzdA0KTGludXggTkZT
IGNsaWVudCBtYWludGFpbmVyDQoNCk5ldEFwcA0KVHJvbmQuTXlrbGVidXN0QG5ldGFwcC5jb20N
Cnd3dy5uZXRhcHAuY29tDQoNCg==
On Apr 24, 2012, at 11:33 AM, Myklebust, Trond wrote:
> On Tue, 2012-04-24 at 10:57 -0400, Weston Andros Adamson wrote:
>> 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 in nfs_do_root_mount".
>>
>> fs/nfs/nfs4namespace.c | 35 ++++++++++++++++++++++++++++++++---
>> 1 files changed, 32 insertions(+), 3 deletions(-)
>>
>> 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
>> + */
>> +static inline char *nfs_parse_path_component(char *nfspath, char *end)
>
> Nit: this is really parsing the server name component of the devname.
>
> Also, please make the 'end' argument 'const char *', and drop the
> 'inline' declaration.
OK.
>
>> +{
>> + 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:
>
> 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 ':').
>> + 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;
>> }
>
> 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