Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ima: Fix the error code for restoring the PCR value

In ima_restore_measurement_list(), hdr[HDR_PCR].data is pointing to a
buffer of type u8, which contains the dumped 32-bit pcr value.
Currently, only the least significant byte is used to restore the pcr
value. We should convert hdr[HDR_PCR].data to a pointer of type u32
before fetching the value to restore the correct pcr value.

Fixes: 47fdee60b47f ("ima: use ima_parse_buf() to parse measurements headers")
Signed-off-by: Li Huafei <lihuafei1@huawei.com>
Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>

authored by

Li Huafei and committed by
Mimi Zohar
7990ccaf f873b28f

+2 -2
+2 -2
security/integrity/ima/ima_template.c
··· 494 494 } 495 495 } 496 496 497 - entry->pcr = !ima_canonical_fmt ? *(hdr[HDR_PCR].data) : 498 - le32_to_cpu(*(hdr[HDR_PCR].data)); 497 + entry->pcr = !ima_canonical_fmt ? *(u32 *)(hdr[HDR_PCR].data) : 498 + le32_to_cpu(*(u32 *)(hdr[HDR_PCR].data)); 499 499 ret = ima_restore_measurement_entry(entry); 500 500 if (ret < 0) 501 501 break;