]> git.ipfire.org Git - thirdparty/linux.git/commit
blk-crypto: add ioctls to create and prepare hardware-wrapped keys
authorEric Biggers <ebiggers@google.com>
Tue, 4 Feb 2025 06:00:37 +0000 (22:00 -0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 10 Feb 2025 16:54:19 +0000 (09:54 -0700)
commit1ebd4a3c095cd538d3c1c7c12738ef47d8e71f96
treefe558921c4164578895912eff0c1f14cb617d320
parente35fde43e25ad725d27315992fba8088d1210b01
blk-crypto: add ioctls to create and prepare hardware-wrapped keys

Until this point, the kernel can use hardware-wrapped keys to do
encryption if userspace provides one -- specifically a key in
ephemerally-wrapped form.  However, no generic way has been provided for
userspace to get such a key in the first place.

Getting such a key is a two-step process.  First, the key needs to be
imported from a raw key or generated by the hardware, producing a key in
long-term wrapped form.  This happens once in the whole lifetime of the
key.  Second, the long-term wrapped key needs to be converted into
ephemerally-wrapped form.  This happens each time the key is "unlocked".

In Android, these operations are supported in a generic way through
KeyMint, a userspace abstraction layer.  However, that method is
Android-specific and can't be used on other Linux systems, may rely on
proprietary libraries, and also misleads people into supporting KeyMint
features like rollback resistance that make sense for other KeyMint keys
but don't make sense for hardware-wrapped inline encryption keys.

Therefore, this patch provides a generic kernel interface for these
operations by introducing new block device ioctls:

- BLKCRYPTOIMPORTKEY: convert a raw key to long-term wrapped form.

- BLKCRYPTOGENERATEKEY: have the hardware generate a new key, then
  return it in long-term wrapped form.

- BLKCRYPTOPREPAREKEY: convert a key from long-term wrapped form to
  ephemerally-wrapped form.

These ioctls are implemented using new operations in blk_crypto_ll_ops.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Tested-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> # sm8650
Link: https://lore.kernel.org/r/20250204060041.409950-4-ebiggers@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Documentation/block/inline-encryption.rst
Documentation/userspace-api/ioctl/ioctl-number.rst
block/blk-crypto-internal.h
block/blk-crypto-profile.c
block/blk-crypto.c
block/ioctl.c
include/linux/blk-crypto-profile.h
include/linux/blk-crypto.h
include/uapi/linux/blk-crypto.h [new file with mode: 0644]
include/uapi/linux/fs.h