Debian Codegraph @

upstream/debian-unstable/man8/auditctl.8

raw
1 .TH AUDITCTL "8" "Sep 2023" "Red Hat" "System Administration Utilities"
2 .SH NAME
3 auditctl \- a utility to assist controlling the kernel's audit system
4 .SH SYNOPSIS
5 \fBauditctl\fP [\fIoptions\fP]
6 .SH DESCRIPTION
7 The \fBauditctl\fP program is used to configure kernel options related to auditing, to see status of the configuration, and to load discretionary audit rules.
8 .SH CONFIGURATION OPTIONS
9 .TP
10 .BI \-b\ backlog
11 Set max number (limit) of outstanding audit buffers allowed (Kernel Default=64) If all buffers are full, the failure flag is consulted by the kernel for action.
12 .TP
13 .BI \-\-backlog_wait_time \ \fIwait_time\fP
14 Set the time for the kernel to wait (Kernel Default 60*HZ) when the backlog limit is reached before queuing more audit events to be transferred to auditd. The number must be greater than or equal to zero and less than 10 times the default value.
15 .TP
16 .BI \-\-reset_backlog_wait_time_actual
17 Reset the actual backlog wait time counter shown by the status command.
18 .TP
19 .B \-c
20 Continue loading rules in spite of an error. This summarizes the results of loading the rules. The exit code will not be success if any rule fails to load.
21 .TP
22 .B \-D
23 Delete all rules and watches. This can take a key option (\-k), too.
24 .TP
25 \fB\-e\fP [\fB0\fP..\fB2\fP]
26 Set enabled flag. When \fB0\fP is passed, this can be used to temporarily disable auditing. When \fB1\fP is passed as an argument, it will enable auditing. To lock the audit configuration so that it can't be changed, pass a \fB2\fP as the argument. Locking the configuration is intended to be the last command in audit.rules for anyone wishing this feature to be active. Any attempt to change the configuration in this mode will be audited and denied. The configuration can only be changed by rebooting the machine.
27 .TP
28 \fB\-f\fP [\fB0\fP..\fB2\fP]
29 Set failure mode
30 \fB0\fP=silent \fB1\fP=printk \fB2\fP=panic. This option lets you determine how you want the kernel to handle critical errors. Example conditions where this mode may have an effect includes: transmission errors to userspace audit daemon, backlog limit exceeded, out of kernel memory, and rate limit exceeded. The default value is \fB1\fP. Secure environments will probably want to set this to \fB2\fP.
31 .TP
32 .B \-h,\ \-\-help
33 Help
34 .TP
35 .B \-i
36 When given by itself, ignore errors when reading rules from a file. This causes auditctl to always return a success exit code. If passed as an argument to
37 .B \-s
38 then it gives an interpretation of the numbers to human readable words if possible.
39 .TP
40 .BI \-\-loginuid-immutable
41 This option tells the kernel to make loginuids unchangeable once they are set. Changing loginuids requires CAP_AUDIT_CONTROL. So, its not something that can be done by unprivileged users. Setting this makes loginuid tamper-proof, but can cause some problems in certain kinds of containers.
42 .TP
43 .BI \-q\ mount-point,subtree
44 If you have an existing directory watch and bind or move mount another subtree in the watched subtree, you need to tell the kernel to make the subtree being mounted equivalent to the directory being watched. If the subtree is already mounted at the time the directory watch is issued, the subtree is automatically tagged for watching. Please note the comma separating the two values. Omitting it will cause errors.
45 .TP
46 .BI \-r\ rate
47 Set limit in messages/sec (\fB0\fP=none). If this \fIrate\fP is non-zero and is exceeded, the failure flag is consulted by the kernel for action. The default value is \fB0\fP.
48 .TP
49 .BI \-\-reset-lost
50 Reset the lost record counter shown by the status command.
51 .TP
52 .BI \-R\ file
53 Read and execute auditctl commands from a \fIfile\fP. The commands are executed line-by-line, in the order that they appear in the file. The file must be owned by root and not readable by other users, or else it will be rejected. Empty lines are skipped. Lines starting with the '#' character are treated as comment lines. Each line is executed as if it was provided to auditctl as command line arguments. Since auditctl is the one reading the file and not a shell such as bash, do not escape special shell characters. See the EXAMPLES section for an example.
54 .TP
55 .BI \-\-signal\ signal
56 Send a signal to the audit daemon. You must have privileges to do this. Supported signals are
57 .I TERM, HUP, USR1, USR2, CONT
58 and user friendly versions
59 .I stop, reload, rotate, resume, state.
60 .TP
61 .BI \-t
62 Trim the subtrees after a mount command.
63 .SH STATUS OPTIONS
64 .TP
65 .B \-l
66 List all rules 1 per line. Two more options may be given to this command. You can give either a key option (\-k) to list rules that match a key or a (\-i) to have a0 through a3 interpreted to help determine the syscall argument values are correct .
67 .TP
68 .BI \-m\ text
69 Send a user space message into the audit system. This can only be done if you have CAP_AUDIT_WRITE capability (normally the root user has this). The resulting event will be the USER type.
70 .TP
71 .B \-s
72 Report the kernel's audit subsystem status. It will tell you the in-kernel values that can be set by \fB-e\fP, \fB-f\fP, \fB-r\fP, and \fB-b\fP options. The pid value is the process number of the audit daemon. Note that a pid of 0 indicates that the audit daemon is not running. The lost entry will tell you how many event records that have been discarded due to the kernel audit queue overflowing. The backlog field tells how many event records are currently queued waiting for auditd to read them. This option can be followed by the \fB-i\fP to get a couple fields interpreted.
73 .TP
74 .BI \-v
75 Print the version of auditctl.
76
77 .SH RULE OPTIONS
78 .TP
79 .BI \-a\ [ list,action | action,list ]
80 Append rule to the end of \fIlist\fP with \fIaction\fP. Please note the comma separating the two values. Omitting it will cause errors. The fields may be in either order. It could be list,action or action,list. The following describes the valid \fIlist\fP names:
81 .RS
82 .TP 12
83 .B task
84 Add a rule to the per task list. This rule list is used only at the time a task is created -- when fork() or clone() are called by the parent task. When using this list, you should only use fields that are known at task creation time, such as the uid, gid, etc.
85 .TP
86 .B exit
87 Add a rule to the syscall exit list. This list is used upon exit from a system call to determine if an audit event should be created.
88 .TP
89 .B user
90 Add a rule to the user message filter list. This list is used by the kernel to filter events originating in user space before relaying them to the audit daemon. It should be noted that the only fields that are valid are: uid, auid, gid, pid, subj_user, subj_role, subj_type, subj_sen, subj_clr, msgtype, and executable name. All other fields will be treated as non-matching. It should be understood that any event originating from user space from a process that has CAP_AUDIT_WRITE will be recorded into the audit trail. This means that the most likely use for this filter is with rules that have an action of never since nothing has to be done to allow events to be recorded.
91 .TP
92 .B exclude
93 Add a rule to the event type exclusion filter list. This list is used to filter events that you do not want to see. For example, if you do not want to see any avc messages, you would using this list to record that. Events can be excluded by process ID, user ID, group ID, login user ID, message type, subject context, or executable name. The action is ignored and uses its default of "never".
94 .TP
95 .B filesystem
96 Add a rule that will be applied to a whole filesystem. The filesystem must be identified with a fstype field. Normally this filter is used to exclude any events for a whole filesystem such as tracefs or debugfs.
97 .TP
98 .B io_uring
99 Add a rule to the io_uring syscall filter. Rules against this filter specify the syscall operation using the -S syscall notion explained below. You can add a key field to the rule so that it may be grouped with other rules watching the same underlying syscall.
100 .RE
101
102 The following describes the valid \fIactions\fP for the rule:
103 .RS
104 .TP 12
105 .B never
106 No audit records will be generated. This can be used to suppress event generation. In general, you want suppressions at the top of the list instead of the bottom. This is because the event triggers on the first matching rule.
107 .TP
108 .B always
109 Allocate an audit context, always fill it in at syscall entry time, and always write out a record at syscall exit time.
110 .RE
111 .TP
112 .BI \-A\ list , action
113 Add rule to the beginning \fIlist\fP with \fIaction\fP.
114 .TP
115 \fB\-C\fP [\fIf\fP\fB=\fP\fIf\fP | \fIf\fP\fB!=\fP\fIf\fP]
116 Build an inter-field comparison rule: field, operation, field. You may pass multiple comparisons on a single command line. Each one must start with \fB\-C\fP. Each inter-field equation is anded with each other as well as equations starting with \fB\-F\fP to trigger an audit record. There are 2 operators supported - equal, and not equal. Valid fields are:
117 .RS
118 .TP 12
119 .B auid, uid, euid, suid, fsuid, obj_uid; and gid, egid, sgid, fsgid, obj_gid
120 .RE
121
122 .RS
123 The two groups of uid and gid cannot be mixed. But any comparison within the group can be made. The obj_uid/gid fields are collected from the object of the event such as a file or directory.
124 .RE
125
126 .TP
127 .BI \-d\ list , action
128 Delete rule from \fIlist\fP with \fIaction\fP. The rule is deleted only if it exactly matches syscall name(s) and every field name and value.
129 .TP
130 \fB\-F\fP [\fIn\fP\fB=\fP\fIv\fP | \fIn\fP\fB!=\fP\fIv\fP | \fIn\fP\fB<\fP\fIv\fP | \fIn\fP\fB>\fP\fIv\fP | \fIn\fP\fB<=\fP\fIv\fP | \fIn\fP\fB>=\fP\fIv\fP | \fIn\fP\fB&\fP\fIv\fP | \fIn\fP\fB&=\fP\fIv\fP]
131 Build a rule field: name, operation, value. You may have up to 64 fields passed on a single command line. Each one must start with \fB\-F\fP. Each field equation is anded with each other (as well as equations starting with \fB\-C\fP) to trigger an audit record. There are 8 operators supported - equal, not equal, less than, greater than, less than or equal, and greater than or equal, bit mask, and bit test respectively. Bit test will "and" the values and check that they are equal, bit mask just "ands" the values. Fields that take a user ID may instead have the user's name; the program will convert the name to user ID. The same is true of group names. Valid fields are:
132 .RS
133 .TP 12
134 .B a0, a1, a2, a3
135 Respectively, the first 4 arguments to a syscall. Note that string arguments are not supported. This is because the kernel is passed a pointer to the string. Triggering on a pointer address value is not likely to work. So, when using this, you should only use on numeric values. This is most likely to be used on platforms that multiplex socket or IPC operations.
136 .TP
137 .B arch
138 The CPU architecture of the syscall. The arch can be found doing 'uname \-m'. If you do not know the arch of your machine but you want to use the 32 bit syscall table and your machine supports 32 bit, you can also use
139 .B b32
140 for the arch. The same applies to the 64 bit syscall table, you can use
141 .B b64.
142 In this way, you can write rules that are somewhat arch independent because the family type will be auto detected. However, syscalls can be arch specific and what is available on x86_64, may not be available on ppc. The arch directive should precede the \-S option so that auditctl knows which internal table to use to look up the syscall numbers.
143 .TP
144 .B auid
145 The original ID the user logged in with. Its an abbreviation of audit uid. Sometimes its referred to as loginuid. Either the user account text or number may be used.
146 .TP
147 .B devmajor
148 Device Major Number
149 .TP
150 .B devminor
151 Device Minor Number
152 .TP
153 .B dir
154 Full Path of Directory to watch. This will place a recursive watch on the directory and its whole subtree. It can only be used on exit list. See "\fB\-w\fP".
155 .TP
156 .B egid
157 Effective Group ID. May be numeric or the groups name.
158 .TP
159 .B euid
160 Effective User ID. May be numeric or the user account name.
161 .TP
162 .B exe
163 Absolute path to application that while executing this rule will apply to. It supports = and != operators. Note that you can only use this once for each rule.
164 .TP
165 .B exit
166 Exit value from a syscall. If the exit code is an errno, you may use the text representation, too.
167 .TP
168 .B fsgid
169 Filesystem Group ID. May be numeric or the groups name.
170 .TP
171 .B fstype
172 File system type. This is used with the filesystem rule list. The only values supported are debugfs and tracefs.
173 .TP
174 .B fsuid
175 Filesystem User ID. May be numeric or the user account name.
176 .TP
177 .B filetype
178 The target file's type. Can be either file, dir, socket, link, character, block, or fifo.
179 .TP
180 .B gid
181 Group ID. May be numeric or the groups name.
182 .TP
183 .B inode
184 Inode Number
185 .TP
186 .B key
187 Set a filter key on an audit rule. The filter key is an arbitrary string of text that can be up to 31 bytes long. It can uniquely identify the audit records produced by a rule. Typical use is for when you have several rules that together satisfy a security requirement. The key value can be searched on with ausearch so that no matter which rule triggered the event, you can find its results. The key can also be used on delete all (\-D) and list rules (\-l) to select rules with a specific key. You may have more than one key on a rule if you want to be able to search logged events in multiple ways or if you have an auditd plugin that uses a key to aid its analysis.
188 .TP
189 .B msgtype
190 This is used to match the event's record type. It should only be used on the exclude or user filter lists.
191 .TP
192 .B obj_uid
193 Object's UID
194 .TP
195 .B obj_gid
196 Object's GID
197 .TP
198 .B obj_user
199 Resource's SE Linux User
200 .TP
201 .B obj_role
202 Resource's SE Linux Role
203 .TP
204 .B obj_type
205 Resource's SE Linux Type
206 .TP
207 .B obj_lev_low
208 Resource's SE Linux Low Level
209 .TP
210 .B obj_lev_high
211 Resource's SE Linux High Level
212 .TP
213 .B path
214 Insert a watch for the file system object at \fIpath\fP. You cannot insert a watch to the top level directory. This is prohibited by the kernel. Wildcards are not supported either and will generate a warning. The way that watches work is by tracking the inode internally. This can only be used on exit list.
215 .TP
216 .B perm
217 Permission filter for file operations. Supply the access type that a file system watch will trigger on. \fBr\fP=read, \fBw\fP=write, \fBx\fP=execute, \fBa\fP=attribute change. These permissions are not the standard file permissions, but rather the kind of syscall that would do this kind of thing. The read & write syscalls are omitted from this set since they would overwhelm the logs. But rather for reads or writes, the open flags are looked at to see what permission was requested. The perm field can only be used on exit list. You can use this without specifying a syscall and the kernel will select the syscalls that satisfy the access permissions being requested. This also requires supplying an arch parameter before the perm field. This way the kernel can better determine what syscalls are needed. Not supplying an arch will result in
218 .B all
219 system calls being subject to audit. This will lower system performance.
220
221 .TP
222 .B pers
223 OS Personality Number
224 .TP
225 .B pid
226 Process ID
227 .TP
228 .B ppid
229 Parent's Process ID
230 .TP
231 .B saddr_fam
232 Address family number as found in /usr/include/bits/socket.h. For example, IPv4 would be 2 and IPv6 would be 10.
233 .TP
234 .B sessionid
235 User's login session ID
236 .TP
237 .B subj_user
238 Program's SE Linux User
239 .TP
240 .B subj_role
241 Program's SE Linux Role
242 .TP
243 .B subj_type
244 Program's SE Linux Type
245 .TP
246 .B subj_sen
247 Program's SE Linux Sensitivity
248 .TP
249 .B subj_clr
250 Program's SE Linux Clearance
251 .TP
252 .B sgid
253 Saved Group ID. See getresgid(2) man page.
254 .TP
255 .B success
256 If the exit value is >= 0 this is true/yes otherwise its false/no. When writing a rule, use a 1 for true/yes and a 0 for false/no
257 .TP
258 .B suid
259 Saved User ID. See getresuid(2) man page.
260 .TP
261 .B uid
262 User ID. May be numeric or the user account name.
263 .RE
264 .TP
265 .BI \-k\ key
266 Set a filter key on an audit rule. This is deprecated when used with watches. Convert any watches to the syscall form of rules. It is still valid for use with deleting or listing rules.
267 .TP
268 \fB\-p\fP [\fBr\fP|\fBw\fP|\fBx\fP|\fBa\fP]
269 Describe the permission access type that a file system watch will trigger on. This is deprecated. Convert watches to the syscall form.
270 .TP
271 \fB\-S\fP [\fISyscall name or number\fP|\fBall\fP]
272 Any \fIsyscall name\fP or \fInumber\fP may be used. The word '\fBall\fP' may also be used. If the given syscall is made by a program, then start an audit record. If a field rule is given and no syscall is specified, it will default to all syscalls. You may also specify multiple syscalls in the same rule by using multiple \-S options in the same rule. Doing so improves performance since fewer rules need to be evaluated. Alternatively, you may pass a comma separated list of syscall names. If you are on a bi-arch system, like x86_64, you should be aware that auditctl simply takes the text, looks it up for the native arch (in this case b64) and sends that rule to the kernel. If there are no additional arch directives, IT WILL APPLY TO BOTH 32 & 64 BIT SYSCALLS. This can have undesirable effects since there is no guarantee that any syscall has the same number on both 32 and 64 bit interfaces. You will likely want to control this and write 2 rules, one with arch equal to b32 and one with b64 to make sure the kernel finds the events that you intend. See the arch field discussion for more info.
273 .TP
274 .BI \-w\ path
275 Place a watch on path. If the path is a file, it's almost the same as using the \-F path option on a syscall rule. If the watch is on a directory, it's almost the same as using the \-F dir option on a syscall rule. The \-w form of writing watches is for backwards compatibility and is
276 .B deprecated due to poor system performance.
277 Convert watches of this form to the syscall based form. The only valid options when using a watch are the \-p and \-k.
278 .TP
279 .BI \-W\ path
280 Remove a watch for the file system object at \fIpath\fP. The rule must match exactly. See \fB-d\fP discussion for more info.
281 .SH "PERFORMANCE TIPS"
282 Syscall rules get evaluated for each syscall for every program. If you have 10 syscall rules, every program on your system will delay during a syscall while the audit system evaluates each rule. Too many syscall rules will hurt performance. Try to combine as many as you can whenever the filter, action, key, and fields are identical. For example:
283
284 .nf
285 .B auditctl \-a always,exit \-F arch=b64 \-S openat \-F success=0
286 .fi
287 .nf
288 .B auditctl \-a always,exit \-F arch=b64 \-S truncate \-F success=0
289 .fi
290
291 could be re-written as one rule:
292
293 .nf
294 .B auditctl \-a always,exit \-F arch=b64 \-S openat \-S truncate \-F success=0
295 .fi
296
297 Also, try to use file system auditing wherever practical. This improves performance. For example, if you were wanting to capture all failed opens & truncates like above, but were only concerned about files in /etc and didn't care about /usr or /sbin, its possible to use this rule:
298
299 .nf
300 .B auditctl \-a always,exit \-F arch=b64 \-S openat,truncate \-F dir=/etc \-F success=0
301 .fi
302
303 This will be higher performance since the kernel will not evaluate it each and every syscall. It will be handled by the filesystem auditing code and only checked on filesystem related syscalls.
304 .SH "EXAMPLES"
305 To see all syscalls made by a specific program:
306
307 .nf
308 # By pid:
309 .B auditctl \-a always,exit \-S all \-F pid=1005
310 # By executable path
311 .B auditctl \-a always,exit \-S all \-F exe=/usr/bin/ls
312 .fi
313
314 To see files opened by a specific user:
315
316 .nf
317 .B auditctl \-a always,exit \-S openat \-F auid=510
318 .fi
319
320 To see unsuccessful openat calls:
321
322 .nf
323 .B auditctl \-a always,exit \-S openat \-F success=0
324 .fi
325
326 To watch a file for changes (2 ways to express):
327
328 .nf
329 .B auditctl \-w /etc/shadow \-p wa # Note this slows the system
330 .B auditctl \-a always,exit \-F arch=b64 \-F path=/etc/shadow \-F perm=wa
331 .fi
332
333 To recursively watch a directory for changes (2 ways to express):
334
335 .nf
336 .B auditctl \-w /etc/ \-p wa # Note this slows the system
337 .B auditctl \-a always,exit \-F arch=b64 \-F dir=/etc/ \-F perm=wa
338 .fi
339
340 To see if an admin is accessing other user's files:
341
342 .nf
343 .B auditctl \-a always,exit \-F dir=/home/ \-F uid=0 \-C auid!=obj_uid
344 .fi
345
346 This is an example rules file:
347
348 .nf
349 # Remove all existing rules
350 \-D
351 # Never record sudo invocations
352 \-A exclude,always \-F exe=/usr/bin/sudo
353 .fi
354
355 .SH DISABLED BY DEFAULT
356
357 On many systems auditd is configured to install an
358 .B -a never,task
359 rule by default. This rule causes every new process to skip all audit rule processing. This is usually done to avoid a small performance overhead imposed by syscall auditing. If you want to use auditd, you need to remove that rule by deleting 10-no-audit.rules and adding 10-base-config.rules to the audit rules directory.
360
361 If you have defined audit rules that are not matching when they should, check auditctl -l to make sure there is no never,task rule there.
362
363 .SH FILES
364 .TP
365 .I /etc/audit/audit.rules /etc/audit/audit-stop.rules
366
367 .SH "SEE ALSO"
368 .BR audit.rules (7),
369 .BR ausearch(8),
370 .BR aureport(8),
371 .BR auditd (8).
372
373 .SH AUTHOR
374 Steve Grubb