ima: Set correct casting types
authorRoberto Sassu <roberto.sassu@huawei.com>
Tue, 8 Jun 2021 12:31:21 +0000 (14:31 +0200)
committerMimi Zohar <zohar@linux.ibm.com>
Tue, 8 Jun 2021 20:29:10 +0000 (16:29 -0400)
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>
security/integrity/ima/ima_template.c
security/integrity/ima/ima_template_lib.c

index a85963853a91ac1536c6c9fc5fb58f06daeb2cc9..694560396be05719bce56b8c8506812c9d861ee3 100644 (file)
@@ -423,9 +423,9 @@ int ima_restore_measurement_list(loff_t size, void *buf)
                return 0;
 
        if (ima_canonical_fmt) {
-               khdr->version = le16_to_cpu(khdr->version);
-               khdr->count = le64_to_cpu(khdr->count);
-               khdr->buffer_size = le64_to_cpu(khdr->buffer_size);
+               khdr->version = le16_to_cpu((__force __le16)khdr->version);
+               khdr->count = le64_to_cpu((__force __le64)khdr->count);
+               khdr->buffer_size = le64_to_cpu((__force __le64)khdr->buffer_size);
        }
 
        if (khdr->version != 1) {
@@ -515,7 +515,7 @@ int ima_restore_measurement_list(loff_t size, void *buf)
                }
 
                entry->pcr = !ima_canonical_fmt ? *(u32 *)(hdr[HDR_PCR].data) :
-                            le32_to_cpu(*(u32 *)(hdr[HDR_PCR].data));
+                            le32_to_cpu(*(__le32 *)(hdr[HDR_PCR].data));
                ret = ima_restore_measurement_entry(entry);
                if (ret < 0)
                        break;
index 518fd50ea48a9f245658055676c1e8f3bfff200c..3f8d53a03612006b48a391a8ed3df004fda7f3d6 100644 (file)
@@ -98,21 +98,21 @@ static void ima_show_template_data_ascii(struct seq_file *m,
                case sizeof(u16):
                        if (ima_canonical_fmt)
                                seq_printf(m, "%u",
-                                          le16_to_cpu(*(u16 *)buf_ptr));
+                                          le16_to_cpu(*(__le16 *)buf_ptr));
                        else
                                seq_printf(m, "%u", *(u16 *)buf_ptr);
                        break;
                case sizeof(u32):
                        if (ima_canonical_fmt)
                                seq_printf(m, "%u",
-                                          le32_to_cpu(*(u32 *)buf_ptr));
+                                          le32_to_cpu(*(__le32 *)buf_ptr));
                        else
                                seq_printf(m, "%u", *(u32 *)buf_ptr);
                        break;
                case sizeof(u64):
                        if (ima_canonical_fmt)
                                seq_printf(m, "%llu",
-                                          le64_to_cpu(*(u64 *)buf_ptr));
+                                          le64_to_cpu(*(__le64 *)buf_ptr));
                        else
                                seq_printf(m, "%llu", *(u64 *)buf_ptr);
                        break;
@@ -226,9 +226,10 @@ int ima_parse_buf(void *bufstartp, void *bufendp, void **bufcurp,
                        if (bufp > (bufendp - sizeof(u32)))
                                break;
 
-                       fields[i].len = *(u32 *)bufp;
                        if (ima_canonical_fmt)
-                               fields[i].len = le32_to_cpu(fields[i].len);
+                               fields[i].len = le32_to_cpu(*(__le32 *)bufp);
+                       else
+                               fields[i].len = *(u32 *)bufp;
 
                        bufp += sizeof(u32);
                }