kernel/audit.c
Source file repositories/reference/linux-study-clean/kernel/audit.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/audit.c- Extension
.c- Size
- 76088 bytes
- Lines
- 2846
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/file.hlinux/hex.hlinux/init.hlinux/types.hlinux/atomic.hlinux/mm.hlinux/export.hlinux/slab.hlinux/err.hlinux/kthread.hlinux/kernel.hlinux/syscalls.hlinux/spinlock.hlinux/rcupdate.hlinux/mutex.hlinux/gfp.hlinux/pid.hlinux/audit.hnet/sock.hnet/netlink.hlinux/skbuff.hlinux/security.hlinux/lsm_hooks.hlinux/freezer.hlinux/pid_namespace.hnet/netns/generic.hnet/ip.hnet/ipv6.hlinux/sctp.haudit.h
Detected Declarations
struct audit_netstruct auditd_connectionstruct audit_bufferstruct audit_replyfunction auditd_test_taskfunction audit_ctl_lockfunction audit_ctl_unlockfunction audit_ctl_owner_currentfunction auditd_pid_vnrfunction audit_cfg_lsmfunction audit_panicfunction audit_rate_checkfunction audit_log_lostfunction audit_log_config_changefunction audit_do_config_changefunction audit_set_rate_limitfunction audit_set_backlog_limitfunction audit_set_backlog_wait_timefunction audit_set_enabledfunction audit_set_failurefunction auditd_conn_freefunction auditd_setfunction kauditd_printk_skbfunction kauditd_rehold_skbfunction kauditd_hold_skbfunction skb_queue_lenfunction kauditd_hold_skbfunction auditd_resetfunction auditd_send_unicast_skbfunction kauditd_send_queuefunction kauditd_send_multicast_skbfunction kauditd_threadfunction audit_send_list_threadfunction audit_free_replyfunction audit_send_reply_threadfunction audit_send_replyfunction audit_netlink_okfunction audit_log_common_recv_msgfunction audit_log_user_recv_msgfunction is_audit_feature_setfunction audit_get_featurefunction audit_log_feature_changefunction audit_set_featurefunction audit_replacefunction audit_receive_msgfunction audit_receivefunction audit_log_multicastfunction audit_multicast_bind
Annotated Snippet
struct audit_net {
struct sock *sk;
};
/**
* struct auditd_connection - kernel/auditd connection state
* @pid: auditd PID
* @portid: netlink portid
* @net: the associated network namespace
* @rcu: RCU head
*
* Description:
* This struct is RCU protected; you must either hold the RCU lock for reading
* or the associated spinlock for writing.
*/
struct auditd_connection {
struct pid *pid;
u32 portid;
struct net *net;
struct rcu_head rcu;
};
static struct auditd_connection __rcu *auditd_conn;
static DEFINE_SPINLOCK(auditd_conn_lock);
/* If audit_rate_limit is non-zero, limit the rate of sending audit records
* to that number per second. This prevents DoS attacks, but results in
* audit records being dropped. */
static u32 audit_rate_limit;
/* Number of outstanding audit_buffers allowed.
* When set to zero, this means unlimited. */
static u32 audit_backlog_limit = 64;
#define AUDIT_BACKLOG_WAIT_TIME (60 * HZ)
static u32 audit_backlog_wait_time = AUDIT_BACKLOG_WAIT_TIME;
/* The identity of the user shutting down the audit system. */
static kuid_t audit_sig_uid = INVALID_UID;
static pid_t audit_sig_pid = -1;
static struct lsm_prop audit_sig_lsm;
/* Records can be lost in several ways:
0) [suppressed in audit_alloc]
1) out of memory in audit_log_start [kmalloc of struct audit_buffer]
2) out of memory in audit_log_move [alloc_skb]
3) suppressed due to audit_rate_limit
4) suppressed due to audit_backlog_limit
*/
static atomic_t audit_lost = ATOMIC_INIT(0);
/* Monotonically increasing sum of time the kernel has spent
* waiting while the backlog limit is exceeded.
*/
static atomic_t audit_backlog_wait_time_actual = ATOMIC_INIT(0);
/* Hash for inode-based rules */
struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS];
static struct kmem_cache *audit_buffer_cache;
/* queue msgs to send via kauditd_task */
static struct sk_buff_head audit_queue;
/* queue msgs due to temporary unicast send problems */
static struct sk_buff_head audit_retry_queue;
/* queue msgs waiting for new auditd connection */
static struct sk_buff_head audit_hold_queue;
/* queue servicing thread */
static struct task_struct *kauditd_task;
static DECLARE_WAIT_QUEUE_HEAD(kauditd_wait);
/* waitqueue for callers who are blocked on the audit backlog */
static DECLARE_WAIT_QUEUE_HEAD(audit_backlog_wait);
static struct audit_features af = {.vers = AUDIT_FEATURE_VERSION,
.mask = -1,
.features = 0,
.lock = 0,};
static char *audit_feature_names[2] = {
"only_unset_loginuid",
"loginuid_immutable",
};
/**
* struct audit_ctl_mutex - serialize requests from userspace
* @lock: the mutex used for locking
* @owner: the task which owns the lock
*
* Description:
* This is the lock struct used to ensure we only process userspace requests
Annotation
- Immediate include surface: `linux/file.h`, `linux/hex.h`, `linux/init.h`, `linux/types.h`, `linux/atomic.h`, `linux/mm.h`, `linux/export.h`, `linux/slab.h`.
- Detected declarations: `struct audit_net`, `struct auditd_connection`, `struct audit_buffer`, `struct audit_reply`, `function auditd_test_task`, `function audit_ctl_lock`, `function audit_ctl_unlock`, `function audit_ctl_owner_current`, `function auditd_pid_vnr`, `function audit_cfg_lsm`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.