// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) 2008 IBM Corporation3*4* Authors:5* Mimi Zohar <[email protected]>6*7* File: integrity_iint.c8* - initialize the integrity directory in securityfs9* - load IMA and EVM keys10*/11#include <linux/security.h>12#include "integrity.h"1314struct dentry *integrity_dir;1516/*17* integrity_kernel_read - read data from the file18*19* This is a function for reading file content instead of kernel_read().20* It does not perform locking checks to ensure it cannot be blocked.21* It does not perform security checks because it is irrelevant for IMA.22*23*/24int integrity_kernel_read(struct file *file, loff_t offset,25void *addr, unsigned long count)26{27return __kernel_read(file, addr, count, &offset);28}2930/*31* integrity_load_keys - load integrity keys hook32*33* Hooks is called from init/main.c:kernel_init_freeable()34* when rootfs is ready35*/36void __init integrity_load_keys(void)37{38ima_load_x509();3940if (!IS_ENABLED(CONFIG_IMA_LOAD_X509))41evm_load_x509();42}4344int __init integrity_fs_init(void)45{46if (integrity_dir)47return 0;4849integrity_dir = securityfs_create_dir("integrity", NULL);50if (IS_ERR(integrity_dir)) {51int ret = PTR_ERR(integrity_dir);5253if (ret != -ENODEV)54pr_err("Unable to create integrity sysfs dir: %d\n",55ret);56integrity_dir = NULL;57return ret;58}5960return 0;61}6263void __init integrity_fs_fini(void)64{65if (!integrity_dir || !simple_empty(integrity_dir))66return;6768securityfs_remove(integrity_dir);69integrity_dir = NULL;70}717273