Skip to content

Commit 74cef68

Browse files
committed
afs: Fix dynamic root lookup DNS check
In the afs dynamic root directory, the ->lookup() function does a DNS check on the cell being asked for and if the DNS upcall reports an error it will report an error back to userspace (typically ENOENT). However, if a failed DNS upcall returns a new-style result, it will return a valid result, with the status field set appropriately to indicate the type of failure - and in that case, dns_query() doesn't return an error and we let stat() complete with no error - which can cause confusion in userspace as subsequent calls that trigger d_automount then fail with ENOENT. Fix this by checking the status result from a valid dns_query() and returning an error if it indicates a failure. Fixes: bbb4c43 ("dns: Allow the dns resolver to retrieve a server set") Reported-by: Markus Suvanto <[email protected]> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=216637 Signed-off-by: David Howells <[email protected]> Tested-by: Markus Suvanto <[email protected]> cc: Marc Dionne <[email protected]> cc: [email protected]
1 parent 71f8b55 commit 74cef68

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

fs/afs/dynroot.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static int afs_probe_cell_name(struct dentry *dentry)
114114
struct afs_net *net = afs_d2net(dentry);
115115
const char *name = dentry->d_name.name;
116116
size_t len = dentry->d_name.len;
117+
char *result = NULL;
117118
int ret;
118119

119120
/* Names prefixed with a dot are R/W mounts. */
@@ -131,9 +132,22 @@ static int afs_probe_cell_name(struct dentry *dentry)
131132
}
132133

133134
ret = dns_query(net->net, "afsdb", name, len, "srv=1",
134-
NULL, NULL, false);
135-
if (ret == -ENODATA || ret == -ENOKEY)
135+
&result, NULL, false);
136+
if (ret == -ENODATA || ret == -ENOKEY || ret == 0)
136137
ret = -ENOENT;
138+
if (ret > 0 && ret >= sizeof(struct dns_server_list_v1_header)) {
139+
struct dns_server_list_v1_header *v1 = (void *)result;
140+
141+
if (v1->hdr.zero == 0 &&
142+
v1->hdr.content == DNS_PAYLOAD_IS_SERVER_LIST &&
143+
v1->hdr.version == 1 &&
144+
(v1->status != DNS_LOOKUP_GOOD &&
145+
v1->status != DNS_LOOKUP_GOOD_WITH_BAD))
146+
return -ENOENT;
147+
148+
}
149+
150+
kfree(result);
137151
return ret;
138152
}
139153

0 commit comments

Comments
 (0)