Skip to content

Commit 8c54135

Browse files
committed
ima: define ima_max_digest_data struct without a flexible array variable
To support larger hash digests in the 'iint' cache, instead of defining the 'digest' field as the maximum digest size, the 'digest' field was defined as a flexible array variable. The "ima_digest_data" struct was wrapped inside a local structure with the maximum digest size. But before adding the record to the iint cache, memory for the exact digest size was dynamically allocated. The original reason for defining the 'digest' field as a flexible array variable is still valid for the 'iint' cache use case. Instead of wrapping the 'ima_digest_data' struct in a local structure define 'ima_max_digest_data' struct. Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent aae6ccb commit 8c54135

5 files changed

Lines changed: 17 additions & 18 deletions

File tree

security/integrity/ima/ima_api.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,11 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
217217
const char *audit_cause = "failed";
218218
struct inode *inode = file_inode(file);
219219
const char *filename = file->f_path.dentry->d_name.name;
220+
struct ima_max_digest_data hash;
220221
int result = 0;
221222
int length;
222223
void *tmpbuf;
223224
u64 i_version;
224-
struct {
225-
struct ima_digest_data hdr;
226-
char digest[IMA_MAX_DIGEST_SIZE];
227-
} hash;
228225

229226
/*
230227
* Always collect the modsig, because IMA might have already collected
@@ -239,8 +236,9 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
239236

240237
/*
241238
* Detecting file change is based on i_version. On filesystems
242-
* which do not support i_version, support is limited to an initial
243-
* measurement/appraisal/audit.
239+
* which do not support i_version, support was originally limited
240+
* to an initial measurement/appraisal/audit, but was modified to
241+
* assume the file changed.
244242
*/
245243
i_version = inode_query_iversion(inode);
246244
hash.hdr.algo = algo;

security/integrity/ima/ima_init.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,9 @@ static int __init ima_add_boot_aggregate(void)
4747
struct integrity_iint_cache tmp_iint, *iint = &tmp_iint;
4848
struct ima_event_data event_data = { .iint = iint,
4949
.filename = boot_aggregate_name };
50+
struct ima_max_digest_data hash;
5051
int result = -ENOMEM;
5152
int violation = 0;
52-
struct {
53-
struct ima_digest_data hdr;
54-
char digest[TPM_MAX_DIGEST_SIZE];
55-
} hash;
5653

5754
memset(iint, 0, sizeof(*iint));
5855
memset(&hash, 0, sizeof(hash));

security/integrity/ima/ima_main.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,10 +874,7 @@ int process_buffer_measurement(struct user_namespace *mnt_userns,
874874
.buf = buf,
875875
.buf_len = size};
876876
struct ima_template_desc *template;
877-
struct {
878-
struct ima_digest_data hdr;
879-
char digest[IMA_MAX_DIGEST_SIZE];
880-
} hash = {};
877+
struct ima_max_digest_data hash;
881878
char digest_hash[IMA_MAX_DIGEST_SIZE];
882879
int digest_hash_len = hash_digest_size[ima_hash_algo];
883880
int violation = 0;

security/integrity/ima/ima_template_lib.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,7 @@ static int ima_eventdigest_init_common(const u8 *digest, u32 digestsize,
307307
int ima_eventdigest_init(struct ima_event_data *event_data,
308308
struct ima_field_data *field_data)
309309
{
310-
struct {
311-
struct ima_digest_data hdr;
312-
char digest[IMA_MAX_DIGEST_SIZE];
313-
} hash;
310+
struct ima_max_digest_data hash;
314311
u8 *cur_digest = NULL;
315312
u32 cur_digestsize = 0;
316313
struct inode *inode;

security/integrity/integrity.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/types.h>
1616
#include <linux/integrity.h>
1717
#include <crypto/sha1.h>
18+
#include <crypto/hash.h>
1819
#include <linux/key.h>
1920
#include <linux/audit.h>
2021

@@ -110,6 +111,15 @@ struct ima_digest_data {
110111
u8 digest[];
111112
} __packed;
112113

114+
/*
115+
* Instead of wrapping the ima_digest_data struct inside a local structure
116+
* with the maximum hash size, define ima_max_digest_data struct.
117+
*/
118+
struct ima_max_digest_data {
119+
struct ima_digest_data hdr;
120+
u8 digest[HASH_MAX_DIGESTSIZE];
121+
} __packed;
122+
113123
/*
114124
* signature format v2 - for using with asymmetric keys
115125
*/

0 commit comments

Comments
 (0)