Skip to content

Commit 8f509fd

Browse files
Tushar Sugandhisnitm
authored andcommitted
dm ima: prefix dm table hashes in ima log with hash algorithm
The active/inactive table hashes measured in the ima log do not contain the information about hash algorithm. This information is useful for the attestation servers to recreate the hashes and compare them with the ones present in the ima log to verify the table contents. Prefix the table hashes in various DM events in ima log with the hash algorithm used to compute those hashes. Signed-off-by: Tushar Sugandhi <[email protected]> Suggested-by: Mimi Zohar <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 528b16b commit 8f509fd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

drivers/md/dm-ima.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_fl
186186
struct crypto_shash *tfm = NULL;
187187
u8 *digest = NULL;
188188
bool noio = false;
189+
/*
190+
* In below hash_alg_prefix_len assignment +1 is for the additional char (':'),
191+
* when prefixing the hash value with the hash algorithm name. e.g. sha256:<hash_value>.
192+
*/
193+
const size_t hash_alg_prefix_len = strlen(DM_IMA_TABLE_HASH_ALG) + 1;
189194

190195
ima_buf = dm_ima_alloc(DM_IMA_MEASUREMENT_BUF_LEN, GFP_KERNEL, noio);
191196
if (!ima_buf)
@@ -204,7 +209,7 @@ void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_fl
204209
if (dm_ima_alloc_and_copy_device_data(table->md, &device_data_buf, num_targets, noio))
205210
goto error;
206211

207-
tfm = crypto_alloc_shash("sha256", 0, 0);
212+
tfm = crypto_alloc_shash(DM_IMA_TABLE_HASH_ALG, 0, 0);
208213
if (IS_ERR(tfm))
209214
goto error;
210215

@@ -315,12 +320,15 @@ void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_fl
315320
if (r < 0)
316321
goto error;
317322

318-
digest_buf = dm_ima_alloc((digest_size*2)+1, GFP_KERNEL, noio);
323+
digest_buf = dm_ima_alloc((digest_size*2) + hash_alg_prefix_len + 1, GFP_KERNEL, noio);
324+
319325
if (!digest_buf)
320326
goto error;
321327

328+
snprintf(digest_buf, hash_alg_prefix_len + 1, "%s:", DM_IMA_TABLE_HASH_ALG);
329+
322330
for (i = 0; i < digest_size; i++)
323-
snprintf((digest_buf+(i*2)), 3, "%02x", digest[i]);
331+
snprintf((digest_buf + hash_alg_prefix_len + (i*2)), 3, "%02x", digest[i]);
324332

325333
if (table->md->ima.active_table.hash != table->md->ima.inactive_table.hash)
326334
kfree(table->md->ima.inactive_table.hash);

drivers/md/dm-ima.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define DM_IMA_TARGET_METADATA_BUF_LEN 128
1717
#define DM_IMA_TARGET_DATA_BUF_LEN 2048
1818
#define DM_IMA_DEVICE_CAPACITY_BUF_LEN 128
19+
#define DM_IMA_TABLE_HASH_ALG "sha256"
1920

2021
#ifdef CONFIG_IMA
2122

0 commit comments

Comments
 (0)