mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
ima/evm: Fix type mismatch
The endianness of a variable written to the measurement list cannot be determined at compile time, as it depends on the value of the ima_canonical_fmt global variable (set through a kernel option with the same name if the machine is big endian). If ima_canonical_fmt is false, the endianness of a variable is the same as the machine; if ima_canonical_fmt is true, the endianness is little endian. The warning arises due to this type of instruction: var = cpu_to_leXX(var) which tries to assign a value in little endian to a variable with native endianness (little or big endian). Given that the variables set with this instruction are not used in any operation but just written to a buffer, it is safe to force the type of the value being set to be the same of the type of the variable with: var = (__force <var type>)cpu_to_leXX(var) 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>
This commit is contained in:
committed by
Mimi Zohar
parent
24c9ae23bd
commit
6b26285f44
@@ -147,7 +147,7 @@ int ima_measurements_show(struct seq_file *m, void *v)
|
||||
* PCR used defaults to the same (config option) in
|
||||
* little-endian format, unless set in policy
|
||||
*/
|
||||
pcr = !ima_canonical_fmt ? e->pcr : cpu_to_le32(e->pcr);
|
||||
pcr = !ima_canonical_fmt ? e->pcr : (__force u32)cpu_to_le32(e->pcr);
|
||||
ima_putc(m, &pcr, sizeof(e->pcr));
|
||||
|
||||
/* 2nd: template digest */
|
||||
@@ -155,7 +155,7 @@ int ima_measurements_show(struct seq_file *m, void *v)
|
||||
|
||||
/* 3rd: template name size */
|
||||
namelen = !ima_canonical_fmt ? strlen(template_name) :
|
||||
cpu_to_le32(strlen(template_name));
|
||||
(__force u32)cpu_to_le32(strlen(template_name));
|
||||
ima_putc(m, &namelen, sizeof(namelen));
|
||||
|
||||
/* 4th: template name */
|
||||
@@ -167,7 +167,7 @@ int ima_measurements_show(struct seq_file *m, void *v)
|
||||
|
||||
if (!is_ima_template) {
|
||||
template_data_len = !ima_canonical_fmt ? e->template_data_len :
|
||||
cpu_to_le32(e->template_data_len);
|
||||
(__force u32)cpu_to_le32(e->template_data_len);
|
||||
ima_putc(m, &template_data_len, sizeof(e->template_data_len));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user