From: Mikulas Patocka <mpatocka@redhat.com>
To: Lorenz Kofler <lorenz@sigma-star.at>, Eric Biggers <ebiggers@google.com>
Cc: Mike Snitzer <snitzer@kernel.org>,
Benjamin Marzinski <bmarzins@redhat.com>,
Alasdair Kergon <agk@redhat.com>,
dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
upstream+dm@sigma-star.at, David Howells <dhowells@redhat.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
keyrings@vger.kernel.org
Subject: Re: [RFC PATCH 1/1] dm-integrity: support keys in the kernel keyring
Date: Fri, 2 Oct 2026 13:48:23 +0200 (CEST) [thread overview]
Message-ID: <1e53661e-42f4-72b2-3331-33af21e9fe0f@redhat.com> (raw)
In-Reply-To: <b0f8f47a-beb0-426e-bdee-5d0d80ade8ad@sigma-star.at>
On Fri, 2 Oct 2026, Lorenz Kofler wrote:
> Hi Mikulas,
>
> thank you for the review!
>
> Some notes below.
>
> >> +#ifdef CONFIG_KEYS
> >> +
> >> +static bool contains_whitespace(const char *str)
> >> +{
> >> + while (*str)
> >> + if (isspace(*str++))
> >> + return true;
> >> + return false;
> >> +}
> >> +
> >> +static int set_key_user(struct alg_spec *a, struct key *key)
> >> +{
> >> + const struct user_key_payload *ukp;
> >> +
> >> + ukp = user_key_payload_locked(key);
> >> + if (!ukp)
> >> + return -EKEYREVOKED;
> >> +
> >> + if (a->key_size != ukp->datalen)
> >> + return -EINVAL;
> >> +
> >> + memcpy(a->key, ukp->data, a->key_size);
> >> +
> >> + return 0;
> >> +}
> >> +
> >> +static int set_key_encrypted(struct alg_spec *a, struct key *key)
> >> +{
> >> + const struct encrypted_key_payload *ekp;
> >> +
> >> + ekp = key->payload.data[0];
> >> + if (!ekp)
> >> + return -EKEYREVOKED;
> >> +
> >> + if (a->key_size != ekp->decrypted_datalen)
> >> + return -EINVAL;
> >> +
> >> + memcpy(a->key, ekp->decrypted_data, a->key_size);
> >> +
> >> + return 0;
> >> +}
> >> +
> >> +static int set_key_trusted(struct alg_spec *a, struct key *key)
> >> +{
> >> + const struct trusted_key_payload *tkp;
> >> +
> >> + tkp = key->payload.data[0];
> >> + if (!tkp)
> >> + return -EKEYREVOKED;
> >> +
> >> + if (a->key_size != tkp->key_len)
> >> + return -EINVAL;
> >> +
> >> + memcpy(a->key, tkp->key, a->key_size);
> >> +
> >> + return 0;
> >> +}
> >
> > These four functions are copied from dm-crypt.c and dm-inlinecrypt.c.
> > Copying code is generally malpattern, they should be unified and moved to
> > an include file (that would be included in all three targets) or to the
> > key management code (that would be called from all three targets).
> >
>
> Yes that is the issue I described in the cover letters. But I don't
> actually know which way is the preferred one. Afaik there are now
> three options:
>
> 1. static inline helpers in a drivers/md header, so dm-crypt and
> dm-integrity each compile their own copy
> 2. a small library module, similar to dm-bufio, so there is one copy
> that follows the value (y/m) of dm-crypt and dm-integrity
> 3. integration into key management code
>
> Please tell me which option you prefer.
Try 3, if not possible then 1. I think that introducing a module with this
would be overkill.
The "if (!strncmp(key_string, "logon:", key_desc - key_string + 1)) {"
lines are duplicated as well, so I would refactor them and move them to
the helper too.
I don't know why dm-inlinecrypt only uses the "logon:" key while dm-crypt
uses "user:", "encrypted:", "trusted:" as well (Eric - could you
explain?). So, perhaps, dm-inlinecrypt could be extended to use all four
key types as well.
I CC'd keyrings maintainers - so, if they have some suggestions or
objections regarding moving the code there, let them say.
Mikulas
next prev parent reply other threads:[~2026-10-02 11:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 6:27 [RFC PATCH 0/1] " Lorenz Kofler
2026-09-28 6:27 ` [RFC PATCH 1/1] " Lorenz Kofler
2026-09-30 15:00 ` Mikulas Patocka
2026-10-02 9:12 ` Lorenz Kofler
2026-10-02 11:48 ` Mikulas Patocka [this message]
2026-10-02 20:14 ` Eric Biggers
2026-10-02 21:09 ` Mikulas Patocka
2026-10-04 7:44 ` Milan Broz
2026-10-04 17:29 ` Eric Biggers
2026-10-05 6:20 ` Milan Broz
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=1e53661e-42f4-72b2-3331-33af21e9fe0f@redhat.com \
--to=mpatocka@redhat.com \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=dhowells@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=ebiggers@google.com \
--cc=jarkko@kernel.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenz@sigma-star.at \
--cc=snitzer@kernel.org \
--cc=upstream+dm@sigma-star.at \
/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
all inboxes | Powered by JetHome®