Skip to content

Commit 87ac3d0

Browse files
committed
evm: output EVM digest calculation info
Output the data used in calculating the EVM digest and the resulting digest as ascii hexadecimal strings. Suggested-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com> (CONFIG_DYNAMIC_DEBUG) Reviewed-by: Lakshmi Ramasubramanian <nramas@linux.microsoft.com> Reported-by: kernel test robot <lkp@intel.com> (Use %zu for size_t) Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 52c2083 commit 87ac3d0

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

security/integrity/evm/evm_crypto.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Using root's kernel master key (kmk), calculate the HMAC
1111
*/
1212

13+
#define pr_fmt(fmt) "EVM: "fmt
14+
1315
#include <linux/export.h>
1416
#include <linux/crypto.h>
1517
#include <linux/xattr.h>
@@ -175,6 +177,30 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
175177
type != EVM_XATTR_PORTABLE_DIGSIG)
176178
crypto_shash_update(desc, (u8 *)&inode->i_sb->s_uuid, UUID_SIZE);
177179
crypto_shash_final(desc, digest);
180+
181+
pr_debug("hmac_misc: (%zu) [%*phN]\n", sizeof(struct h_misc),
182+
(int)sizeof(struct h_misc), &hmac_misc);
183+
}
184+
185+
/*
186+
* Dump large security xattr values as a continuous ascii hexademical string.
187+
* (pr_debug is limited to 64 bytes.)
188+
*/
189+
static void dump_security_xattr(const char *prefix, const void *src,
190+
size_t count)
191+
{
192+
#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
193+
char *asciihex, *p;
194+
195+
p = asciihex = kmalloc(count * 2 + 1, GFP_KERNEL);
196+
if (!asciihex)
197+
return;
198+
199+
p = bin2hex(p, src, count);
200+
*p = 0;
201+
pr_debug("%s: (%zu) %.*s\n", prefix, count, (int)count * 2, asciihex);
202+
kfree(asciihex);
203+
#endif
178204
}
179205

180206
/*
@@ -230,6 +256,16 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
230256
req_xattr_value_len);
231257
if (is_ima)
232258
ima_present = true;
259+
260+
if (req_xattr_value_len < 64)
261+
pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
262+
req_xattr_value_len,
263+
(int)req_xattr_value_len,
264+
req_xattr_value);
265+
else
266+
dump_security_xattr(req_xattr_name,
267+
req_xattr_value,
268+
req_xattr_value_len);
233269
continue;
234270
}
235271
size = vfs_getxattr_alloc(&init_user_ns, dentry, xattr->name,
@@ -246,6 +282,13 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
246282
crypto_shash_update(desc, (const u8 *)xattr_value, xattr_size);
247283
if (is_ima)
248284
ima_present = true;
285+
286+
if (xattr_size < 64)
287+
pr_debug("%s: (%zu) [%*phN]", xattr->name, xattr_size,
288+
(int)xattr_size, xattr_value);
289+
else
290+
dump_security_xattr(xattr->name, xattr_value,
291+
xattr_size);
249292
}
250293
hmac_add_misc(desc, inode, type, data->digest);
251294

security/integrity/evm/evm_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* evm_inode_removexattr, and evm_verifyxattr
1212
*/
1313

14+
#define pr_fmt(fmt) "EVM: "fmt
15+
1416
#include <linux/init.h>
1517
#include <linux/crypto.h>
1618
#include <linux/audit.h>
@@ -272,6 +274,8 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,
272274
else
273275
evm_status = INTEGRITY_FAIL;
274276
}
277+
pr_debug("digest: (%d) [%*phN]\n", digest.hdr.length, digest.hdr.length,
278+
digest.digest);
275279
out:
276280
if (iint)
277281
iint->evm_status = evm_status;

0 commit comments

Comments
 (0)