security/integrity/ima/ima_template_lib.c

Source file repositories/reference/linux-study-clean/security/integrity/ima/ima_template_lib.c

File Facts

System
Linux kernel
Corpus path
security/integrity/ima/ima_template_lib.c
Extension
.c
Size
20174 bytes
Lines
765
Domain
Core OS
Bucket
Security And Isolation
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

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(*(__le16 *)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(*(__le32 *)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(*(__le64 *)buf_ptr));
			else
				seq_printf(m, "%llu", *(u64 *)buf_ptr);
			break;
		default:
			break;
		}
		break;
	default:
		break;
	}
}

static void ima_show_template_data_binary(struct seq_file *m,
					  enum ima_show_type show,
					  enum data_formats datafmt,
					  struct ima_field_data *field_data)
{
	u32 len = (show == IMA_SHOW_BINARY_OLD_STRING_FMT) ?
	    strlen(field_data->data) : field_data->len;

	if (show != IMA_SHOW_BINARY_NO_FIELD_LEN) {
		u32 field_len = !ima_canonical_fmt ?
				len : (__force u32)cpu_to_le32(len);

		ima_putc(m, &field_len, sizeof(field_len));
	}

	if (!len)
		return;

	ima_putc(m, field_data->data, len);
}

static void ima_show_template_field_data(struct seq_file *m,
					 enum ima_show_type show,
					 enum data_formats datafmt,
					 struct ima_field_data *field_data)
{
	switch (show) {
	case IMA_SHOW_ASCII:
		ima_show_template_data_ascii(m, show, datafmt, field_data);
		break;
	case IMA_SHOW_BINARY:
	case IMA_SHOW_BINARY_NO_FIELD_LEN:
	case IMA_SHOW_BINARY_OLD_STRING_FMT:
		ima_show_template_data_binary(m, show, datafmt, field_data);
		break;
	default:
		break;
	}
}

void ima_show_template_digest(struct seq_file *m, enum ima_show_type show,
			      struct ima_field_data *field_data)
{
	ima_show_template_field_data(m, show, DATA_FMT_DIGEST, field_data);
}

void ima_show_template_digest_ng(struct seq_file *m, enum ima_show_type show,
				 struct ima_field_data *field_data)
{
	ima_show_template_field_data(m, show, DATA_FMT_DIGEST_WITH_ALGO,
				     field_data);
}

void ima_show_template_digest_ngv2(struct seq_file *m, enum ima_show_type show,
				   struct ima_field_data *field_data)
{

Annotation

Implementation Notes