Re: hooks and callbacks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* h.vanberkum@chello.nl (h.vanberkum@chello.nl) wrote:
> Hello everybody,
> 

> I've seen a presentation on LSM in a irc channel. I would like to
> know more on hooks and callbacks in the kernel. What's the difference
> between hooks and callbacks?

As Greg mentioned, they are often used interchangeably.  One minor
distinction:

The hook is the location in the kernel where code is called from.  For
example:

  error = security_inode_create(dir, dentry, mode);

This code is called in the kernel's VFS create function.  This is the
hook.  However, if you look more closely you'll find:

static inline int security_inode_create (struct inode *dir,
					 struct dentry *dentry,
					 int mode)
{
	return security_ops->inode_create (dir, dentry, mode);
}

The hook calls a function pointer in the security_ops structure.  The
code that is executed though this function pointer is set by the
security module when it registers it's security_ops structure.  This
code is the callback code.

> What happens if hooks and callbacks are
> not registered?(null pointer?)

For LSM, as Greg said, the framework fills out a default callback for
the null values during registration.  Other parts of the kernel will
test for null pointers and use a default if the pointer is null (inline
in the code).  The VFS is a fine example of that.

thanks,
-chris
-- 
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux