Linux Security Module Development

Based on https://lore.kernel.org/r/20071026073721.618b4778@laptopd505.fenrus.org, a new LSM is accepted into the kernel when its intent (a description of what it tries to protect against and in what cases one would expect to use it) has been appropriately documented in Documentation/admin-guide/LSM/. This allows an LSM’s code to be easily compared to its goals, and so that end users and distros can make a more informed decision about which LSMs suit their requirements.

For extensive documentation on the available LSM hook interfaces, please see include/linux/lsm_hooks.h and associated structures:

union security_list_options

Linux Security Module hook function list

Definition

union security_list_options {
#define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__);
  ;
#include "lsm_hook_defs.h";
#undef LSM_HOOK;
  void *lsm_func_addr;
};

Members

Description

Security hooks for program execution operations.

Security hooks for mount using fs_context.

[See also Filesystem Mount API]

Security hooks for filesystem operations.

Security hooks for inode operations.

Security hooks for kernfs node operations

Security hooks for file operations

Security hooks for task operations.

Security hooks for Netlink messaging.

Security hooks for Unix domain networking.

The unix_stream_connect and unix_may_send hooks were necessary because Linux provides an alternative to the conventional file name space for Unix domain sockets. Whereas binding and connecting to sockets in the file name space is mediated by the typical file permissions (and caught by the mknod and permission hooks in inode_security_ops), binding and connecting to sockets in the abstract name space is completely unmediated. Sufficient control of Unix domain sockets in the abstract name space isn’t possible using only the socket layer hooks, since we need to know the actual target socket, which is not looked up until we are inside the af_unix code.

Security hooks for socket operations.

Security hooks for SCTP

Security hooks for Infiniband

Security hooks for XFRM operations.

Security hooks affecting all Key Management operations

Security hooks affecting all System V IPC operations.

Security hooks for individual messages held in System V IPC message queues

Security hooks for System V IPC Message Queues

Security hooks for System V Shared Memory Segments

Security hooks for System V Semaphores

Security hooks for Audit

Security hooks for the general notification queue:

lock_kernel_down

Put the kernel into lock-down mode.

Security hooks for perf events

Security hooks for io_uring

struct lsm_id

Identify a Linux Security Module.

Definition

struct lsm_id {
  const char *name;
  u64 id;
};

Members

id

LSM ID number from uapi/linux/lsm.h

Description

Contains the information that identifies the LSM.

struct xattr *lsm_get_xattr_slot(struct xattr *xattrs, int *xattr_count)

Return the next available slot and increment the index

Parameters

struct xattr *xattrs

array storing LSM-provided xattrs

int *xattr_count

number of already stored xattrs (updated)

Description

Retrieve the first available slot in the xattrs array to fill with an xattr, and increment xattr_count.

Return

The slot to fill in xattrs if non-NULL, NULL otherwise.