Skip to content

Commit eec7ef6

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 <markus.suvanto@gmail.com> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=216637 Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: Markus Suvanto <markus.suvanto@gmail.com> cc: Marc Dionne <marc.dionne@auristor.com> cc: linux-afs@lists.infradead.org Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 82d64cb commit eec7ef6

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
@@ -20,6 +20,7 @@ static int afs_probe_cell_name(struct dentry *dentry)
2020
struct afs_net *net = afs_d2net(dentry);
2121
const char *name = dentry->d_name.name;
2222
size_t len = dentry->d_name.len;
23+
char *result = NULL;
2324
int ret;
2425

2526
/* Names prefixed with a dot are R/W mounts. */
@@ -37,9 +38,22 @@ static int afs_probe_cell_name(struct dentry *dentry)
3738
}
3839

3940
ret = dns_query(net->net, "afsdb", name, len, "srv=1",
40-
NULL, NULL, false);
41-
if (ret == -ENODATA || ret == -ENOKEY)
41+
&result, NULL, false);
42+
if (ret == -ENODATA || ret == -ENOKEY || ret == 0)
4243
ret = -ENOENT;
44+
if (ret > 0 && ret >= sizeof(struct dns_server_list_v1_header)) {
45+
struct dns_server_list_v1_header *v1 = (void *)result;
46+
47+
if (v1->hdr.zero == 0 &&
48+
v1->hdr.content == DNS_PAYLOAD_IS_SERVER_LIST &&
49+
v1->hdr.version == 1 &&
50+
(v1->status != DNS_LOOKUP_GOOD &&
51+
v1->status != DNS_LOOKUP_GOOD_WITH_BAD))
52+
return -ENOENT;
53+
54+
}
55+
56+
kfree(result);
4357
return ret;
4458
}
4559

0 commit comments

Comments
 (0)