Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  *
0003  * Copyright (C) 2021 Microsoft Corporation
0004  *
0005  * Author: Tushar Sugandhi <tusharsu@linux.microsoft.com>
0006  *
0007  * File: dm-ima.h
0008  *       Header file for device mapper IMA measurements.
0009  */
0010 
0011 #ifndef DM_IMA_H
0012 #define DM_IMA_H
0013 
0014 #define DM_IMA_MEASUREMENT_BUF_LEN  4096
0015 #define DM_IMA_DEVICE_BUF_LEN       1024
0016 #define DM_IMA_TARGET_METADATA_BUF_LEN  128
0017 #define DM_IMA_TARGET_DATA_BUF_LEN  2048
0018 #define DM_IMA_DEVICE_CAPACITY_BUF_LEN  128
0019 #define DM_IMA_TABLE_HASH_ALG       "sha256"
0020 
0021 #define __dm_ima_stringify(s) #s
0022 #define __dm_ima_str(s) __dm_ima_stringify(s)
0023 
0024 #define DM_IMA_VERSION_STR "dm_version="    \
0025     __dm_ima_str(DM_VERSION_MAJOR) "."  \
0026     __dm_ima_str(DM_VERSION_MINOR) "."  \
0027     __dm_ima_str(DM_VERSION_PATCHLEVEL) ";"
0028 
0029 #ifdef CONFIG_IMA
0030 
0031 struct dm_ima_device_table_metadata {
0032     /*
0033      * Contains data specific to the device which is common across
0034      * all the targets in the table (e.g. name, uuid, major, minor, etc).
0035      * The values are stored in comma separated list of key1=val1,key2=val2;
0036      * pairs delimited by a semicolon at the end of the list.
0037      */
0038     char *device_metadata;
0039     unsigned int device_metadata_len;
0040     unsigned int num_targets;
0041 
0042     /*
0043      * Contains the sha256 hashes of the IMA measurements of the target
0044      * attributes' key-value pairs from the active/inactive tables.
0045      */
0046     char *hash;
0047     unsigned int hash_len;
0048 };
0049 
0050 /*
0051  * This structure contains device metadata, and table hash for
0052  * active and inactive tables for ima measurements.
0053  */
0054 struct dm_ima_measurements {
0055     struct dm_ima_device_table_metadata active_table;
0056     struct dm_ima_device_table_metadata inactive_table;
0057     unsigned int dm_version_str_len;
0058 };
0059 
0060 void dm_ima_reset_data(struct mapped_device *md);
0061 void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags);
0062 void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap);
0063 void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all);
0064 void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map);
0065 void dm_ima_measure_on_device_rename(struct mapped_device *md);
0066 
0067 #else
0068 
0069 static inline void dm_ima_reset_data(struct mapped_device *md) {}
0070 static inline void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags) {}
0071 static inline void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap) {}
0072 static inline void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all) {}
0073 static inline void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map) {}
0074 static inline void dm_ima_measure_on_device_rename(struct mapped_device *md) {}
0075 
0076 #endif /* CONFIG_IMA */
0077 
0078 #endif /* DM_IMA_H */