162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2021 Microsoft Corporation 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Author: Tushar Sugandhi <tusharsu@linux.microsoft.com> 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Header file for device mapper IMA measurements. 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef DM_IMA_H 1162306a36Sopenharmony_ci#define DM_IMA_H 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define DM_IMA_MEASUREMENT_BUF_LEN 4096 1462306a36Sopenharmony_ci#define DM_IMA_DEVICE_BUF_LEN 1024 1562306a36Sopenharmony_ci#define DM_IMA_TARGET_METADATA_BUF_LEN 128 1662306a36Sopenharmony_ci#define DM_IMA_TARGET_DATA_BUF_LEN 2048 1762306a36Sopenharmony_ci#define DM_IMA_DEVICE_CAPACITY_BUF_LEN 128 1862306a36Sopenharmony_ci#define DM_IMA_TABLE_HASH_ALG "sha256" 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#define __dm_ima_stringify(s) #s 2162306a36Sopenharmony_ci#define __dm_ima_str(s) __dm_ima_stringify(s) 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define DM_IMA_VERSION_STR "dm_version=" \ 2462306a36Sopenharmony_ci __dm_ima_str(DM_VERSION_MAJOR) "." \ 2562306a36Sopenharmony_ci __dm_ima_str(DM_VERSION_MINOR) "." \ 2662306a36Sopenharmony_ci __dm_ima_str(DM_VERSION_PATCHLEVEL) ";" 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#ifdef CONFIG_IMA 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistruct dm_ima_device_table_metadata { 3162306a36Sopenharmony_ci /* 3262306a36Sopenharmony_ci * Contains data specific to the device which is common across 3362306a36Sopenharmony_ci * all the targets in the table (e.g. name, uuid, major, minor, etc). 3462306a36Sopenharmony_ci * The values are stored in comma separated list of key1=val1,key2=val2; 3562306a36Sopenharmony_ci * pairs delimited by a semicolon at the end of the list. 3662306a36Sopenharmony_ci */ 3762306a36Sopenharmony_ci char *device_metadata; 3862306a36Sopenharmony_ci unsigned int device_metadata_len; 3962306a36Sopenharmony_ci unsigned int num_targets; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci /* 4262306a36Sopenharmony_ci * Contains the sha256 hashes of the IMA measurements of the target 4362306a36Sopenharmony_ci * attributes' key-value pairs from the active/inactive tables. 4462306a36Sopenharmony_ci */ 4562306a36Sopenharmony_ci char *hash; 4662306a36Sopenharmony_ci unsigned int hash_len; 4762306a36Sopenharmony_ci}; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* 5062306a36Sopenharmony_ci * This structure contains device metadata, and table hash for 5162306a36Sopenharmony_ci * active and inactive tables for ima measurements. 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_cistruct dm_ima_measurements { 5462306a36Sopenharmony_ci struct dm_ima_device_table_metadata active_table; 5562306a36Sopenharmony_ci struct dm_ima_device_table_metadata inactive_table; 5662306a36Sopenharmony_ci unsigned int dm_version_str_len; 5762306a36Sopenharmony_ci}; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_civoid dm_ima_reset_data(struct mapped_device *md); 6062306a36Sopenharmony_civoid dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags); 6162306a36Sopenharmony_civoid dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap); 6262306a36Sopenharmony_civoid dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all); 6362306a36Sopenharmony_civoid dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map); 6462306a36Sopenharmony_civoid dm_ima_measure_on_device_rename(struct mapped_device *md); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci#else 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_cistatic inline void dm_ima_reset_data(struct mapped_device *md) {} 6962306a36Sopenharmony_cistatic inline void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags) {} 7062306a36Sopenharmony_cistatic inline void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap) {} 7162306a36Sopenharmony_cistatic inline void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all) {} 7262306a36Sopenharmony_cistatic inline void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map) {} 7362306a36Sopenharmony_cistatic inline void dm_ima_measure_on_device_rename(struct mapped_device *md) {} 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#endif /* CONFIG_IMA */ 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci#endif /* DM_IMA_H */ 78