0

I am writing a simple LSM code in kernel version 3.14.17.

Code Snippet:

#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");

Output:

register_security undefined

I have no idea why it is showing register_security not defined ? Any suggestions how can I use register_security. Note: I don't want to edit existing kernel headers like security.h

Kr Sourav
  • 1
  • 1

1 Answers1

2

register_security() is not exported from kernel (i.e. there is no EXPORT_SYMBOL(register_security)). That means, register_security() can only be referenced inside the kernel; you can't access it from module.

Furthermore, register_security() is defined as __init. That means, that it's pretty OK for kernel to remove this symbol as far as initialization process is done.

Alexey Shmalko
  • 3,678
  • 1
  • 19
  • 35
  • It seems like LSMs are baked into the kernel and you can't hot swap it. In other words, you can't just write a module for it. – tangrs Sep 01 '14 at 00:14