From nobody Thu Dec 18 22:14:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89B52C4332F for ; Mon, 11 Dec 2023 21:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345277AbjLKVco (ORCPT ); Mon, 11 Dec 2023 16:32:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345233AbjLKVcl (ORCPT ); Mon, 11 Dec 2023 16:32:41 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15BE9D1 for ; Mon, 11 Dec 2023 13:32:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702330367; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/T6yVZIIW8gaOaFWvjKuKFf94e1s7X/v7fENW4wrGt4=; b=hitp1wNOYZ6wTs7Z0ZnNn1B4ARK+04y7dMXOwEaZxFdy8uWqzjly83gcTk/M9ObWVAsZ6t rY0vFGnxt5eSUPt0wkVz4riugDBTIuGQEC6aVQ42cOhJI8CBsUcZO/8VQi52Ss5iyVM73j ux5hFiADNwlcZVJnGzGiNlEH7OKczGs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-6Zu9lM7qOvmBrHvBp8NfIA-1; Mon, 11 Dec 2023 16:32:40 -0500 X-MC-Unique: 6Zu9lM7qOvmBrHvBp8NfIA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F2D4881C84; Mon, 11 Dec 2023 21:32:40 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B0B62026D66; Mon, 11 Dec 2023 21:32:39 +0000 (UTC) From: David Howells To: Markus Suvanto , Marc Dionne Cc: David Howells , linux-afs@lists.infradead.org, keyrings@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] afs: Fix dynamic root lookup DNS check Date: Mon, 11 Dec 2023 21:32:32 +0000 Message-ID: <20231211213233.2793525-3-dhowells@redhat.com> In-Reply-To: <20231211213233.2793525-1-dhowells@redhat.com> References: <20231211213233.2793525-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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: bbb4c4323a4d ("dns: Allow the dns resolver to retrieve a server set") Reported-by: Markus Suvanto Closes: https://bugzilla.kernel.org/show_bug.cgi?id=3D216637 Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org --- Notes: Changes =3D=3D=3D=3D=3D=3D=3D ver #2) - Fix signed-unsigned comparison when checking return val. fs/afs/dynroot.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/afs/dynroot.c b/fs/afs/dynroot.c index 34474a061654..1f656005018e 100644 --- a/fs/afs/dynroot.c +++ b/fs/afs/dynroot.c @@ -114,6 +114,7 @@ static int afs_probe_cell_name(struct dentry *dentry) struct afs_net *net =3D afs_d2net(dentry); const char *name =3D dentry->d_name.name; size_t len =3D dentry->d_name.len; + char *result =3D NULL; int ret; =20 /* Names prefixed with a dot are R/W mounts. */ @@ -131,9 +132,22 @@ static int afs_probe_cell_name(struct dentry *dentry) } =20 ret =3D dns_query(net->net, "afsdb", name, len, "srv=3D1", - NULL, NULL, false); - if (ret =3D=3D -ENODATA || ret =3D=3D -ENOKEY) + &result, NULL, false); + if (ret =3D=3D -ENODATA || ret =3D=3D -ENOKEY || ret =3D=3D 0) ret =3D -ENOENT; + if (ret > 0 && ret >=3D sizeof(struct dns_server_list_v1_header)) { + struct dns_server_list_v1_header *v1 =3D (void *)result; + + if (v1->hdr.zero =3D=3D 0 && + v1->hdr.content =3D=3D DNS_PAYLOAD_IS_SERVER_LIST && + v1->hdr.version =3D=3D 1 && + (v1->status !=3D DNS_LOOKUP_GOOD && + v1->status !=3D DNS_LOOKUP_GOOD_WITH_BAD)) + return -ENOENT; + + } + + kfree(result); return ret; }