Hi All,
I way trying to make use of struct security_operations and add a hook on inode_create, but my module is not getting loaded.
This is how my code look like.
#define MY_NAME "Some_String"
int inode_created (struct inode *dir, struct dentry *dentry, int mode)
{
printk (KERN_INFO "Inode Created.\n" );
return 0 ;
}
struct security_operations my_security =
{
.inode_create = inode_created
} ;
static int __init initialize_module (void)
{
/* register ourselves with the security framework */
if (register_security (&my_security))
{
printk (KERN_INFO "Failure registering Root Plug module with the kernel\n");
/* try registering with primary module */
if (mod_reg_security (MY_NAME, &my_security))
{
printk (KERN_INFO "Failure registering Root Plug module with primary security module.\n");
return -EINVAL;
}
secondary = 1;
}
return 0 ;
}
.......
......
Code is compiled successfully. But, when I try inserting modules it gives me error
root@prasad-desktop:/home/prasad/programs/ldd/inode_hooks# insmod inode_hook.ko
insmod: error inserting 'inode_hook.ko': -1 Invalid parameters
Code for register_security() is
int register_security(struct security_operations *ops)
{
if (verify(ops)) {
printk(KERN_DEBUG "%s could not verify "
"security_operations structure.\n", __FUNCTION__);
return -EINVAL;
}
if (security_ops != &dummy_security_ops)
return -EAGAIN;
security_ops = ops;
return 0;
}
static inline int verify(struct security_operations *ops)
{
/* verify the security_operations structure exists */
if (!ops)
return -EINVAL;
security_fixup_ops(ops);
return 0;
}
A main surprise to me is only these two messages are printed there in dmesg.
Mar 10 16:34:53 prasad-desktop kernel: [ 756.143003
] Failure registering Root Plug module with the kernel
Mar 10 16:34:53 prasad-desktop kernel: [ 756.143015] Failure registering Root Plug module with primary security module.
Please help...........
Thanks in advance.
Thanks and Regards,
Prasad.