Skip to content
Snippets Groups Projects
Commit cde1391a authored by Roberto Sassu's avatar Roberto Sassu Committed by Mimi Zohar
Browse files

ima: Add ima_show_template_uint() template library function


This patch introduces the new function ima_show_template_uint(). This can
be used for showing integers of different sizes in ASCII format. The
function ima_show_template_data_ascii() automatically determines how to
print a stored integer by checking the integer size.

If integers have been written in canonical format,
ima_show_template_data_ascii() calls the appropriate leXX_to_cpu() function
to correctly display the value.

Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
parent 5a25d8ce
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,8 @@ enum data_formats { ...@@ -24,7 +24,8 @@ enum data_formats {
DATA_FMT_DIGEST = 0, DATA_FMT_DIGEST = 0,
DATA_FMT_DIGEST_WITH_ALGO, DATA_FMT_DIGEST_WITH_ALGO,
DATA_FMT_STRING, DATA_FMT_STRING,
DATA_FMT_HEX DATA_FMT_HEX,
DATA_FMT_UINT
}; };
static int ima_write_template_field_data(const void *data, const u32 datalen, static int ima_write_template_field_data(const void *data, const u32 datalen,
...@@ -88,6 +89,35 @@ static void ima_show_template_data_ascii(struct seq_file *m, ...@@ -88,6 +89,35 @@ static void ima_show_template_data_ascii(struct seq_file *m,
case DATA_FMT_STRING: case DATA_FMT_STRING:
seq_printf(m, "%s", buf_ptr); seq_printf(m, "%s", buf_ptr);
break; break;
case DATA_FMT_UINT:
switch (field_data->len) {
case sizeof(u8):
seq_printf(m, "%u", *(u8 *)buf_ptr);
break;
case sizeof(u16):
if (ima_canonical_fmt)
seq_printf(m, "%u",
le16_to_cpu(*(u16 *)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));
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));
else
seq_printf(m, "%llu", *(u64 *)buf_ptr);
break;
default:
break;
}
default: default:
break; break;
} }
...@@ -163,6 +193,12 @@ void ima_show_template_buf(struct seq_file *m, enum ima_show_type show, ...@@ -163,6 +193,12 @@ void ima_show_template_buf(struct seq_file *m, enum ima_show_type show,
ima_show_template_field_data(m, show, DATA_FMT_HEX, field_data); ima_show_template_field_data(m, show, DATA_FMT_HEX, field_data);
} }
void ima_show_template_uint(struct seq_file *m, enum ima_show_type show,
struct ima_field_data *field_data)
{
ima_show_template_field_data(m, show, DATA_FMT_UINT, field_data);
}
/** /**
* ima_parse_buf() - Parses lengths and data from an input buffer * ima_parse_buf() - Parses lengths and data from an input buffer
* @bufstartp: Buffer start address. * @bufstartp: Buffer start address.
......
...@@ -27,6 +27,8 @@ void ima_show_template_sig(struct seq_file *m, enum ima_show_type show, ...@@ -27,6 +27,8 @@ void ima_show_template_sig(struct seq_file *m, enum ima_show_type show,
struct ima_field_data *field_data); struct ima_field_data *field_data);
void ima_show_template_buf(struct seq_file *m, enum ima_show_type show, void ima_show_template_buf(struct seq_file *m, enum ima_show_type show,
struct ima_field_data *field_data); struct ima_field_data *field_data);
void ima_show_template_uint(struct seq_file *m, enum ima_show_type show,
struct ima_field_data *field_data);
int ima_parse_buf(void *bufstartp, void *bufendp, void **bufcurp, int ima_parse_buf(void *bufstartp, void *bufendp, void **bufcurp,
int maxfields, struct ima_field_data *fields, int *curfields, int maxfields, struct ima_field_data *fields, int *curfields,
unsigned long *len_mask, int enforce_mask, char *bufname); unsigned long *len_mask, int enforce_mask, char *bufname);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment