printf: Remove unused 'bprintf'
[drm/drm-misc.git] / drivers / md / dm-verity-loadpin.c
blob0666699b6858166227131e17a0da99e5ae22a4c2
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>
7 #include "dm.h"
8 #include "dm-core.h"
9 #include "dm-verity.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)
17 int verity_mode;
18 u8 *root_digest;
19 unsigned int digest_size;
20 struct dm_verity_loadpin_trusted_root_digest *trd;
21 bool trusted = false;
23 if (!dm_is_verity_target(ti))
24 return false;
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))
31 return false;
33 if (dm_verity_get_root_digest(ti, &root_digest, &digest_size))
34 return false;
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)) {
39 trusted = true;
40 break;
44 kfree(root_digest);
46 return trusted;
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;
57 struct dm_target *ti;
58 int srcu_idx;
59 bool trusted = false;
61 if (bdev == NULL)
62 return false;
64 if (list_empty(&dm_verity_loadpin_trusted_root_digests))
65 return false;
67 md = dm_get_md(bdev->bd_dev);
68 if (!md)
69 return false;
71 table = dm_get_live_table(md, &srcu_idx);
73 if (table->num_targets != 1)
74 goto out;
76 ti = dm_table_get_target(table, 0);
78 if (is_trusted_verity_target(ti))
79 trusted = true;
81 out:
82 dm_put_live_table(md, srcu_idx);
83 dm_put(md);
85 return trusted;