EVM: add some debugging info
Subsystems (4)
Mimi Zohar
maintainercover EVM: add some debugging info
With the recent EVM portable & immutable signature usability improvements and the ability of including the EVM portable signatures in the IMA measurement list, adding some debugging information - security xattrs and file metadata (misc info) - would be useful.
Suggestons on how to improve this patch set would be much appreciated.
thanks,
Mimi
Mimi Zohar (2):
ima: differentiate between EVM failures in the audit log
evm: output EVM digest calculation info needed for debugging
security/integrity/evm/evm.h | 1 + security/integrity/evm/evm_crypto.c | 7 +++++++ security/integrity/evm/evm_main.c | 19 +++++++++++++++++++ security/integrity/ima/ima_appraise.c | 3 ++- 4 files changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.27.0
Mimi Zohar
maintainerRFC PATCH 1/2 ima: differentiate between EVM failures in the audit log
Differenatiate between an invalid EVM portable signature failure from other EVM HMAC/signature failures.
--- security/integrity/ima/ima_appraise.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/integrity/ima/ima_appraise.c +2 -1
@@ -422,7 +422,8 @@ int ima_appraise_measurement(enum ima_hooks func, goto out;case INTEGRITY_FAIL_IMMUTABLE :set_bit (IMA_DIGSIG , &iint->atomic_flags); - fallthrough; + cause ="invalid-fail-immutable" ; + goto out;case INTEGRITY_FAIL :/* Invalid HMAC/signature. */ cause ="invalid-HMAC" ; goto out;
Signature · 1 line
2.27.0
RE: [RFC PATCH 1/2] ima: differentiate between EVM failures in the audit log
Quoted 3 lines
From: Mimi Zohar [mailto:[email protected]]
Sent: Thursday, June 3, 2021 5:18 PM
Differenatiate between an invalid EVM portable signature failure
Typo.
Quoted 3 lines
from other EVM HMAC/signature failures.
Signed-off-by Mimi Zohar <[email protected]>
Thanks, looks good.
Roberto
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Li Jian, Shi Yanli
Quoted 22 lines
--- security/integrity/ima/ima_appraise.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)security/integrity/ima/ima_appraise.c +2
-1@@ -422,7 +422,8 @@ int ima_appraise_measurement(enum ima_hooks func, goto out;case INTEGRITY_FAIL_IMMUTABLE :set_bit (IMA_DIGSIG , &iint->atomic_flags); - fallthrough; + cause ="invalid-fail-immutable" ; + goto out;case INTEGRITY_FAIL :/* Invalid HMAC/signature. */ cause ="invalid-HMAC" ;goto out;
--
2.27.0
Mimi Zohar
maintainerRFC PATCH 2/2 evm: output EVM digest calculation info needed for debugging
In reply to Mimi ZoharConvert and output the binary data used in calculating the EVM digest to a hexadecimal string.
--- security/integrity/evm/evm.h | 1 + security/integrity/evm/evm_crypto.c | 7 +++++++ security/integrity/evm/evm_main.c | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+)
security/integrity/evm/evm.h +1 -0
@@ -64,5 +64,6 @@ int evm_calc_hash(struct dentry *dentry, const char *req_xattr_name,int evm_init_hmac (struct inode *inode,const struct xattr *xattr,char *hmac_val);int evm_init_secfs (void ); +void evm_bin2hex_print (const char *prefix,const void *src,size_t count);#endif
security/integrity/evm/evm_crypto.c +7 -0
@@ -175,6 +175,8 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode, type != EVM_XATTR_PORTABLE_DIGSIG)crypto_shash_update (desc, (u8 *)&inode->i_sb->s_uuid,UUID_SIZE );crypto_shash_final (desc, digest); + +evm_bin2hex_print ("hmac_misc" , &hmac_misc,sizeof (struct h_misc )); }/*
@@ -230,6 +232,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry, req_xattr_value_len);if (is_ima) ima_present = true; + +evm_bin2hex_print (req_xattr_name, req_xattr_value, + req_xattr_value_len);continue ; } size = vfs_getxattr_alloc(&init_user_ns, dentry, xattr->name,
@@ -246,6 +251,8 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,crypto_shash_update (desc, (const u8 *)xattr_value, xattr_size);if (is_ima) ima_present = true; + +evm_bin2hex_print (xattr->name, xattr_value, xattr_size); }hmac_add_misc (desc, inode, type, data->digest);
security/integrity/evm/evm_main.c +19 -0
@@ -155,6 +155,23 @@ static int evm_find_protected_xattrs(struct dentry *dentry)return count; } +void evm_bin2hex_print (const char *prefix,const void *src,size_t count) +{ +#ifdef DEBUG +char *asciihex, *p; + + p = asciihex =kmalloc (count *2 +1 ,GFP_KERNEL ); +if (!asciihex) +return ; + + p =bin2hex (p, src, count); + *p =0 ; +printk ("%s: (%lu) %.*s\n" , prefix, count, (int ) count *2 , asciihex); + +kfree (asciihex); +#endif +} +/* * evm_verify_hmac - calculate and compare the HMAC with the EVM xattr *
@@ -272,6 +289,8 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,else evm_status =INTEGRITY_FAIL ; } + +evm_bin2hex_print ("evm digest" , digest.digest, digest.hdr.length); out:if (iint) iint->evm_status = evm_status;
Signature · 1 line
2.27.0
Re: [RFC PATCH 2/2] evm: output EVM digest calculation info needed for debugging
On Thu, 2021-06-03 at 11:18 -0400, Mimi Zohar wrote:
Hi Mimi,
Quoted 17 lines
Convert and output the binary data used in calculating the EVM digest to a hexadecimal string.
Signed-off-by Mimi Zohar <[email protected]>--- security/integrity/evm/evm.h | 1 + security/integrity/evm/evm_crypto.c | 7 +++++++ security/integrity/evm/evm_main.c | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+)security/integrity/evm/evm.h +0
-0
security/integrity/evm/evm.h int evm_calc_hash(struct dentry *dentry, const char · line 69
Quoted 6 lines
security/integrity/evm/evm.h +1
-0@@ -64,5 +64,6 @@ int evm_calc_hash(struct dentry *dentry, const char *req_xattr_name, int (struct inode *inode, const struct xattr *xattr, char *hmac_val);int evm_init_secfs (void ); +void evm_bin2hex_print (const char *prefix,const void *src,size_t count);
For evm_bin2hex_print() can we could do the following in evm.h?
#ifdef DEBUG
void evm_bin2hex_print(const char *prefix, const void *src, size_t count);
#else
void evm_bin2hex_print(const char *prefix, const void *src, size_t count) {}
#endif /* DEBUG */
Quoted 61 lines
void
evm_bin2hex_print(const char *prefix, const void *src, size_t count);#endif
security/integrity/evm/evm_crypto.c +2
-0@@ -175,6 +175,8 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode, type != EVM_XATTR_PORTABLE_DIGSIG)crypto_shash_update (desc, (u8 *)&inode->i_sb->s_uuid,UUID_SIZE );crypto_shash_final (desc, digest); + +evm_bin2hex_print ("hmac_misc" , &hmac_misc,sizeof (struct h_misc ));}
/*
security/integrity/evm/evm_crypto.c +3
-0@@ -230,6 +232,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry, req_xattr_value_len);if (is_ima) ima_present = true; + +evm_bin2hex_print (req_xattr_name, req_xattr_value, + req_xattr_value_len);continue ;security/integrity/evm/evm_crypto.c +0
-0} size = vfs_getxattr_alloc(&init_user_ns, dentry, xattr-Quoted 1 line
name,
security/integrity/evm/evm_crypto.c +2
-0@@ -246,6 +251,8 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,crypto_shash_update (desc, (const u8 *)xattr_value, xattr_size);if (is_ima) ima_present = true; + +evm_bin2hex_print (xattr->name, xattr_value, xattr_size);security/integrity/evm/evm_crypto.c +0
-0}hmac_add_misc (desc, inode, type, data->digest);security/integrity/evm/evm_main.c +3
-0@@ -155,6 +155,23 @@ static int evm_find_protected_xattrs(struct dentry *dentry)return count; } +void evm_bin2hex_print (const char *prefix,const void *src,size_t count) +{ +#ifdef DEBUG
security/integrity/evm/evm_main.c static int evm_find_protected_xattrs(struct · line 172
Quoted 10 lines
security/integrity/evm/evm_main.c +9
-0+char *asciihex, *p; + + p = asciihex =kmalloc (count *2 +1 ,GFP_KERNEL ); +if (!asciihex) +return ; + + p =bin2hex (p, src, count); + *p =0 ; +printk ("%s: (%lu) %.*s\n" , prefix, count, (int ) count *2 , asciihex);
Prefix the message with, say, "evm:".
thanks,
-lakshmi
Quoted 20 lines
security/integrity/evm/evm_main.c +5
-0+ +kfree (asciihex); +#endif +} +/*
*evm_verify_hmac- calculate and compare the HMAC with the EVM
xattr
*security/integrity/evm/evm_main.c +2
-0@@ -272,6 +289,8 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry, else evm_status =INTEGRITY_FAIL ; } + +evm_bin2hex_print ("evm digest" , digest.digest, digest.hdr.length); out:security/integrity/evm/evm_main.c +0
-0if (iint) iint->evm_status = evm_status;
Mimi Zohar
maintainerRe: [RFC PATCH 2/2] evm: output EVM digest calculation info needed for debugging
Hi Lakshmi,
Quoted 6 lines · nramas
Quoted 3 lines
+void
evm_bin2hex_print(const char *prefix, const void *src, size_t count);For
evm_bin2hex_print()can we could do the following inevm.h?
Quoted 7 lines
#ifdef DEBUG
voidevm_bin2hex_print(const char *prefix, const void *src, size_t count);
#else
voidevm_bin2hex_print(const char *prefix, const void *src, size_t count){}
#endif /* DEBUG */
Yes, if we decide that it needs to be based on DEBUG, this would be the proper way of doing it. However, since there's nothing really private here, it's just displaying the security xattrs and other file metadata,
should enabling/disabling the debugging be runtime configurable? Kind
of like how print_hex_dump() relies on loglevel. Or should it be more granular?
thanks,
Mimi
Re: [RFC PATCH 2/2] evm: output EVM digest calculation info needed for debugging
Quoted 17 lines · Mimi Zohar
Quoted 7 lines · nramas
Quoted 4 lines
+void evm_bin2hex_print(const char *prefix, const void *src,
size_t
count);For
evm_bin2hex_print()can we could do the following inevm.h?Quoted 7 lines
#ifdef DEBUG
voidevm_bin2hex_print(const char *prefix, const void *src, size_t count);
#else
voidevm_bin2hex_print(const char *prefix, const void *src, size_t count){}
#endif /* DEBUG */
Quoted 12 lines
Yes, if we decide that it needs to be based on DEBUG, this would be the
proper way of doing it. However, since there's nothing really private
here, it's just displaying the security xattrs and other file metadata,
should enabling/disabling the debugging be runtime
configurable? Kind
of like howprint_hex_dump()relies on loglevel. Or should it be more
granular?
I read "Documentation/admin-guide/dynamic-debug-howto.rst". I think dynamically enabling/disabling, like how print_hex_dump() does, would be better for evm_bin2hex_print() as well.
thanks,
-lakshmi