Skip to contentSkip to conversation

dm-ima: use SHA-256 library

PATCH New Eric Biggers 1 participant 1 message Feb 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-ima: use SHA-256 library

Make dm_ima_measure_on_table_load() use the SHA-256 library API instead of crypto_shash to calculate the SHA-256 hash value that it needs. This is simpler and more efficient. It also ensures that SHA-256 is actually available and doesn't fail due to the unreliable loading by name.

While doing this, also use kasprintf() to simplify building the string version of the digest.

---
 drivers/md/Kconfig  |  1 +
 drivers/md/dm-ima.c | 54 +++++++++------------------------------------
 drivers/md/dm-ima.h |  1 -
 3 files changed, 11 insertions(+), 45 deletions(-)
drivers/md/Kconfig +1 -0
index c58a9a8ea54e..53351048d3ec 100644
@@ -224,10 +224,11 @@ config BLK_DEV_DM_BUILTIN
 config BLK_DEV_DM
 	tristate "Device mapper support"
 	select BLOCK_HOLDER_DEPRECATED if SYSFS
 	select BLK_DEV_DM_BUILTIN
 	select BLK_MQ_STACKING
+	select CRYPTO_LIB_SHA256 if IMA
 	depends on DAX || DAX=n
 	help
 	  Device-mapper is a low level volume manager.  It works by allowing
 	  people to specify mappings for ranges of logical sectors.  Various
 	  mapping types are available, in addition people may write their own
drivers/md/dm-ima.c +10 -44

129 lines not on this page · raw message

drivers/md/dm-ima.h +0 -1
index 568870a1a145..a403deca6093 100644
@@ -13,11 +13,10 @@
 #define DM_IMA_MEASUREMENT_BUF_LEN	4096
 #define DM_IMA_DEVICE_BUF_LEN		1024
 #define DM_IMA_TARGET_METADATA_BUF_LEN	128
 #define DM_IMA_TARGET_DATA_BUF_LEN	2048
 #define DM_IMA_DEVICE_CAPACITY_BUF_LEN	128
-#define DM_IMA_TABLE_HASH_ALG		"sha256"
 
 #define __dm_ima_stringify(s) #s
 #define __dm_ima_str(s) __dm_ima_stringify(s)
 
 #define DM_IMA_VERSION_STR "dm_version="	\

base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f

Signature · 1 line
2.53.0