dm-ima.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright (C) 2021 Microsoft Corporation
  4. *
  5. * Author: Tushar Sugandhi <[email protected]>
  6. *
  7. * File: dm-ima.h
  8. * Header file for device mapper IMA measurements.
  9. */
  10. #ifndef DM_IMA_H
  11. #define DM_IMA_H
  12. #define DM_IMA_MEASUREMENT_BUF_LEN 4096
  13. #define DM_IMA_DEVICE_BUF_LEN 1024
  14. #define DM_IMA_TARGET_METADATA_BUF_LEN 128
  15. #define DM_IMA_TARGET_DATA_BUF_LEN 2048
  16. #define DM_IMA_DEVICE_CAPACITY_BUF_LEN 128
  17. #define DM_IMA_TABLE_HASH_ALG "sha256"
  18. #define __dm_ima_stringify(s) #s
  19. #define __dm_ima_str(s) __dm_ima_stringify(s)
  20. #define DM_IMA_VERSION_STR "dm_version=" \
  21. __dm_ima_str(DM_VERSION_MAJOR) "." \
  22. __dm_ima_str(DM_VERSION_MINOR) "." \
  23. __dm_ima_str(DM_VERSION_PATCHLEVEL) ";"
  24. #ifdef CONFIG_IMA
  25. struct dm_ima_device_table_metadata {
  26. /*
  27. * Contains data specific to the device which is common across
  28. * all the targets in the table (e.g. name, uuid, major, minor, etc).
  29. * The values are stored in comma separated list of key1=val1,key2=val2;
  30. * pairs delimited by a semicolon at the end of the list.
  31. */
  32. char *device_metadata;
  33. unsigned int device_metadata_len;
  34. unsigned int num_targets;
  35. /*
  36. * Contains the sha256 hashes of the IMA measurements of the target
  37. * attributes' key-value pairs from the active/inactive tables.
  38. */
  39. char *hash;
  40. unsigned int hash_len;
  41. };
  42. /*
  43. * This structure contains device metadata, and table hash for
  44. * active and inactive tables for ima measurements.
  45. */
  46. struct dm_ima_measurements {
  47. struct dm_ima_device_table_metadata active_table;
  48. struct dm_ima_device_table_metadata inactive_table;
  49. unsigned int dm_version_str_len;
  50. };
  51. void dm_ima_reset_data(struct mapped_device *md);
  52. void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags);
  53. void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap);
  54. void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all);
  55. void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map);
  56. void dm_ima_measure_on_device_rename(struct mapped_device *md);
  57. #else
  58. static inline void dm_ima_reset_data(struct mapped_device *md) {}
  59. static inline void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags) {}
  60. static inline void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap) {}
  61. static inline void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all) {}
  62. static inline void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map) {}
  63. static inline void dm_ima_measure_on_device_rename(struct mapped_device *md) {}
  64. #endif /* CONFIG_IMA */
  65. #endif /* DM_IMA_H */