Skip to content

Commit 63ad66d

Browse files
dhowellsgregkh
authored andcommitted
afs: Fix dynamic root lookup DNS check
[ Upstream commit 74cef68 ] 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] Signed-off-by: Sasha Levin <[email protected]>
1 parent 65d2c28 commit 63ad66d

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
@@ -113,6 +113,7 @@ static int afs_probe_cell_name(struct dentry *dentry)
113113
struct afs_net *net = afs_d2net(dentry);
114114
const char *name = dentry->d_name.name;
115115
size_t len = dentry->d_name.len;
116+
char *result = NULL;
116117
int ret;
117118

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

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

0 commit comments

Comments
 (0)