From: Jarkko Sakkinen <jarkko@kernel.org>
To: Guixiong Wei <weiguixiong@bytedance.com>
Cc: David Howells <dhowells@redhat.com>,
keyrings@vger.kernel.org, Paul Moore <paul@paul-moore.com>,
James Morris <jmorris@namei.org>,
"Serge E . Hallyn" <serge@hallyn.com>,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KEYS: do not let an unmatched key decide the search result
Date: Mon, 9 Nov 2026 03:17:25 +0200 [thread overview]
Message-ID: <avEfJT6hg-SCr7SN@kernel.org> (raw)
In-Reply-To: <451788d5e97cba38274e663d2b7952c593e959be.f77cb812.a801.42ef.9775.d2480a239fa8@bytedance.com>
On Mon, Nov 09, 2026 at 09:10:08AM +0800, Guixiong Wei wrote:
>
> > From: "Jarkko Sakkinen"<jarkko@kernel.org>
> > Date: Mon, Nov 9, 2026, 03:01
> > Subject: Re: [PATCH] KEYS: do not let an unmatched key decide the search result
> > To: "Guixiong Wei"<weiguixiong@bytedance.com>
> > Cc: "David Howells"<dhowells@redhat.com>, <keyrings@vger.kernel.org>, "Paul Moore"<paul@paul-moore.com>, "James Morris"<jmorris@namei.org>, "Serge E . Hallyn"<serge@hallyn.com>, <linux-security-module@vger.kernel.org>, <linux-kernel@vger.kernel.org>
> > On Sun, Nov 08, 2026 at 09:14:12PM +0800, Guixiong Wei wrote:
> > > KEYCTL_SEARCH returns -ENOKEY, -EKEYREVOKED, or -EKEYEXPIRED for the key
> > > selected by type and description. keyring_search_iterator() currently
> > > records revoked or expired state before asking the key type whether the key
> > > matches.
> >
> > I don't understand the "asking the key type or" part here. Please,
> > explain what you mean.
> >
> I meant calling ctx->match_data.cmp() to check whether a candidate key
> matches the search request. For dns_resolver, this calls
> dns_resolver_cmp() to compare the candidate's description with the
> requested name. I'll make that explicit in v2.
>
> > >
> > > Direct lookup visits the indexed description, so that ordering normally
> >
> > "Direct lookup visits the indexed description"
> >
> > I don't honestly understand this type of jargon, which is all over the
> > place.
> >
> I meant that assoc_array_find() looks up a candidate using the requested
> type and description. The dns_resolver search instead walks the keys and
> checks their descriptions using dns_resolver_cmp().
> I'll rewrite the commit message around your foo/bar example.
>
> > > does not matter. Iterative lookup visits every key of the requested type,
> > > however. The in-tree asymmetric id/ex/dn lookups and dns_resolver use this
> > > mode. A revoked key with a different description can therefore make
> > > KEYCTL_SEARCH return -EKEYREVOKED instead of continuing the search. It can
> > > also prevent request_key_and_link() from issuing an upcall because that
> > > path only upcalls after -EAGAIN. An unmatched expired key similarly
> > > pollutes searches that do not set KEYRING_SEARCH_SKIP_EXPIRED; the request
> > > path itself sets that flag.
> > >
> > > Run the type comparator before recording state errors, so only a key that
> > > matches the caller's criterion can decide the search result.
> >
> >
> > Can you describe instead describe the what goes wrong with an example,
> > which does not require much effort:
> >
> > keyctl new_session >/dev/null
> > A=$(printf '127.0.0.1\0' | keyctl padd dns_resolver foo @s)
> > keyctl revoke "$A"
> > keyctl search @s dns_resolver bar
> >
> > Results:
> >
> > keyctl_search: Key has been revoked
> >
> Thanks for the reproducer. The expected result is -ENOKEY because "bar"
> is absent.
>
> When the search encounters "foo", keyring_search_iterator() sets
> ctx->result to -EKEYREVOKED and skips that candidate before calling
> dns_resolver_cmp(). It therefore never checks whether "foo" matches
> "bar".
>
> The walk continues, but in this example it finishes with ctx->result
> still set to -EKEYREVOKED. My wording "instead of continuing the search"
> was inaccurate.
>
> The patch moves the match check before the state checks, so "foo" is
> skipped without changing ctx->result.
>
> > This example alone is not of course enough because it is lacking
> > explanation what goes wrong, which is neither clearly described by
> > the commit message but you could add my reported-by because at
> > least I constructe a real bug report that justifies this fix.
> Thanks, I will add your Reported-by.
Yeah, just sorting things out in proper order :-) Do those changes for
v2 and this should be good to go.
Br, Jarkko
prev parent reply other threads:[~2026-11-09 1:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 13:14 [PATCH] KEYS: do not let an unmatched key decide the search result Guixiong Wei
2026-11-08 13:24 ` sashiko-bot
2026-11-08 19:01 ` Jarkko Sakkinen
2026-11-09 1:10 ` Guixiong Wei
2026-11-09 1:17 ` Jarkko Sakkinen [this message]
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=avEfJT6hg-SCr7SN@kernel.org \
--to=jarkko@kernel.org \
--cc=dhowells@redhat.com \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.com \
--cc=weiguixiong@bytedance.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.