blob: b3d859831a31683cbc48836fba23b67e04af1412 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
85c87212005-04-29 16:23:29 +01002/* audit.h -- Auditing support
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
5 * All Rights Reserved.
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Written by Rickard E. (Rik) Faith <faith@redhat.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#ifndef _LINUX_AUDIT_H_
10#define _LINUX_AUDIT_H_
11
David Woodhousef001e472006-04-27 00:11:01 +010012#include <linux/sched.h>
Mike Frysingerc0a3a202013-01-11 14:32:13 -080013#include <linux/ptrace.h>
David Howells607ca462012-10-13 10:46:48 +010014#include <uapi/linux/audit.h>
Richard Guy Briggs8e6cf362020-06-04 09:20:49 -040015#include <uapi/linux/netfilter/nf_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Richard Guy Briggs84cb7772015-08-05 23:48:20 -040017#define AUDIT_INO_UNSET ((unsigned long)-1)
18#define AUDIT_DEV_UNSET ((dev_t)-1)
19
Steve Grubbc2f0c7c2005-05-06 12:38:39 +010020struct audit_sig_info {
21 uid_t uid;
22 pid_t pid;
Gustavo A. R. Silva0090c1e2020-05-07 13:50:41 -050023 char ctx[];
Steve Grubbc2f0c7c2005-05-06 12:38:39 +010024};
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026struct audit_buffer;
27struct audit_context;
28struct inode;
David Woodhouse5bb289b2005-06-24 14:14:05 +010029struct netlink_skb_parms;
Alexey Dobriyan37721e12011-01-10 08:17:10 +020030struct path;
Al Viro473ae302006-04-26 14:04:08 -040031struct linux_binprm;
George C. Wilson20ca73b2006-05-24 16:09:55 -050032struct mq_attr;
33struct mqstat;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020034struct audit_watch;
35struct audit_tree;
Eric W. Biederman099dd232014-02-28 20:36:55 -080036struct sk_buff;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020037
38struct audit_krule {
Richard Guy Briggs041d7b92014-12-23 13:02:04 -050039 u32 pflags;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020040 u32 flags;
41 u32 listnr;
42 u32 action;
43 u32 mask[AUDIT_BITMASK_SIZE];
44 u32 buflen; /* for data alloc on list rules */
45 u32 field_count;
46 char *filterkey; /* ties events to rules */
47 struct audit_field *fields;
48 struct audit_field *arch_f; /* quick access to arch field */
49 struct audit_field *inode_f; /* quick access to an inode field */
50 struct audit_watch *watch; /* associated watch */
51 struct audit_tree *tree; /* associated watched tree */
Richard Guy Briggs34d99af52015-08-05 16:29:37 -040052 struct audit_fsnotify_mark *exe;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020053 struct list_head rlist; /* entry in audit_{watch,tree}.rules list */
Al Viroe45aa212008-12-15 01:17:50 -050054 struct list_head list; /* for AUDIT_LIST* purposes only */
Al Viro0590b932008-12-14 23:45:27 -050055 u64 prio;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020056};
57
Richard Guy Briggs041d7b92014-12-23 13:02:04 -050058/* Flag to indicate legacy AUDIT_LOGINUID unset usage */
59#define AUDIT_LOGINUID_LEGACY 0x1
60
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020061struct audit_field {
62 u32 type;
Richard Guy Briggs219ca392014-03-26 07:26:47 -040063 union {
64 u32 val;
65 kuid_t uid;
66 kgid_t gid;
67 struct {
68 char *lsm_str;
69 void *lsm_rule;
70 };
71 };
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020072 u32 op;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020073};
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +020075enum audit_ntp_type {
76 AUDIT_NTP_OFFSET,
77 AUDIT_NTP_FREQ,
78 AUDIT_NTP_STATUS,
79 AUDIT_NTP_TAI,
80 AUDIT_NTP_TICK,
81 AUDIT_NTP_ADJUST,
82
83 AUDIT_NTP_NVALS /* count */
84};
85
86#ifdef CONFIG_AUDITSYSCALL
87struct audit_ntp_val {
88 long long oldval, newval;
89};
90
91struct audit_ntp_data {
92 struct audit_ntp_val vals[AUDIT_NTP_NVALS];
93};
94#else
95struct audit_ntp_data {};
96#endif
97
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -040098enum audit_nfcfgop {
99 AUDIT_XT_OP_REGISTER,
100 AUDIT_XT_OP_REPLACE,
Richard Guy Briggsa45d8852020-04-22 17:39:29 -0400101 AUDIT_XT_OP_UNREGISTER,
Richard Guy Briggs8e6cf362020-06-04 09:20:49 -0400102 AUDIT_NFT_OP_TABLE_REGISTER,
103 AUDIT_NFT_OP_TABLE_UNREGISTER,
104 AUDIT_NFT_OP_CHAIN_REGISTER,
105 AUDIT_NFT_OP_CHAIN_UNREGISTER,
106 AUDIT_NFT_OP_RULE_REGISTER,
107 AUDIT_NFT_OP_RULE_UNREGISTER,
108 AUDIT_NFT_OP_SET_REGISTER,
109 AUDIT_NFT_OP_SET_UNREGISTER,
110 AUDIT_NFT_OP_SETELEM_REGISTER,
111 AUDIT_NFT_OP_SETELEM_UNREGISTER,
112 AUDIT_NFT_OP_GEN_REGISTER,
113 AUDIT_NFT_OP_OBJ_REGISTER,
114 AUDIT_NFT_OP_OBJ_UNREGISTER,
115 AUDIT_NFT_OP_OBJ_RESET,
116 AUDIT_NFT_OP_FLOWTABLE_REGISTER,
117 AUDIT_NFT_OP_FLOWTABLE_UNREGISTER,
118 AUDIT_NFT_OP_INVALID,
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -0400119};
120
Eric Parisb0fed402013-05-22 12:54:49 -0400121extern int is_audit_feature_set(int which);
122
Al Virob9155432006-07-01 03:56:16 -0400123extern int __init audit_register_class(int class, unsigned *list);
Al Viro55669bf2006-08-31 19:26:40 -0400124extern int audit_classify_syscall(int abi, unsigned syscall);
Amy Griffise54dc242007-03-29 18:01:04 -0400125extern int audit_classify_arch(int arch);
AKASHI Takahiro4b588412014-03-15 14:48:00 +0900126/* only for compat system calls */
127extern unsigned compat_write_class[];
128extern unsigned compat_read_class[];
129extern unsigned compat_dir_class[];
130extern unsigned compat_chattr_class[];
131extern unsigned compat_signal_class[];
132
Bjorn Helgaas9e8beeb2014-10-13 18:58:48 -0600133extern int audit_classify_compat_syscall(int abi, unsigned syscall);
Jeff Layton78e2e802012-10-10 15:25:22 -0400134
135/* audit_names->type values */
136#define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
137#define AUDIT_TYPE_NORMAL 1 /* a "normal" audit record */
Jeff Laytonbfcec702012-10-10 15:25:23 -0400138#define AUDIT_TYPE_PARENT 2 /* a parent audit record */
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400139#define AUDIT_TYPE_CHILD_DELETE 3 /* a child being deleted */
140#define AUDIT_TYPE_CHILD_CREATE 4 /* a child being created */
Jeff Layton78e2e802012-10-10 15:25:22 -0400141
Chen Gang2950fa92013-04-07 16:55:23 +0800142/* maximized args number that audit_socketcall can process */
143#define AUDITSC_ARGS 6
144
Peter Hurley2e28d382016-01-09 22:55:33 -0800145/* bit values for ->signal->audit_tty */
146#define AUDIT_TTY_ENABLE BIT(0)
147#define AUDIT_TTY_LOG_PASSWD BIT(1)
148
Jeff Layton91a27b22012-10-10 15:25:28 -0400149struct filename;
150
Richard Guy Briggsf7859592018-06-05 19:20:39 -0400151#define AUDIT_OFF 0
152#define AUDIT_ON 1
153#define AUDIT_LOCKED 2
Paul Moore96368702016-01-13 09:18:55 -0500154#ifdef CONFIG_AUDIT
155/* These are defined in audit.c */
156 /* Public API */
157extern __printf(4, 5)
158void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
159 const char *fmt, ...);
160
161extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
162extern __printf(2, 3)
163void audit_log_format(struct audit_buffer *ab, const char *fmt, ...);
164extern void audit_log_end(struct audit_buffer *ab);
165extern bool audit_string_contains_control(const char *string,
166 size_t len);
167extern void audit_log_n_hex(struct audit_buffer *ab,
168 const unsigned char *buf,
169 size_t len);
170extern void audit_log_n_string(struct audit_buffer *ab,
171 const char *buf,
172 size_t n);
173extern void audit_log_n_untrustedstring(struct audit_buffer *ab,
174 const char *string,
175 size_t n);
176extern void audit_log_untrustedstring(struct audit_buffer *ab,
177 const char *string);
178extern void audit_log_d_path(struct audit_buffer *ab,
179 const char *prefix,
180 const struct path *path);
181extern void audit_log_key(struct audit_buffer *ab,
182 char *key);
Kees Cook245d7362019-10-02 16:41:58 -0700183extern void audit_log_path_denied(int type,
184 const char *operation);
Paul Moore96368702016-01-13 09:18:55 -0500185extern void audit_log_lost(const char *message);
Paul Moore96368702016-01-13 09:18:55 -0500186
187extern int audit_log_task_context(struct audit_buffer *ab);
Paul Moore2a1fe212018-11-26 18:40:07 -0500188extern void audit_log_task_info(struct audit_buffer *ab);
Paul Moore96368702016-01-13 09:18:55 -0500189
190extern int audit_update_lsm_rules(void);
191
192 /* Private API (for audit.c only) */
Paul Moore45a06422017-05-02 10:16:05 -0400193extern int audit_rule_change(int type, int seq, void *data, size_t datasz);
Paul Moore96368702016-01-13 09:18:55 -0500194extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
195
Richard Guy Briggs4b7d2482019-01-22 17:06:39 -0500196extern int audit_set_loginuid(kuid_t loginuid);
197
198static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
199{
200 return tsk->loginuid;
201}
202
203static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
204{
205 return tsk->sessionid;
206}
207
Paul Moore96368702016-01-13 09:18:55 -0500208extern u32 audit_enabled;
Richard Guy Briggsb48345a2019-05-10 12:21:49 -0400209
210extern int audit_signal_info(int sig, struct task_struct *t);
211
Paul Moore96368702016-01-13 09:18:55 -0500212#else /* CONFIG_AUDIT */
213static inline __printf(4, 5)
214void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
215 const char *fmt, ...)
216{ }
217static inline struct audit_buffer *audit_log_start(struct audit_context *ctx,
218 gfp_t gfp_mask, int type)
219{
220 return NULL;
221}
222static inline __printf(2, 3)
223void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
224{ }
225static inline void audit_log_end(struct audit_buffer *ab)
226{ }
227static inline void audit_log_n_hex(struct audit_buffer *ab,
228 const unsigned char *buf, size_t len)
229{ }
230static inline void audit_log_n_string(struct audit_buffer *ab,
231 const char *buf, size_t n)
232{ }
233static inline void audit_log_n_untrustedstring(struct audit_buffer *ab,
234 const char *string, size_t n)
235{ }
236static inline void audit_log_untrustedstring(struct audit_buffer *ab,
237 const char *string)
238{ }
239static inline void audit_log_d_path(struct audit_buffer *ab,
240 const char *prefix,
241 const struct path *path)
242{ }
243static inline void audit_log_key(struct audit_buffer *ab, char *key)
244{ }
Kees Cook245d7362019-10-02 16:41:58 -0700245static inline void audit_log_path_denied(int type, const char *operation)
Paul Moore96368702016-01-13 09:18:55 -0500246{ }
Paul Moore96368702016-01-13 09:18:55 -0500247static inline int audit_log_task_context(struct audit_buffer *ab)
248{
249 return 0;
250}
Paul Moore2a1fe212018-11-26 18:40:07 -0500251static inline void audit_log_task_info(struct audit_buffer *ab)
Paul Moore96368702016-01-13 09:18:55 -0500252{ }
Richard Guy Briggs4b7d2482019-01-22 17:06:39 -0500253
254static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
255{
256 return INVALID_UID;
257}
258
259static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
260{
261 return AUDIT_SID_UNSET;
262}
263
Richard Guy Briggsf7859592018-06-05 19:20:39 -0400264#define audit_enabled AUDIT_OFF
Richard Guy Briggsb48345a2019-05-10 12:21:49 -0400265
266static inline int audit_signal_info(int sig, struct task_struct *t)
267{
268 return 0;
269}
270
Paul Moore96368702016-01-13 09:18:55 -0500271#endif /* CONFIG_AUDIT */
272
Chris Metcalf312103d2014-03-25 09:25:41 -0400273#ifdef CONFIG_AUDIT_COMPAT_GENERIC
Eric Paris356750e2014-03-24 12:13:48 -0400274#define audit_is_compat(arch) (!((arch) & __AUDIT_ARCH_64BIT))
275#else
276#define audit_is_compat(arch) false
277#endif
278
Al Viroc9b07ea2019-07-14 13:22:27 -0400279#define AUDIT_INODE_PARENT 1 /* dentry represents the parent */
280#define AUDIT_INODE_HIDDEN 2 /* audit record should be hidden */
281#define AUDIT_INODE_NOEVAL 4 /* audit record incomplete */
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#ifdef CONFIG_AUDITSYSCALL
Eric Parisa9ebe0b2014-04-22 11:46:16 -0400284#include <asm/syscall.h> /* for syscall_get_arch() */
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286/* These are defined in auditsc.c */
287 /* Public API */
288extern int audit_alloc(struct task_struct *task);
Eric Parisa4ff8db2012-01-03 14:23:07 -0500289extern void __audit_free(struct task_struct *task);
Richard Guy Briggsb4f0d372014-03-04 10:38:06 -0500290extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
Eric Parisb05d8442012-01-03 14:23:06 -0500291 unsigned long a2, unsigned long a3);
Eric Parisd7e75282012-01-03 14:23:06 -0500292extern void __audit_syscall_exit(int ret_success, long ret_value);
Jeff Layton7ac86262012-10-10 15:25:28 -0400293extern struct filename *__audit_reusename(const __user char *uptr);
Jeff Layton91a27b22012-10-10 15:25:28 -0400294extern void __audit_getname(struct filename *name);
Richard Guy Briggsd7481b22020-07-03 12:56:19 -0400295extern void __audit_getcwd(void);
Jeff Laytonadb5c242012-10-10 16:43:13 -0400296extern void __audit_inode(struct filename *name, const struct dentry *dentry,
Jeff Layton79f65302013-07-08 15:59:36 -0700297 unsigned int flags);
Al Viro9f45f5b2014-10-31 17:44:57 -0400298extern void __audit_file(const struct file *);
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500299extern void __audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400300 const struct dentry *dentry,
301 const unsigned char type);
Tyler Hicks326bee02018-05-04 01:08:15 +0000302extern void audit_seccomp(unsigned long syscall, long signr, int code);
Tyler Hicksea6eca72018-05-04 01:08:14 +0000303extern void audit_seccomp_actions_logged(const char *names,
304 const char *old_names, int res);
Al Viroa5cb0132007-03-20 13:58:35 -0400305extern void __audit_ptrace(struct task_struct *t);
306
Richard Guy Briggsc0b0ae82018-05-12 21:58:21 -0400307static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
308{
309 task->audit_context = ctx;
310}
311
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400312static inline struct audit_context *audit_context(void)
313{
314 return current->audit_context;
315}
316
Yaowei Bai36734812015-11-04 08:23:51 -0500317static inline bool audit_dummy_context(void)
Al Virod51374a2006-08-03 10:59:26 -0400318{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400319 void *p = audit_context();
Al Virod51374a2006-08-03 10:59:26 -0400320 return !p || *(int *)p;
321}
Eric Parisa4ff8db2012-01-03 14:23:07 -0500322static inline void audit_free(struct task_struct *task)
323{
324 if (unlikely(task->audit_context))
325 __audit_free(task);
326}
Eric Paris91397402014-03-11 13:29:28 -0400327static inline void audit_syscall_entry(int major, unsigned long a0,
Eric Parisb05d8442012-01-03 14:23:06 -0500328 unsigned long a1, unsigned long a2,
329 unsigned long a3)
330{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400331 if (unlikely(audit_context()))
Richard Guy Briggsb4f0d372014-03-04 10:38:06 -0500332 __audit_syscall_entry(major, a0, a1, a2, a3);
Eric Parisb05d8442012-01-03 14:23:06 -0500333}
Eric Parisd7e75282012-01-03 14:23:06 -0500334static inline void audit_syscall_exit(void *pt_regs)
335{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400336 if (unlikely(audit_context())) {
Eric Parisd7e75282012-01-03 14:23:06 -0500337 int success = is_syscall_success(pt_regs);
AKASHI Takahiro06bdadd2014-01-13 13:33:09 -0800338 long return_code = regs_return_value(pt_regs);
Eric Parisd7e75282012-01-03 14:23:06 -0500339
340 __audit_syscall_exit(success, return_code);
341 }
342}
Jeff Layton7ac86262012-10-10 15:25:28 -0400343static inline struct filename *audit_reusename(const __user char *name)
344{
345 if (unlikely(!audit_dummy_context()))
346 return __audit_reusename(name);
347 return NULL;
348}
Jeff Layton91a27b22012-10-10 15:25:28 -0400349static inline void audit_getname(struct filename *name)
Al Virod8945bb52006-05-18 16:01:30 -0400350{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400351 if (unlikely(!audit_dummy_context()))
Al Virod8945bb52006-05-18 16:01:30 -0400352 __audit_getname(name);
353}
Richard Guy Briggsd7481b22020-07-03 12:56:19 -0400354static inline void audit_getcwd(void)
355{
356 if (unlikely(audit_context()))
357 __audit_getcwd();
358}
Jeff Layton79f65302013-07-08 15:59:36 -0700359static inline void audit_inode(struct filename *name,
360 const struct dentry *dentry,
Al Viroc9b07ea2019-07-14 13:22:27 -0400361 unsigned int aflags) {
362 if (unlikely(!audit_dummy_context()))
Richard Guy Briggs57d46572019-01-23 13:35:00 -0500363 __audit_inode(name, dentry, aflags);
Jeff Layton79f65302013-07-08 15:59:36 -0700364}
Al Viro9f45f5b2014-10-31 17:44:57 -0400365static inline void audit_file(struct file *file)
366{
367 if (unlikely(!audit_dummy_context()))
368 __audit_file(file);
369}
Jeff Layton79f65302013-07-08 15:59:36 -0700370static inline void audit_inode_parent_hidden(struct filename *name,
371 const struct dentry *dentry)
372{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400373 if (unlikely(!audit_dummy_context()))
Jeff Layton79f65302013-07-08 15:59:36 -0700374 __audit_inode(name, dentry,
375 AUDIT_INODE_PARENT | AUDIT_INODE_HIDDEN);
Amy Griffis73241cc2005-11-03 16:00:25 +0000376}
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500377static inline void audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400378 const struct dentry *dentry,
379 const unsigned char type) {
Al Viro5ac3a9c2006-07-16 06:38:45 -0400380 if (unlikely(!audit_dummy_context()))
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400381 __audit_inode_child(parent, dentry, type);
Amy Griffis73241cc2005-11-03 16:00:25 +0000382}
Steve Grubb0a4ff8c2007-04-19 10:28:21 -0400383void audit_core_dumps(long signr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Al Viroa5cb0132007-03-20 13:58:35 -0400385static inline void audit_ptrace(struct task_struct *t)
386{
387 if (unlikely(!audit_dummy_context()))
388 __audit_ptrace(t);
389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 /* Private API (for audit.c only) */
Al Viroa33e6752008-12-10 03:40:06 -0500392extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
Al Viro2570ebb2011-07-27 14:03:22 -0400393extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
Richard Guy Briggsd9cfea92013-10-30 17:56:13 -0400394extern void __audit_bprm(struct linux_binprm *bprm);
Chen Gang2950fa92013-04-07 16:55:23 +0800395extern int __audit_socketcall(int nargs, unsigned long *args);
Eric Paris07c49412012-01-03 14:23:07 -0500396extern int __audit_sockaddr(int len, void *addr);
Al Viro157cf642008-12-14 04:57:47 -0500397extern void __audit_fd_pair(int fd1, int fd2);
Al Virodf0a4282011-07-26 05:26:10 -0400398extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
Deepa Dinamanib9047722017-08-02 19:51:11 -0700399extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec64 *abs_timeout);
Al Viro20114f72008-12-10 07:16:12 -0500400extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
Al Viro73929062008-12-10 06:58:59 -0500401extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
David Howellsd84f4f92008-11-14 10:39:23 +1100402extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
403 const struct cred *new,
404 const struct cred *old);
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700405extern void __audit_log_capset(const struct cred *new, const struct cred *old);
Al Viro120a7952010-10-30 02:54:44 -0400406extern void __audit_mmap_fd(int fd, int flags);
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500407extern void __audit_log_kern_module(char *name);
Steve Grubbde8cd832017-10-02 20:21:39 -0400408extern void __audit_fanotify(unsigned int response);
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200409extern void __audit_tk_injoffset(struct timespec64 offset);
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200410extern void __audit_ntp_log(const struct audit_ntp_data *ad);
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -0400411extern void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
Richard Guy Briggs14224032020-06-27 23:24:19 -0400412 enum audit_nfcfgop op, gfp_t gfp);
Al Virod8945bb52006-05-18 16:01:30 -0400413
Al Viroa33e6752008-12-10 03:40:06 -0500414static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
Al Virod8945bb52006-05-18 16:01:30 -0400415{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400416 if (unlikely(!audit_dummy_context()))
Al Viroa33e6752008-12-10 03:40:06 -0500417 __audit_ipc_obj(ipcp);
Al Virod8945bb52006-05-18 16:01:30 -0400418}
Al Viro157cf642008-12-14 04:57:47 -0500419static inline void audit_fd_pair(int fd1, int fd2)
Al Virodb349502007-02-07 01:48:00 -0500420{
421 if (unlikely(!audit_dummy_context()))
Al Viro157cf642008-12-14 04:57:47 -0500422 __audit_fd_pair(fd1, fd2);
Al Virodb349502007-02-07 01:48:00 -0500423}
Al Viro2570ebb2011-07-27 14:03:22 -0400424static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode)
Al Virod8945bb52006-05-18 16:01:30 -0400425{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400426 if (unlikely(!audit_dummy_context()))
Al Viroe816f372008-12-10 03:47:15 -0500427 __audit_ipc_set_perm(qbytes, uid, gid, mode);
Al Virod8945bb52006-05-18 16:01:30 -0400428}
Richard Guy Briggs9410d222013-10-30 18:05:24 -0400429static inline void audit_bprm(struct linux_binprm *bprm)
Eric Paris07c49412012-01-03 14:23:07 -0500430{
431 if (unlikely(!audit_dummy_context()))
Richard Guy Briggsd9cfea92013-10-30 17:56:13 -0400432 __audit_bprm(bprm);
Eric Paris07c49412012-01-03 14:23:07 -0500433}
Chen Gang2950fa92013-04-07 16:55:23 +0800434static inline int audit_socketcall(int nargs, unsigned long *args)
Eric Paris07c49412012-01-03 14:23:07 -0500435{
436 if (unlikely(!audit_dummy_context()))
Chen Gang2950fa92013-04-07 16:55:23 +0800437 return __audit_socketcall(nargs, args);
438 return 0;
Eric Paris07c49412012-01-03 14:23:07 -0500439}
Richard Guy Briggs62bc3062017-01-17 11:07:15 -0500440
441static inline int audit_socketcall_compat(int nargs, u32 *args)
442{
443 unsigned long a[AUDITSC_ARGS];
444 int i;
445
446 if (audit_dummy_context())
447 return 0;
448
449 for (i = 0; i < nargs; i++)
450 a[i] = (unsigned long)args[i];
451 return __audit_socketcall(nargs, a);
452}
453
Eric Paris07c49412012-01-03 14:23:07 -0500454static inline int audit_sockaddr(int len, void *addr)
455{
456 if (unlikely(!audit_dummy_context()))
457 return __audit_sockaddr(len, addr);
458 return 0;
459}
Al Virodf0a4282011-07-26 05:26:10 -0400460static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500461{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400462 if (unlikely(!audit_dummy_context()))
Al Viro564f6992008-12-14 04:02:26 -0500463 __audit_mq_open(oflag, mode, attr);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500464}
Deepa Dinamanib9047722017-08-02 19:51:11 -0700465static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec64 *abs_timeout)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500466{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400467 if (unlikely(!audit_dummy_context()))
Al Viroc32c8af2008-12-14 03:46:48 -0500468 __audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500469}
Al Viro20114f72008-12-10 07:16:12 -0500470static inline void audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500471{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400472 if (unlikely(!audit_dummy_context()))
Al Viro20114f72008-12-10 07:16:12 -0500473 __audit_mq_notify(mqdes, notification);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500474}
Al Viro73929062008-12-10 06:58:59 -0500475static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500476{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400477 if (unlikely(!audit_dummy_context()))
Al Viro73929062008-12-10 06:58:59 -0500478 __audit_mq_getsetattr(mqdes, mqstat);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500479}
Eric Paris3fc689e2008-11-11 21:48:18 +1100480
David Howellsd84f4f92008-11-14 10:39:23 +1100481static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
482 const struct cred *new,
483 const struct cred *old)
Eric Paris3fc689e2008-11-11 21:48:18 +1100484{
485 if (unlikely(!audit_dummy_context()))
David Howellsd84f4f92008-11-14 10:39:23 +1100486 return __audit_log_bprm_fcaps(bprm, new, old);
487 return 0;
Eric Paris3fc689e2008-11-11 21:48:18 +1100488}
489
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700490static inline void audit_log_capset(const struct cred *new,
David Howellsd84f4f92008-11-14 10:39:23 +1100491 const struct cred *old)
Eric Parise68b75a02008-11-11 21:48:22 +1100492{
493 if (unlikely(!audit_dummy_context()))
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700494 __audit_log_capset(new, old);
Eric Parise68b75a02008-11-11 21:48:22 +1100495}
496
Al Viro120a7952010-10-30 02:54:44 -0400497static inline void audit_mmap_fd(int fd, int flags)
498{
499 if (unlikely(!audit_dummy_context()))
500 __audit_mmap_fd(fd, flags);
501}
502
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500503static inline void audit_log_kern_module(char *name)
504{
505 if (!audit_dummy_context())
506 __audit_log_kern_module(name);
507}
508
Steve Grubbde8cd832017-10-02 20:21:39 -0400509static inline void audit_fanotify(unsigned int response)
510{
511 if (!audit_dummy_context())
512 __audit_fanotify(response);
513}
514
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200515static inline void audit_tk_injoffset(struct timespec64 offset)
516{
517 /* ignore no-op events */
518 if (offset.tv_sec == 0 && offset.tv_nsec == 0)
519 return;
520
521 if (!audit_dummy_context())
522 __audit_tk_injoffset(offset);
523}
524
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200525static inline void audit_ntp_init(struct audit_ntp_data *ad)
526{
527 memset(ad, 0, sizeof(*ad));
528}
529
530static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
531 enum audit_ntp_type type, long long val)
532{
533 ad->vals[type].oldval = val;
534}
535
536static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
537 enum audit_ntp_type type, long long val)
538{
539 ad->vals[type].newval = val;
540}
541
542static inline void audit_ntp_log(const struct audit_ntp_data *ad)
543{
544 if (!audit_dummy_context())
545 __audit_ntp_log(ad);
546}
547
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -0400548static inline void audit_log_nfcfg(const char *name, u8 af,
549 unsigned int nentries,
Richard Guy Briggs14224032020-06-27 23:24:19 -0400550 enum audit_nfcfgop op, gfp_t gfp)
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -0400551{
552 if (audit_enabled)
Richard Guy Briggs14224032020-06-27 23:24:19 -0400553 __audit_log_nfcfg(name, af, nentries, op, gfp);
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -0400554}
555
Al Viro471a5c72006-07-10 08:29:24 -0400556extern int audit_n_rules;
Amy Griffise54dc242007-03-29 18:01:04 -0400557extern int audit_signals;
Eric Parisd7e75282012-01-03 14:23:06 -0500558#else /* CONFIG_AUDITSYSCALL */
Kees Cook9321d522012-10-04 17:11:11 -0700559static inline int audit_alloc(struct task_struct *task)
560{
561 return 0;
562}
563static inline void audit_free(struct task_struct *task)
564{ }
Eric Paris91397402014-03-11 13:29:28 -0400565static inline void audit_syscall_entry(int major, unsigned long a0,
Kees Cook9321d522012-10-04 17:11:11 -0700566 unsigned long a1, unsigned long a2,
567 unsigned long a3)
568{ }
569static inline void audit_syscall_exit(void *pt_regs)
570{ }
Yaowei Bai36734812015-11-04 08:23:51 -0500571static inline bool audit_dummy_context(void)
Kees Cook9321d522012-10-04 17:11:11 -0700572{
Yaowei Bai36734812015-11-04 08:23:51 -0500573 return true;
Kees Cook9321d522012-10-04 17:11:11 -0700574}
Richard Guy Briggsc0b0ae82018-05-12 21:58:21 -0400575static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
576{ }
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400577static inline struct audit_context *audit_context(void)
578{
579 return NULL;
580}
Jeff Layton7ac86262012-10-10 15:25:28 -0400581static inline struct filename *audit_reusename(const __user char *name)
582{
583 return NULL;
584}
Jeff Layton91a27b22012-10-10 15:25:28 -0400585static inline void audit_getname(struct filename *name)
Kees Cook9321d522012-10-04 17:11:11 -0700586{ }
Richard Guy Briggsd7481b22020-07-03 12:56:19 -0400587static inline void audit_getcwd(void)
588{ }
Jeff Laytonadb5c242012-10-10 16:43:13 -0400589static inline void audit_inode(struct filename *name,
590 const struct dentry *dentry,
Al Viroc9b07ea2019-07-14 13:22:27 -0400591 unsigned int aflags)
Kees Cook9321d522012-10-04 17:11:11 -0700592{ }
Al Viro9f45f5b2014-10-31 17:44:57 -0400593static inline void audit_file(struct file *file)
594{
595}
Jeff Layton79f65302013-07-08 15:59:36 -0700596static inline void audit_inode_parent_hidden(struct filename *name,
597 const struct dentry *dentry)
598{ }
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500599static inline void audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400600 const struct dentry *dentry,
601 const unsigned char type)
Kees Cook9321d522012-10-04 17:11:11 -0700602{ }
603static inline void audit_core_dumps(long signr)
604{ }
Kees Cook9321d522012-10-04 17:11:11 -0700605static inline void audit_seccomp(unsigned long syscall, long signr, int code)
606{ }
Tyler Hicksea6eca72018-05-04 01:08:14 +0000607static inline void audit_seccomp_actions_logged(const char *names,
608 const char *old_names, int res)
609{ }
Kees Cook9321d522012-10-04 17:11:11 -0700610static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
611{ }
612static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
613 gid_t gid, umode_t mode)
614{ }
Richard Guy Briggs9410d222013-10-30 18:05:24 -0400615static inline void audit_bprm(struct linux_binprm *bprm)
616{ }
Chen Gang2950fa92013-04-07 16:55:23 +0800617static inline int audit_socketcall(int nargs, unsigned long *args)
618{
619 return 0;
620}
Richard Guy Briggs62bc3062017-01-17 11:07:15 -0500621
622static inline int audit_socketcall_compat(int nargs, u32 *args)
623{
624 return 0;
625}
626
Kees Cook9321d522012-10-04 17:11:11 -0700627static inline void audit_fd_pair(int fd1, int fd2)
628{ }
629static inline int audit_sockaddr(int len, void *addr)
630{
631 return 0;
632}
633static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
634{ }
635static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
636 unsigned int msg_prio,
Deepa Dinamanib9047722017-08-02 19:51:11 -0700637 const struct timespec64 *abs_timeout)
Kees Cook9321d522012-10-04 17:11:11 -0700638{ }
639static inline void audit_mq_notify(mqd_t mqdes,
640 const struct sigevent *notification)
641{ }
642static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
643{ }
644static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
645 const struct cred *new,
646 const struct cred *old)
647{
648 return 0;
649}
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700650static inline void audit_log_capset(const struct cred *new,
651 const struct cred *old)
Kees Cook9321d522012-10-04 17:11:11 -0700652{ }
653static inline void audit_mmap_fd(int fd, int flags)
654{ }
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500655
656static inline void audit_log_kern_module(char *name)
657{
658}
659
Steve Grubbde8cd832017-10-02 20:21:39 -0400660static inline void audit_fanotify(unsigned int response)
661{ }
662
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200663static inline void audit_tk_injoffset(struct timespec64 offset)
664{ }
665
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200666static inline void audit_ntp_init(struct audit_ntp_data *ad)
667{ }
668
669static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
670 enum audit_ntp_type type, long long val)
671{ }
672
673static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
674 enum audit_ntp_type type, long long val)
675{ }
676
677static inline void audit_ntp_log(const struct audit_ntp_data *ad)
678{ }
679
Kees Cook9321d522012-10-04 17:11:11 -0700680static inline void audit_ptrace(struct task_struct *t)
681{ }
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -0400682
683static inline void audit_log_nfcfg(const char *name, u8 af,
684 unsigned int nentries,
Richard Guy Briggs14224032020-06-27 23:24:19 -0400685 enum audit_nfcfgop op, gfp_t gfp)
Richard Guy Briggsc4dad0a2020-04-22 17:39:28 -0400686{ }
687
Al Viro471a5c72006-07-10 08:29:24 -0400688#define audit_n_rules 0
Amy Griffise54dc242007-03-29 18:01:04 -0400689#define audit_signals 0
Eric Parisd7e75282012-01-03 14:23:06 -0500690#endif /* CONFIG_AUDITSYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Eric W. Biederman780a7652013-04-09 02:22:10 -0700692static inline bool audit_loginuid_set(struct task_struct *tsk)
693{
694 return uid_valid(audit_get_loginuid(tsk));
695}
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#endif