Skip to content

Commit 24c9ae2

Browse files
robertosassumimizohar
authored andcommitted
ima: Set correct casting types
The code expects that the values being parsed from a buffer when the ima_canonical_fmt global variable is true are in little endian. Thus, this patch sets the casting types accordingly. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
1 parent 22a558f commit 24c9ae2

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

security/integrity/ima/ima_template.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ int ima_restore_measurement_list(loff_t size, void *buf)
423423
return 0;
424424

425425
if (ima_canonical_fmt) {
426-
khdr->version = le16_to_cpu(khdr->version);
427-
khdr->count = le64_to_cpu(khdr->count);
428-
khdr->buffer_size = le64_to_cpu(khdr->buffer_size);
426+
khdr->version = le16_to_cpu((__force __le16)khdr->version);
427+
khdr->count = le64_to_cpu((__force __le64)khdr->count);
428+
khdr->buffer_size = le64_to_cpu((__force __le64)khdr->buffer_size);
429429
}
430430

431431
if (khdr->version != 1) {
@@ -515,7 +515,7 @@ int ima_restore_measurement_list(loff_t size, void *buf)
515515
}
516516

517517
entry->pcr = !ima_canonical_fmt ? *(u32 *)(hdr[HDR_PCR].data) :
518-
le32_to_cpu(*(u32 *)(hdr[HDR_PCR].data));
518+
le32_to_cpu(*(__le32 *)(hdr[HDR_PCR].data));
519519
ret = ima_restore_measurement_entry(entry);
520520
if (ret < 0)
521521
break;

security/integrity/ima/ima_template_lib.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,21 @@ static void ima_show_template_data_ascii(struct seq_file *m,
9898
case sizeof(u16):
9999
if (ima_canonical_fmt)
100100
seq_printf(m, "%u",
101-
le16_to_cpu(*(u16 *)buf_ptr));
101+
le16_to_cpu(*(__le16 *)buf_ptr));
102102
else
103103
seq_printf(m, "%u", *(u16 *)buf_ptr);
104104
break;
105105
case sizeof(u32):
106106
if (ima_canonical_fmt)
107107
seq_printf(m, "%u",
108-
le32_to_cpu(*(u32 *)buf_ptr));
108+
le32_to_cpu(*(__le32 *)buf_ptr));
109109
else
110110
seq_printf(m, "%u", *(u32 *)buf_ptr);
111111
break;
112112
case sizeof(u64):
113113
if (ima_canonical_fmt)
114114
seq_printf(m, "%llu",
115-
le64_to_cpu(*(u64 *)buf_ptr));
115+
le64_to_cpu(*(__le64 *)buf_ptr));
116116
else
117117
seq_printf(m, "%llu", *(u64 *)buf_ptr);
118118
break;
@@ -226,9 +226,10 @@ int ima_parse_buf(void *bufstartp, void *bufendp, void **bufcurp,
226226
if (bufp > (bufendp - sizeof(u32)))
227227
break;
228228

229-
fields[i].len = *(u32 *)bufp;
230229
if (ima_canonical_fmt)
231-
fields[i].len = le32_to_cpu(fields[i].len);
230+
fields[i].len = le32_to_cpu(*(__le32 *)bufp);
231+
else
232+
fields[i].len = *(u32 *)bufp;
232233

233234
bufp += sizeof(u32);
234235
}

0 commit comments

Comments
 (0)