Skip to content

Commit b4efd62

Browse files
committed
Merge tag 'ipe-pr-20250728' of git://git.kernel.org/pub/scm/linux/kernel/git/wufan/ipe
Pull ipe update from Fan Wu: "A single commit from Eric Biggers to simplify the IPE (Integrity Policy Enforcement) policy audit with the SHA-256 library API" * tag 'ipe-pr-20250728' of git://git.kernel.org/pub/scm/linux/kernel/git/wufan/ipe: ipe: use SHA-256 library API instead of crypto_shash API
2 parents b1cce98 + b90bb6d commit b4efd62

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

security/ipe/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
menuconfig SECURITY_IPE
77
bool "Integrity Policy Enforcement (IPE)"
88
depends on SECURITY && SECURITYFS && AUDIT && AUDITSYSCALL
9+
select CRYPTO_LIB_SHA256
910
select PKCS7_MESSAGE_PARSER
1011
select SYSTEM_DATA_VERIFICATION
1112
select IPE_PROP_DM_VERITY if DM_VERITY

security/ipe/audit.c

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <linux/slab.h>
77
#include <linux/audit.h>
88
#include <linux/types.h>
9-
#include <crypto/hash.h>
9+
#include <crypto/sha2.h>
1010

1111
#include "ipe.h"
1212
#include "eval.h"
@@ -17,7 +17,7 @@
1717

1818
#define ACTSTR(x) ((x) == IPE_ACTION_ALLOW ? "ALLOW" : "DENY")
1919

20-
#define IPE_AUDIT_HASH_ALG "sha256"
20+
#define IPE_AUDIT_HASH_ALG "sha256" /* keep in sync with audit_policy() */
2121

2222
#define AUDIT_POLICY_LOAD_FMT "policy_name=\"%s\" policy_version=%hu.%hu.%hu "\
2323
"policy_digest=" IPE_AUDIT_HASH_ALG ":"
@@ -182,37 +182,14 @@ static void audit_policy(struct audit_buffer *ab,
182182
const char *audit_format,
183183
const struct ipe_policy *const p)
184184
{
185-
SHASH_DESC_ON_STACK(desc, tfm);
186-
struct crypto_shash *tfm;
187-
u8 *digest = NULL;
185+
u8 digest[SHA256_DIGEST_SIZE];
188186

189-
tfm = crypto_alloc_shash(IPE_AUDIT_HASH_ALG, 0, 0);
190-
if (IS_ERR(tfm))
191-
return;
192-
193-
desc->tfm = tfm;
194-
195-
digest = kzalloc(crypto_shash_digestsize(tfm), GFP_KERNEL);
196-
if (!digest)
197-
goto out;
198-
199-
if (crypto_shash_init(desc))
200-
goto out;
201-
202-
if (crypto_shash_update(desc, p->pkcs7, p->pkcs7len))
203-
goto out;
204-
205-
if (crypto_shash_final(desc, digest))
206-
goto out;
187+
sha256(p->pkcs7, p->pkcs7len, digest);
207188

208189
audit_log_format(ab, audit_format, p->parsed->name,
209190
p->parsed->version.major, p->parsed->version.minor,
210191
p->parsed->version.rev);
211-
audit_log_n_hex(ab, digest, crypto_shash_digestsize(tfm));
212-
213-
out:
214-
kfree(digest);
215-
crypto_free_shash(tfm);
192+
audit_log_n_hex(ab, digest, sizeof(digest));
216193
}
217194

218195
/**

0 commit comments

Comments
 (0)