linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Dionne <marc.dionne@auristor.com>
To: David Howells <dhowells@redhat.com>
Cc: Markus Suvanto <markus.suvanto@gmail.com>,
	linux-afs@lists.infradead.org,  keyrings@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] afs: Fix dynamic root lookup DNS check
Date: Mon, 11 Dec 2023 13:37:24 -0400	[thread overview]
Message-ID: <CAB9dFdsCnAeitHcNJRY+f8eG=exrgpBZpczfMhHHXLvCR32MaA@mail.gmail.com> (raw)
In-Reply-To: <20231211163412.2766147-3-dhowells@redhat.com>

On Mon, Dec 11, 2023 at 12:34 PM David Howells <dhowells@redhat.com> wrote:
>
> 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 <markus.suvanto@gmail.com>
> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=216637
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Marc Dionne <marc.dionne@auristor.com>
> cc: linux-afs@lists.infradead.org
> ---
>  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..4089d77a7a4d 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 = afs_d2net(dentry);
>         const char *name = dentry->d_name.name;
>         size_t len = dentry->d_name.len;
> +       char *result = NULL;
>         int ret;
>
>         /* Names prefixed with a dot are R/W mounts. */
> @@ -131,9 +132,22 @@ static int afs_probe_cell_name(struct dentry *dentry)
>         }
>
>         ret = dns_query(net->net, "afsdb", name, len, "srv=1",
> -                       NULL, NULL, false);
> -       if (ret == -ENODATA || ret == -ENOKEY)
> +                       &result, NULL, false);
> +       if (ret == -ENODATA || ret == -ENOKEY || ret == 0)
>                 ret = -ENOENT;
> +       if (ret >= sizeof(struct dns_server_list_v1_header)) {

This needs an additional ret > 0 check, as the comparison may return
true with a negative ret if it gets promoted to an unsigned.

> +               struct dns_server_list_v1_header *v1 = (void *)result;
> +
> +               if (v1->hdr.zero == 0 &&
> +                   v1->hdr.content == DNS_PAYLOAD_IS_SERVER_LIST &&
> +                   v1->hdr.version == 1 &&
> +                   (v1->status != DNS_LOOKUP_GOOD &&
> +                    v1->status != DNS_LOOKUP_GOOD_WITH_BAD))
> +                       return -ENOENT;
> +
> +       }
> +
> +       kfree(result);
>         return ret;
>  }

Marc

  reply	other threads:[~2023-12-11 17:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11 16:34 [PATCH 0/3] afs: Fix dynamic root interaction with failing DNS lookups David Howells
2023-12-11 16:34 ` [PATCH 1/3] afs: Fix the dynamic root's d_delete to always delete unused dentries David Howells
2023-12-11 16:34 ` [PATCH 2/3] afs: Fix dynamic root lookup DNS check David Howells
2023-12-11 17:37   ` Marc Dionne [this message]
2023-12-11 16:34 ` [PATCH 3/3] keys, dns: Allow key types (eg. DNS) to be reclaimed immediately on expiry David Howells
2023-12-11 16:40 ` [PATCH 0/3] afs: Fix dynamic root interaction with failing DNS lookups David Howells
2023-12-11 21:33 ` markus.suvanto
2023-12-12  9:03 ` David Howells
2023-12-12  9:41   ` markus.suvanto
2023-12-12  9:49   ` David Howells
2023-12-12  9:57     ` markus.suvanto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAB9dFdsCnAeitHcNJRY+f8eG=exrgpBZpczfMhHHXLvCR32MaA@mail.gmail.com' \
    --to=marc.dionne@auristor.com \
    --cc=dhowells@redhat.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus.suvanto@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).