ima/evm: Fix type mismatch
authorRoberto Sassu <roberto.sassu@huawei.com>
Tue, 8 Jun 2021 12:31:22 +0000 (14:31 +0200)
committerMimi Zohar <zohar@linux.ibm.com>
Tue, 8 Jun 2021 20:29:10 +0000 (16:29 -0400)
commit6b26285f44c9306747c609cb304f787f1933594c
tree50ca9c69d4317105c9d384292c32fa56b9f9fd62
parent24c9ae23bdfa0642228e747849dd052fd4295c6c
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>
security/integrity/evm/evm_main.c
security/integrity/ima/ima_crypto.c
security/integrity/ima/ima_fs.c
security/integrity/ima/ima_template_lib.c