summaryrefslogtreecommitdiff
path: root/security/integrity/ima/ima_template.c
diff options
context:
space:
mode:
authorMimi Zohar <zohar@linux.vnet.ibm.com>2016-12-20 03:22:57 +0300
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-20 20:48:45 +0300
commitd68a6fe9fccfd00589c61df672b449d66ba3183f (patch)
tree0a651c25b42fc38870cbe80ac434a2c107a5690e /security/integrity/ima/ima_template.c
parentc7d09367702e2f4faebc6176d24df72dd5066c3e (diff)
downloadlinux-d68a6fe9fccfd00589c61df672b449d66ba3183f.tar.xz
ima: define a canonical binary_runtime_measurements list format
The IMA binary_runtime_measurements list is currently in platform native format. To allow restoring a measurement list carried across kexec with a different endianness than the targeted kernel, this patch defines little-endian as the canonical format. For big endian systems wanting to save/restore the measurement list from a system with a different endianness, a new boot command line parameter named "ima_canonical_fmt" is defined. Considerations: use of the "ima_canonical_fmt" boot command line option will break existing userspace applications on big endian systems expecting the binary_runtime_measurements list to be in platform native format. Link: http://lkml.kernel.org/r/1480554346-29071-10-git-send-email-zohar@linux.vnet.ibm.com Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com> Acked-by: Dmitry Kasatkin <dmitry.kasatkin@gmail.com> Cc: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Andreas Steffen <andreas.steffen@strongswan.org> Cc: Josh Sklar <sklar@linux.vnet.ibm.com> Cc: Dave Young <dyoung@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Baoquan He <bhe@redhat.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Stewart Smith <stewart@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security/integrity/ima/ima_template.c')
-rw-r--r--security/integrity/ima/ima_template.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
index 16bbb5a80fc8..cebb37c63629 100644
--- a/security/integrity/ima/ima_template.c
+++ b/security/integrity/ima/ima_template.c
@@ -302,6 +302,9 @@ static int ima_restore_template_data(struct ima_template_desc *template_desc,
}
offset += sizeof(*field_data);
+ if (ima_canonical_fmt)
+ field_data->len = le32_to_cpu(field_data->len);
+
if (offset > (template_data_size - field_data->len)) {
pr_err("Restoring the template field data failed\n");
ret = -EINVAL;
@@ -352,7 +355,7 @@ int ima_restore_measurement_list(loff_t size, void *buf)
struct binary_data_v1 *data_v1;
void *bufp = buf + sizeof(*khdr);
- void *bufendp = buf + khdr->buffer_size;
+ void *bufendp;
struct ima_template_entry *entry;
struct ima_template_desc *template_desc;
unsigned long count = 0;
@@ -361,6 +364,12 @@ int ima_restore_measurement_list(loff_t size, void *buf)
if (!buf || size < sizeof(*khdr))
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);
+ }
+
if (khdr->version != 1) {
pr_err("attempting to restore a incompatible measurement list");
return -EINVAL;
@@ -376,6 +385,7 @@ int ima_restore_measurement_list(loff_t size, void *buf)
* v1 format: pcr, digest, template-name-len, template-name,
* template-data-size, template-data
*/
+ bufendp = buf + khdr->buffer_size;
while ((bufp < bufendp) && (count++ < khdr->count)) {
hdr_v1 = bufp;
if (bufp > (bufendp - sizeof(*hdr_v1))) {
@@ -385,6 +395,10 @@ int ima_restore_measurement_list(loff_t size, void *buf)
}
bufp += sizeof(*hdr_v1);
+ if (ima_canonical_fmt)
+ hdr_v1->template_name_len =
+ le32_to_cpu(hdr_v1->template_name_len);
+
if ((hdr_v1->template_name_len >= MAX_TEMPLATE_NAME_LEN) ||
(bufp > (bufendp - hdr_v1->template_name_len))) {
pr_err("attempting to restore a template name \
@@ -434,6 +448,10 @@ int ima_restore_measurement_list(loff_t size, void *buf)
}
bufp += (u_int8_t) sizeof(data_v1->template_data_size);
+ if (ima_canonical_fmt)
+ data_v1->template_data_size =
+ le32_to_cpu(data_v1->template_data_size);
+
if (bufp > (bufendp - data_v1->template_data_size)) {
pr_err("restoring the template data failed\n");
ret = -EINVAL;
@@ -449,7 +467,8 @@ int ima_restore_measurement_list(loff_t size, void *buf)
break;
memcpy(entry->digest, hdr_v1->digest, TPM_DIGEST_SIZE);
- entry->pcr = hdr_v1->pcr;
+ entry->pcr =
+ !ima_canonical_fmt ? hdr_v1->pcr : le32_to_cpu(hdr_v1->pcr);
ret = ima_restore_measurement_entry(entry);
if (ret < 0)
break;