我在内核版本3.14.17中编写了一个简单的LSM代码。
代码段:
#include <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
#include <linux/security.h>
#include <linux/tracehook.h>
static int blabbermouth_inode_alloc_security(struct inode *inode)
{
return 0;
}
static void blabbermouth_inode_free_security(struct inode *inode)
{
}
static struct security_operations blabbermouth_ops = {
.inode_alloc_security = blabbermouth_inode_alloc_security,
.inode_free_security = blabbermouth_inode_free_security,
};
static int __init hello_init(void)
{
if (register_security(&blabbermouth_ops))
panic("blabbermouth: Unable to register blabbermouth with kernel.\n");
else
printk("blabbermouth: registered with the kernel\n");
return 0;
}
static void __exit hello_cleanup(void)
{
printk("Exit \n");
return;
}
module_init(hello_init);
module_exit(hello_cleanup);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Lakshmanan");
MODULE_DESCRIPTION("A Simple Hello World module");
输出:
register_security undefined
我不知道为什么显示register_security没有定义? 任何建议如何使用register_security。 注意:我不想编辑现有的内核头文件,如security.h
答案 0 :(得分:2)
register_security()
未从内核导出(即没有EXPORT_SYMBOL(register_security)
)。这意味着,register_security()
只能在内核中引用;你无法从模块访问它。
此外,register_security()
定义为__init
。这意味着,只要初始化过程完成,内核就可以删除此符号。