From: Sascha Hauer <s.hauer@pengutronix.de>
To: Tobias Waldekranz <tobias@waldekranz.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 03/11] dm: verity: Add transparent integrity checking target
Date: Thu, 18 Sep 2025 15:06:04 +0200 [thread overview]
Message-ID: <aMwDvHXzbzpaCwey@pengutronix.de> (raw)
In-Reply-To: <20250918074455.891780-4-tobias@waldekranz.com>
On Thu, Sep 18, 2025 at 09:43:13AM +0200, Tobias Waldekranz wrote:
> Add the dm-verity target, which is compatible with the Linux
> implementation. This means that we can now create dm-verity devices on
> top of partitions containing read-only filesystems and transparently
> verify the integrity of all data is associated the verity root hash.
>
> CRUCIALLY: The root hash still has be validated by some other means,
> which is outside of the scope of this implementation. Future changes
> will add support for validation of the root hash using a PKCS#7
> signature, again compatible with the Linux kernel implementation.
>
> Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
> ---
> drivers/block/dm/Kconfig | 7 +
> drivers/block/dm/Makefile | 1 +
> drivers/block/dm/dm-target.h | 14 ++
> drivers/block/dm/dm-verity.c | 463 +++++++++++++++++++++++++++++++++++
> 4 files changed, 485 insertions(+)
> create mode 100644 drivers/block/dm/dm-verity.c
>
> +static int dm_verity_create(struct dm_target *ti, unsigned int argc, char **argv)
> +{
> + struct dm_verity *v;
> + unsigned int ver;
> + int err;
> +
> + if (argc != 10) {
> + dm_target_err(ti, "Expected 10 arguments, got %u\n", argc);
> + return -EINVAL;
> + }
For the sake of readablity, can you do a
const char *verity_version = argv[0];
const char *verity_device = argv[1];
...
and use these instead of argv[x] directly?
> +
> + if (kstrtouint(argv[0], 0, &ver) || ver != 1) {
> + dm_target_err(ti, "Only version 1 is supported, not \"%s\"\n", argv[0]);
> + return -EINVAL;
> + }
> +
> + v = xzalloc(sizeof(*v));
> + ti->private = v;
> +
> + err = dm_verity_cdev_init(ti, &v->ddev, argv[1], argv[3], argv[5], NULL);
> + if (err)
> + goto err;
> +
> + err = dm_verity_cdev_init(ti, &v->hdev, argv[2], argv[4], NULL, argv[6]);
> + if (err)
> + goto err;
> +
> + v->digest_algo = digest_alloc(argv[7]);
> + if (!v->digest_algo) {
> + dm_target_err(ti, "Unknown digest \"%s\"\n", argv[7]);
> + err = -EINVAL;
> + goto err;
> + }
> +
> + v->digest_len = digest_length(v->digest_algo);
> + if ((1 << v->hdev.blk.bits) < v->digest_len * 2) {
> + dm_target_err(ti, "Digest size too big\n");
> + err = -EINVAL;
> + goto err;
> + }
> +
> + v->root_digest = xmalloc(v->digest_len);
> + if (strlen(argv[8]) != v->digest_len * 2 ||
> + hex2bin(v->root_digest, argv[8], v->digest_len)) {
> + dm_target_err(ti, "Invalid root digest \"%s\"\n", argv[8]);
> + err = -EINVAL;
> + goto err;
> + }
> +
> + if (strcmp(argv[9], "-")) {
> + v->salt_size = strlen(argv[9]) / 2;
> + v->salt = xmalloc(v->salt_size);
> +
> + if (strlen(argv[9]) != v->salt_size * 2 ||
> + hex2bin(v->salt, argv[9], v->salt_size)) {
> + dm_target_err(ti, "Invalid salt \"%s\"\n", argv[9]);
> + err = -EINVAL;
> + goto err;
> + }
> + }
> +
> + err = dm_verity_measure(ti);
> + if (err)
> + goto err;
> +
> + /* Initialize this to a value larger than the largest possible
> + * hash block lba to make sure that the first hash block read
> + * in dm_verity_verify() always misses the cache.
> + */
> + v->verify.hblock.block = v->hdev.blk.num;
> + v->verify.hblock.data = xmalloc(1 << v->hdev.blk.bits);
> +
> + v->verify.digest = xmalloc(v->digest_len);
> + v->verify.trusted = bitmap_xzalloc(v->hdev.blk.num);
> + return 0;
> +
> +err:
> + if (v->salt)
> + free(v->salt);
> + if (v->root_digest)
> + free(v->root_digest);
No need to check. free() handles NULL pointers.
Sascha
> + if (v->digest_algo)
> + digest_free(v->digest_algo);
> + if (v->hdev.cdev)
> + cdev_close(v->hdev.cdev);
> + if (v->ddev.cdev)
> + cdev_close(v->ddev.cdev);
> +
> + free(v);
> + return err;
> +}
> +
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2025-09-18 13:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 7:43 [PATCH 00/11] " Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 01/11] dm: Add helper to manage a lower device Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 02/11] dm: linear: Refactor to make use of the generalized cdev management Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 03/11] dm: verity: Add transparent integrity checking target Tobias Waldekranz
2025-09-18 13:06 ` Sascha Hauer [this message]
2025-09-18 7:43 ` [PATCH 04/11] dm: verity: Add helper to parse superblock information Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 05/11] commands: veritysetup: Create dm-verity devices Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 06/11] ci: pytest: Open up testfs to more consumers than the FIT test Tobias Waldekranz
2025-09-22 15:38 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 07/11] ci: pytest: Enable testfs feature on malta boards Tobias Waldekranz
2025-09-22 15:40 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 08/11] ci: pytest: Generate test data for dm-verity Tobias Waldekranz
2025-09-22 15:41 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 09/11] test: pytest: add basic dm-verity test Tobias Waldekranz
2025-09-22 15:44 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 10/11] ci: pytest: Centralize feature discovery to a separate step Tobias Waldekranz
2025-09-22 15:45 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 11/11] ci: pytest: Enable device-mapper labgrid tests Tobias Waldekranz
2025-09-22 15:46 ` Ahmad Fatoum
2025-09-18 14:08 ` [PATCH 00/11] dm: verity: Add transparent integrity checking target Sascha Hauer
2025-09-18 15:38 ` Tobias Waldekranz
2025-09-23 6:30 ` Sascha Hauer
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=aMwDvHXzbzpaCwey@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=tobias@waldekranz.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