mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rodolfo Giometti <giometti@enneenne.com>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: "David Howells" <dhowells@redhat.com>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	keyrings@vger.kernel.org,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Jens Wiklander" <jenswi@kernel.org>,
	"Sumit Garg" <sumit.garg@kernel.org>,
	op-tee@lists.trustedfirmware.org,
	"Horia Geantă" <horia.geanta@nxp.com>,
	"Pankaj Gupta" <pankaj.gupta@nxp.com>,
	"Sahil Malhotra" <sahil.malhotra@nxp.com>,
	"Ahmad Fatoum" <a.fatoum@pengutronix.de>,
	"Richard Weinberger" <richard@nod.at>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Demi Marie Obenour" <demiobenour@gmail.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Paul Moore" <paul@paul-moore.com>,
	"James Morris" <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	linux-crypto@vger.kernel.org, linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-api@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	kernel@pengutronix.de
Subject: Re: [RFC PATCH 0/9] KEYS: keycrypt: keys that user space can use but never read
Date: Thu, 19 Nov 2026 11:18:35 +0100	[thread overview]
Message-ID: <3929b9f6-6c75-4118-8565-0fa815daad73@enneenne.com> (raw)
In-Reply-To: <mvyqqjhvfka3kkumztixzozrthutkq6mfakkonxqbpm5gvzb62@eitzzleeyioe>

On 18/11/2026 15:57, Marco Felsch wrote:
> Hi Rodolfo,

Hi.

> thanks for the RFC and bringing this up. Please see my comments below.

Thanks to you for reading it!

> On 26-11-18 15:04, Rodolfo Giometti wrote:
>> This RFC proposes a key type, "keycrypt", whose material user space can
> 
> Albeit I'm not against a new key-type we already have plenty types.
> 
> Furthermore the keyctl API is very open, lacks a common API. E.g. for the
> 'trusted-key' keytype userspace needs to know the actual used backend
> because each backend handles it differently.
> 
> Therefore I wouldn't add further keytypes till we have a common API
> which the userspace can rely on.

I agree that a common API is missing. keycrypt is meant to be one, for
keys that user space uses but never reads: the same ioctls on the fd
for every backend, and the same add_key() strings but for the sw
backend's master=, so user space does not need to know which backend
holds the key (unless it asks for one with backend=). What is missing
is a way to ask which backends and algorithms exist (see below).

[snip]

> So it's not a new keytype but a new mechanism to handle trusted-keys
> from userspace?

No, a keycrypt key is not a trusted key. Only the sw backend uses a
trusted key, as the master that seals its blobs; the OP-TEE and CAAM
backends use none. Also, an ELE backend, not written yet, would use
none, and it could be the first hsm backend!

[snip]

>> An embedded product that encrypts its own data (a root filesystem
>> archive, configuration backups, logs) needs a key that does not sit in
>> the root filesystem and that a compromised user space cannot copy. Today
> 								^
> 					What exactly do you mean by copy?
> 
> If you're using the standard LUKS2 scheme, the (volume)key never sits
> inside encrypted device. The key is part of the LUKS2 header. Maybe I
> didn't got your use-case, can you please elaborate a bit more?

By copy I mean getting the key's bytes to use them elsewhere. A user
key can be read back; a logon key cannot, but its bytes come from user
space at every boot, so they sit in a file. A trusted or encrypted key
fixes that, and the cover letter was wrong there: AF_ALG can use one
from user space. But, as you note below, once unsealed its bytes are
in kernel memory, so it falls with the kernel, and nothing binds it to
an algorithm or a purpose.

My use case is not a block device: it is files that an application
encrypts itself (an archive of the root filesystem, configuration
backups, logs), with a key that must not be readable on the device and
that ideally may only encrypt, or only decrypt.

You can see keycrypt keys as the symmetric counterpart of the
asymmetric keys that KEYCTL_PKEY_* already lets user space use without
reading them. The difference is that a symmetric mode keeps state
across calls (the CBC chain, a stream's segments), hence an fd instead
of one keyctl call per operation. And, as for KEYCTL_PKEY_*, the open
could become a key_type operation, so that keyctl knows no key type.

[snip]

> Above you mentioned trusted-keys, but trusted-keys don't let the key
> stay inside the TEE. Albeit the key is only reachable kernel (EL1) it is
> always reachable from normal world. So a kernel CVE could leak the key
> as well. This is different compared to protected keys like
> p(rotected)aes. Here the keys always stay within firmware/secure-world.

Yes. With the OP-TEE backend a generated key never leaves the TA,
which runs the operation, and the kernel only holds a blob it cannot
open, so even a compromised kernel can only use the key, and only for
what it was sealed for. An hsm backend, as ELE could become, would do
the same in dedicated hardware.

> I didn't get your problem from your above description, sorry and
> therefore I'm asking.
> Do you want to use trusted-keys for partition (rootfs, data, ...)
> encryption? In such case I've developed another idea which I'm about to
> post as RFC.

No, file encryption from user space, as above. In one sentence:
keycrypt gives the keyring keys that user space can use but never
read, bound to one algorithm and purpose; with a TEE backend they are
never in clear in the kernel either, and they work from a minimal
initramfs, before any user-space crypto stack exists.

That last part matters a lot on embedded systems. The initramfs
usually sits in the FIT image that the secure-boot chain must
authenticate, and often decrypt, before running it, so it must be as
small as possible (on our i.MX93 boards this runs at about 2.4MiB/s
through ELE). In such an initramfs, OP-TEE's PKCS#11 TA would also need
secure storage set up before the root filesystem (tee-supplicant with
a writable filesystem, or a provisioned RPMB); keycrypt's OP-TEE
backend needs no storage and no daemon, just the keyctl syscall and a
small tool driving the fd.

[snip]

>> 1. A key type, "keycrypt", created with add_key() from "new <alg>
>>    <purposes> [tier=|min-tier=] [backend=]", "load <blob>
>>    [accepted-min-tier=] [purpose=]" or, when allowed, "import <alg>
>>    <purposes> [tier=|min-tier=] [backend=] <hex>". User space states the
> 
> This is exactly what I meant at the begining. I'm not a maintainer, but
> this string parsing "API" is very error-prone. Furthermore, how can a
> userspace enum available backends? Instead of try and error I would like
> to see a query/enum phase and later on userspace can decide which
> backend and tier to use.

The strings follow what trusted and encrypted keys already take in
add_key(), but I'm open to another form, such as a versioned binary
struct like the one KEYCTL_CRYPT_OPEN already takes with
copy_struct_from_user().

On the enumeration you're right, there is none: a key's line in
/proc/keys and KEYCRYPT_IOC_INFO on an open fd tell its backend and
tier only after the fact. A list of the backends, with their tier and
algorithms, would be easy to add, and it is needed since algorithms
differ per backend (the CAAM one does aes256-cbc only): would a keyctl
or a file under /proc be what you have in mind?

[snip]

>>   tier     key in clear    purpose enforced by   who may use the key
>>            in the kernel
>>   kernel   yes             the kernel            the kernel
> 
> These are basically the trusted-key purpose.

Yes, the kernel tier gives the protection of a trusted key, and it does
not meet the goal above. It is there only so that the same interface
works on systems with nothing better; its only backend, sw, is
optional and off by default, and it can go if it is considered wrong.

>>   engine   no              the kernel            the kernel
>>   tee      no              the TA                the kernel
>>   hsm      no              the HSM               the kernel
> 
> These are protected keys which we have already (see S390, CAAM, DCP,
> Zynqmp, ...).
> 
> I don't see what you want to solve with your approach. Do you want to
> have a common interface for generating/loading protected keys?

Yes, and for using them from user space, with a purpose bound to each
key (encrypt-only, decrypt-only, verify-only) that the TA, or an HSM,
enforces. keycrypt does not replace the protected keys you name: a
backend is where such a key lives.

> That beeing said, loading protected keys can already be done by just
> specifying the correct key-cipher. Generating the key is platform
> specific and would need a common API.

For user space that means AF_ALG with cbc(paes) only (the CAAM,
CryptoCell and s390 register one AF_ALG can reach; DCP's is internal),
each driver with its own key format, and since v7.3 privileged by
default (d9506e82ced5). Generating is what "new" does in keycrypt:
with OP-TEE the TA generates the key itself. The CAAM patches are only
a prototype there: they still generate the key in kernel memory, and
the aim is to have the CAAM generate it and keep it black (one of the
questions to the CAAM maintainers in the cover letter).

> Thanks for sharing your ideas :)

:)

Ciao,

Rodolfo

-- 
GNU/Linux Solutions                  e-mail: giometti@enneenne.com
Linux Device Driver                          giometti@linux.it
Embedded Systems                     phone:  +39 349 2432127
UNIX programming

  parent reply	other threads:[~2026-11-19 10:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:04 Rodolfo Giometti
2026-11-18 14:04 ` [RFC PATCH 1/9] KEYS: keycrypt: Add a key type for keys user space never reads Rodolfo Giometti
2026-11-18 14:04 ` [RFC PATCH 2/9] KEYS: keycrypt: Add the sw backend Rodolfo Giometti
2026-11-18 14:04 ` [RFC PATCH 3/9] KEYS: keycrypt: Add the OP-TEE backend Rodolfo Giometti
2026-11-18 14:07 ` [RFC PATCH 4/9] docs: keycrypt: document keycrypt keys Rodolfo Giometti
2026-11-18 14:08 ` [RFC PATCH 5/9] MAINTAINERS: add KEYS-KEYCRYPT Rodolfo Giometti
2026-11-18 14:09 ` [RFC PATCH 6/9] KEYS: keycrypt: Add the engine tier Rodolfo Giometti
2026-11-18 14:10 ` [RFC PATCH 7/9] crypto: caam - add an internal cbc(paes) taking the blob's key modifier Rodolfo Giometti
2026-11-18 14:11 ` [RFC PATCH 8/9] KEYS: keycrypt: Add the CAAM backend Rodolfo Giometti
2026-11-18 14:12 ` [RFC PATCH 9/9] KEYS: keycrypt: Add the aes256-gcm-stream algorithm Rodolfo Giometti
2026-11-19  0:25   ` Demi Marie Obenour
2026-11-19  0:55     ` Jarkko Sakkinen
2026-11-18 14:31 ` [RFC PATCH 0/9] KEYS: keycrypt: keys that user space can use but never read Jarkko Sakkinen
2026-11-18 14:39   ` Jarkko Sakkinen
2026-11-18 14:57 ` Marco Felsch
2026-11-18 15:07   ` Jarkko Sakkinen
2026-11-19 10:18   ` Rodolfo Giometti [this message]
2026-11-18 23:42 ` Demi Marie Obenour
2026-11-19  0:37   ` Jarkko Sakkinen
2026-11-19  0:43     ` Demi Marie Obenour
2026-11-19  1:01       ` Jarkko Sakkinen
2026-11-19  4:35       ` Demi Marie Obenour
2026-11-19  5:01         ` Jarkko Sakkinen
2026-11-19 12:17         ` Rodolfo Giometti
2026-11-19 10:19     ` Rodolfo Giometti

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=3929b9f6-6c75-4118-8565-0fa815daad73@enneenne.com \
    --to=giometti@enneenne.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=arnd@arndb.de \
    --cc=chleroy@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=demiobenour@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=jarkko@kernel.org \
    --cc=jenswi@kernel.org \
    --cc=jmorris@namei.org \
    --cc=kernel@pengutronix.de \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=m.felsch@pengutronix.de \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=pankaj.gupta@nxp.com \
    --cc=paul@paul-moore.com \
    --cc=rdunlap@infradead.org \
    --cc=richard@nod.at \
    --cc=sahil.malhotra@nxp.com \
    --cc=serge@hallyn.com \
    --cc=skhan@linuxfoundation.org \
    --cc=sumit.garg@kernel.org \
    /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®