forked from Qortal/Brooklyn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1012 B
44 lines
1012 B
// SPDX-License-Identifier: GPL-2.0+ |
|
/* |
|
* Copyright (C) 2021 Microsoft Corporation |
|
* |
|
* Author: Lakshmi Ramasubramanian ([email protected]) |
|
* |
|
* Measure critical data structures maintainted by SELinux |
|
* using IMA subsystem. |
|
*/ |
|
#include <linux/vmalloc.h> |
|
#include <linux/ima.h> |
|
#include "security.h" |
|
#include "ima.h" |
|
|
|
/* |
|
* selinux_ima_measure_state - Measure hash of the SELinux policy |
|
* |
|
* @state: selinux state struct |
|
* |
|
* NOTE: This function must be called with policy_mutex held. |
|
*/ |
|
void selinux_ima_measure_state(struct selinux_state *state) |
|
{ |
|
void *policy = NULL; |
|
size_t policy_len; |
|
int rc = 0; |
|
|
|
/* |
|
* Measure SELinux policy only after initialization is completed. |
|
*/ |
|
if (!selinux_initialized(state)) |
|
return; |
|
|
|
rc = security_read_state_kernel(state, &policy, &policy_len); |
|
if (rc) { |
|
pr_err("SELinux: %s: failed to read policy %d.\n", __func__, rc); |
|
return; |
|
} |
|
|
|
ima_measure_critical_data("selinux", "selinux-policy-hash", |
|
policy, policy_len, true); |
|
|
|
vfree(policy); |
|
}
|
|
|