1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/list.h>
4 #include <linux/kernel.h>
5 #include <linux/dm-verity-loadpin.h>
11 #define DM_MSG_PREFIX "verity-loadpin"
13 LIST_HEAD(dm_verity_loadpin_trusted_root_digests);
15 static bool is_trusted_verity_target(struct dm_target *ti)
19 unsigned int digest_size;
20 struct dm_verity_loadpin_trusted_root_digest *trd;
23 if (!dm_is_verity_target(ti))
26 verity_mode = dm_verity_get_mode(ti);
28 if ((verity_mode != DM_VERITY_MODE_EIO) &&
29 (verity_mode != DM_VERITY_MODE_RESTART) &&
30 (verity_mode != DM_VERITY_MODE_PANIC))
33 if (dm_verity_get_root_digest(ti, &root_digest, &digest_size))
36 list_for_each_entry(trd, &dm_verity_loadpin_trusted_root_digests, node) {
37 if ((trd->len == digest_size) &&
38 !memcmp(trd->data, root_digest, digest_size)) {
50 * Determines whether the file system of a superblock is located on
51 * a verity device that is trusted by LoadPin.
53 bool dm_verity_loadpin_is_bdev_trusted(struct block_device *bdev)
55 struct mapped_device *md;
56 struct dm_table *table;
61 if (list_empty(&dm_verity_loadpin_trusted_root_digests))
64 md = dm_get_md(bdev->bd_dev);
68 table = dm_get_live_table(md, &srcu_idx);
70 if (table->num_targets != 1)
73 ti = dm_table_get_target(table, 0);
75 if (is_trusted_verity_target(ti))
79 dm_put_live_table(md, srcu_idx);