| /* |
| * Copyright 2019 The Chromium OS Authors. All rights reserved. |
| * Distributed under the terms of the GNU General Public License v2. |
| * |
| * Module to trigger loadpin. The kernel module calls |
| * kernel_read_file_from_path to load a dummy file from rootfs into kernel, |
| * which will trigger loadpin. |
| */ |
| |
| #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| |
| #include <linux/err.h> |
| #include <linux/fs.h> |
| #include <linux/init.h> |
| #include <linux/kernel.h> |
| #include <linux/module.h> |
| #include <linux/types.h> |
| #include <linux/version.h> |
| #include <linux/vmalloc.h> |
| |
| #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) |
| #include <linux/kernel_read_file.h> |
| #endif |
| |
| MODULE_LICENSE("GPL"); |
| MODULE_AUTHOR("Ke Wu"); |
| MODULE_DESCRIPTION("A Linux module to trigger loadpin."); |
| MODULE_VERSION("1"); |
| |
| #define MAX_DATA_SIZE 1024 |
| |
| static const char *root_fs_dummy_path = "/etc/loadpin_trigger"; |
| |
| static int __init loadpin_trigger_init(void) { |
| void *data; |
| #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) |
| size_t size; |
| #else |
| loff_t size; |
| #endif |
| int rc; |
| |
| data = NULL; |
| #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0)) |
| rc = kernel_read_file_from_path(root_fs_dummy_path, 0, &data, |
| MAX_DATA_SIZE, &size, |
| READING_UNKNOWN); |
| #else |
| rc = kernel_read_file_from_path(root_fs_dummy_path, &data, &size, |
| 0, READING_UNKNOWN); |
| #endif |
| if (rc < 0) { |
| pr_err("Unable to read file: %s (%d)", root_fs_dummy_path, rc); |
| return -EIO; |
| } |
| vfree(data); |
| return 0; |
| } |
| |
| module_init(loadpin_trigger_init); |