blob: 43a23e28ba23a95fa3008429b6428aa412804c5d [file] [log] [blame]
85c87212005-04-29 16:23:29 +01001/* audit.h -- Auditing support
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
4 * All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Written by Rickard E. (Rik) Faith <faith@redhat.com>
21 *
22 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#ifndef _LINUX_AUDIT_H_
24#define _LINUX_AUDIT_H_
25
David Woodhousef001e472006-04-27 00:11:01 +010026#include <linux/sched.h>
Mike Frysingerc0a3a202013-01-11 14:32:13 -080027#include <linux/ptrace.h>
Richard Guy Briggs57d46572019-01-23 13:35:00 -050028#include <linux/namei.h> /* LOOKUP_* */
David Howells607ca462012-10-13 10:46:48 +010029#include <uapi/linux/audit.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Richard Guy Briggs84cb7772015-08-05 23:48:20 -040031#define AUDIT_INO_UNSET ((unsigned long)-1)
32#define AUDIT_DEV_UNSET ((dev_t)-1)
33
Steve Grubbc2f0c7c2005-05-06 12:38:39 +010034struct audit_sig_info {
35 uid_t uid;
36 pid_t pid;
Al Viroe1396062006-05-25 10:19:47 -040037 char ctx[0];
Steve Grubbc2f0c7c2005-05-06 12:38:39 +010038};
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040struct audit_buffer;
41struct audit_context;
42struct inode;
David Woodhouse5bb289b2005-06-24 14:14:05 +010043struct netlink_skb_parms;
Alexey Dobriyan37721e12011-01-10 08:17:10 +020044struct path;
Al Viro473ae302006-04-26 14:04:08 -040045struct linux_binprm;
George C. Wilson20ca73b2006-05-24 16:09:55 -050046struct mq_attr;
47struct mqstat;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020048struct audit_watch;
49struct audit_tree;
Eric W. Biederman099dd232014-02-28 20:36:55 -080050struct sk_buff;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020051
52struct audit_krule {
Richard Guy Briggs041d7b92014-12-23 13:02:04 -050053 u32 pflags;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020054 u32 flags;
55 u32 listnr;
56 u32 action;
57 u32 mask[AUDIT_BITMASK_SIZE];
58 u32 buflen; /* for data alloc on list rules */
59 u32 field_count;
60 char *filterkey; /* ties events to rules */
61 struct audit_field *fields;
62 struct audit_field *arch_f; /* quick access to arch field */
63 struct audit_field *inode_f; /* quick access to an inode field */
64 struct audit_watch *watch; /* associated watch */
65 struct audit_tree *tree; /* associated watched tree */
Richard Guy Briggs34d99af52015-08-05 16:29:37 -040066 struct audit_fsnotify_mark *exe;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020067 struct list_head rlist; /* entry in audit_{watch,tree}.rules list */
Al Viroe45aa212008-12-15 01:17:50 -050068 struct list_head list; /* for AUDIT_LIST* purposes only */
Al Viro0590b932008-12-14 23:45:27 -050069 u64 prio;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020070};
71
Richard Guy Briggs041d7b92014-12-23 13:02:04 -050072/* Flag to indicate legacy AUDIT_LOGINUID unset usage */
73#define AUDIT_LOGINUID_LEGACY 0x1
74
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020075struct audit_field {
76 u32 type;
Richard Guy Briggs219ca392014-03-26 07:26:47 -040077 union {
78 u32 val;
79 kuid_t uid;
80 kgid_t gid;
81 struct {
82 char *lsm_str;
83 void *lsm_rule;
84 };
85 };
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020086 u32 op;
Ahmed S. Darwish9d57a7f2008-03-01 22:03:14 +020087};
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +020089enum audit_ntp_type {
90 AUDIT_NTP_OFFSET,
91 AUDIT_NTP_FREQ,
92 AUDIT_NTP_STATUS,
93 AUDIT_NTP_TAI,
94 AUDIT_NTP_TICK,
95 AUDIT_NTP_ADJUST,
96
97 AUDIT_NTP_NVALS /* count */
98};
99
100#ifdef CONFIG_AUDITSYSCALL
101struct audit_ntp_val {
102 long long oldval, newval;
103};
104
105struct audit_ntp_data {
106 struct audit_ntp_val vals[AUDIT_NTP_NVALS];
107};
108#else
109struct audit_ntp_data {};
110#endif
111
Eric Parisb0fed402013-05-22 12:54:49 -0400112extern int is_audit_feature_set(int which);
113
Al Virob9155432006-07-01 03:56:16 -0400114extern int __init audit_register_class(int class, unsigned *list);
Al Viro55669bf2006-08-31 19:26:40 -0400115extern int audit_classify_syscall(int abi, unsigned syscall);
Amy Griffise54dc242007-03-29 18:01:04 -0400116extern int audit_classify_arch(int arch);
AKASHI Takahiro4b588412014-03-15 14:48:00 +0900117/* only for compat system calls */
118extern unsigned compat_write_class[];
119extern unsigned compat_read_class[];
120extern unsigned compat_dir_class[];
121extern unsigned compat_chattr_class[];
122extern unsigned compat_signal_class[];
123
Bjorn Helgaas9e8beeb2014-10-13 18:58:48 -0600124extern int audit_classify_compat_syscall(int abi, unsigned syscall);
Jeff Layton78e2e802012-10-10 15:25:22 -0400125
126/* audit_names->type values */
127#define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
128#define AUDIT_TYPE_NORMAL 1 /* a "normal" audit record */
Jeff Laytonbfcec702012-10-10 15:25:23 -0400129#define AUDIT_TYPE_PARENT 2 /* a parent audit record */
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400130#define AUDIT_TYPE_CHILD_DELETE 3 /* a child being deleted */
131#define AUDIT_TYPE_CHILD_CREATE 4 /* a child being created */
Jeff Layton78e2e802012-10-10 15:25:22 -0400132
Chen Gang2950fa92013-04-07 16:55:23 +0800133/* maximized args number that audit_socketcall can process */
134#define AUDITSC_ARGS 6
135
Peter Hurley2e28d382016-01-09 22:55:33 -0800136/* bit values for ->signal->audit_tty */
137#define AUDIT_TTY_ENABLE BIT(0)
138#define AUDIT_TTY_LOG_PASSWD BIT(1)
139
Jeff Layton91a27b22012-10-10 15:25:28 -0400140struct filename;
141
Richard Guy Briggsf7859592018-06-05 19:20:39 -0400142#define AUDIT_OFF 0
143#define AUDIT_ON 1
144#define AUDIT_LOCKED 2
Paul Moore96368702016-01-13 09:18:55 -0500145#ifdef CONFIG_AUDIT
146/* These are defined in audit.c */
147 /* Public API */
148extern __printf(4, 5)
149void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
150 const char *fmt, ...);
151
152extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
153extern __printf(2, 3)
154void audit_log_format(struct audit_buffer *ab, const char *fmt, ...);
155extern void audit_log_end(struct audit_buffer *ab);
156extern bool audit_string_contains_control(const char *string,
157 size_t len);
158extern void audit_log_n_hex(struct audit_buffer *ab,
159 const unsigned char *buf,
160 size_t len);
161extern void audit_log_n_string(struct audit_buffer *ab,
162 const char *buf,
163 size_t n);
164extern void audit_log_n_untrustedstring(struct audit_buffer *ab,
165 const char *string,
166 size_t n);
167extern void audit_log_untrustedstring(struct audit_buffer *ab,
168 const char *string);
169extern void audit_log_d_path(struct audit_buffer *ab,
170 const char *prefix,
171 const struct path *path);
172extern void audit_log_key(struct audit_buffer *ab,
173 char *key);
Richard Guy Briggs94b9d9b2018-03-21 04:42:20 -0400174extern void audit_log_link_denied(const char *operation);
Paul Moore96368702016-01-13 09:18:55 -0500175extern void audit_log_lost(const char *message);
Paul Moore96368702016-01-13 09:18:55 -0500176
177extern int audit_log_task_context(struct audit_buffer *ab);
Paul Moore2a1fe212018-11-26 18:40:07 -0500178extern void audit_log_task_info(struct audit_buffer *ab);
Paul Moore96368702016-01-13 09:18:55 -0500179
180extern int audit_update_lsm_rules(void);
181
182 /* Private API (for audit.c only) */
Paul Moore45a06422017-05-02 10:16:05 -0400183extern int audit_rule_change(int type, int seq, void *data, size_t datasz);
Paul Moore96368702016-01-13 09:18:55 -0500184extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
185
Richard Guy Briggs4b7d2482019-01-22 17:06:39 -0500186extern int audit_set_loginuid(kuid_t loginuid);
187
188static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
189{
190 return tsk->loginuid;
191}
192
193static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
194{
195 return tsk->sessionid;
196}
197
Paul Moore96368702016-01-13 09:18:55 -0500198extern u32 audit_enabled;
199#else /* CONFIG_AUDIT */
200static inline __printf(4, 5)
201void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
202 const char *fmt, ...)
203{ }
204static inline struct audit_buffer *audit_log_start(struct audit_context *ctx,
205 gfp_t gfp_mask, int type)
206{
207 return NULL;
208}
209static inline __printf(2, 3)
210void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
211{ }
212static inline void audit_log_end(struct audit_buffer *ab)
213{ }
214static inline void audit_log_n_hex(struct audit_buffer *ab,
215 const unsigned char *buf, size_t len)
216{ }
217static inline void audit_log_n_string(struct audit_buffer *ab,
218 const char *buf, size_t n)
219{ }
220static inline void audit_log_n_untrustedstring(struct audit_buffer *ab,
221 const char *string, size_t n)
222{ }
223static inline void audit_log_untrustedstring(struct audit_buffer *ab,
224 const char *string)
225{ }
226static inline void audit_log_d_path(struct audit_buffer *ab,
227 const char *prefix,
228 const struct path *path)
229{ }
230static inline void audit_log_key(struct audit_buffer *ab, char *key)
231{ }
Richard Guy Briggs94b9d9b2018-03-21 04:42:20 -0400232static inline void audit_log_link_denied(const char *string)
Paul Moore96368702016-01-13 09:18:55 -0500233{ }
Paul Moore96368702016-01-13 09:18:55 -0500234static inline int audit_log_task_context(struct audit_buffer *ab)
235{
236 return 0;
237}
Paul Moore2a1fe212018-11-26 18:40:07 -0500238static inline void audit_log_task_info(struct audit_buffer *ab)
Paul Moore96368702016-01-13 09:18:55 -0500239{ }
Richard Guy Briggs4b7d2482019-01-22 17:06:39 -0500240
241static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
242{
243 return INVALID_UID;
244}
245
246static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
247{
248 return AUDIT_SID_UNSET;
249}
250
Richard Guy Briggsf7859592018-06-05 19:20:39 -0400251#define audit_enabled AUDIT_OFF
Paul Moore96368702016-01-13 09:18:55 -0500252#endif /* CONFIG_AUDIT */
253
Chris Metcalf312103d2014-03-25 09:25:41 -0400254#ifdef CONFIG_AUDIT_COMPAT_GENERIC
Eric Paris356750e2014-03-24 12:13:48 -0400255#define audit_is_compat(arch) (!((arch) & __AUDIT_ARCH_64BIT))
256#else
257#define audit_is_compat(arch) false
258#endif
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#ifdef CONFIG_AUDITSYSCALL
Eric Parisa9ebe0b2014-04-22 11:46:16 -0400261#include <asm/syscall.h> /* for syscall_get_arch() */
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/* These are defined in auditsc.c */
264 /* Public API */
265extern int audit_alloc(struct task_struct *task);
Eric Parisa4ff8db2012-01-03 14:23:07 -0500266extern void __audit_free(struct task_struct *task);
Richard Guy Briggsb4f0d372014-03-04 10:38:06 -0500267extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
Eric Parisb05d8442012-01-03 14:23:06 -0500268 unsigned long a2, unsigned long a3);
Eric Parisd7e75282012-01-03 14:23:06 -0500269extern void __audit_syscall_exit(int ret_success, long ret_value);
Jeff Layton7ac86262012-10-10 15:25:28 -0400270extern struct filename *__audit_reusename(const __user char *uptr);
Jeff Layton91a27b22012-10-10 15:25:28 -0400271extern void __audit_getname(struct filename *name);
Jeff Layton79f65302013-07-08 15:59:36 -0700272
273#define AUDIT_INODE_PARENT 1 /* dentry represents the parent */
274#define AUDIT_INODE_HIDDEN 2 /* audit record should be hidden */
Richard Guy Briggs57d46572019-01-23 13:35:00 -0500275#define AUDIT_INODE_NOEVAL 4 /* audit record incomplete */
Jeff Laytonadb5c242012-10-10 16:43:13 -0400276extern void __audit_inode(struct filename *name, const struct dentry *dentry,
Jeff Layton79f65302013-07-08 15:59:36 -0700277 unsigned int flags);
Al Viro9f45f5b2014-10-31 17:44:57 -0400278extern void __audit_file(const struct file *);
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500279extern void __audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400280 const struct dentry *dentry,
281 const unsigned char type);
Tyler Hicks326bee02018-05-04 01:08:15 +0000282extern void audit_seccomp(unsigned long syscall, long signr, int code);
Tyler Hicksea6eca72018-05-04 01:08:14 +0000283extern void audit_seccomp_actions_logged(const char *names,
284 const char *old_names, int res);
Al Viroa5cb0132007-03-20 13:58:35 -0400285extern void __audit_ptrace(struct task_struct *t);
286
Richard Guy Briggsc0b0ae82018-05-12 21:58:21 -0400287static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
288{
289 task->audit_context = ctx;
290}
291
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400292static inline struct audit_context *audit_context(void)
293{
294 return current->audit_context;
295}
296
Yaowei Bai36734812015-11-04 08:23:51 -0500297static inline bool audit_dummy_context(void)
Al Virod51374a2006-08-03 10:59:26 -0400298{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400299 void *p = audit_context();
Al Virod51374a2006-08-03 10:59:26 -0400300 return !p || *(int *)p;
301}
Eric Parisa4ff8db2012-01-03 14:23:07 -0500302static inline void audit_free(struct task_struct *task)
303{
304 if (unlikely(task->audit_context))
305 __audit_free(task);
306}
Eric Paris91397402014-03-11 13:29:28 -0400307static inline void audit_syscall_entry(int major, unsigned long a0,
Eric Parisb05d8442012-01-03 14:23:06 -0500308 unsigned long a1, unsigned long a2,
309 unsigned long a3)
310{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400311 if (unlikely(audit_context()))
Richard Guy Briggsb4f0d372014-03-04 10:38:06 -0500312 __audit_syscall_entry(major, a0, a1, a2, a3);
Eric Parisb05d8442012-01-03 14:23:06 -0500313}
Eric Parisd7e75282012-01-03 14:23:06 -0500314static inline void audit_syscall_exit(void *pt_regs)
315{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400316 if (unlikely(audit_context())) {
Eric Parisd7e75282012-01-03 14:23:06 -0500317 int success = is_syscall_success(pt_regs);
AKASHI Takahiro06bdadd2014-01-13 13:33:09 -0800318 long return_code = regs_return_value(pt_regs);
Eric Parisd7e75282012-01-03 14:23:06 -0500319
320 __audit_syscall_exit(success, return_code);
321 }
322}
Jeff Layton7ac86262012-10-10 15:25:28 -0400323static inline struct filename *audit_reusename(const __user char *name)
324{
325 if (unlikely(!audit_dummy_context()))
326 return __audit_reusename(name);
327 return NULL;
328}
Jeff Layton91a27b22012-10-10 15:25:28 -0400329static inline void audit_getname(struct filename *name)
Al Virod8945bb52006-05-18 16:01:30 -0400330{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400331 if (unlikely(!audit_dummy_context()))
Al Virod8945bb52006-05-18 16:01:30 -0400332 __audit_getname(name);
333}
Jeff Layton79f65302013-07-08 15:59:36 -0700334static inline void audit_inode(struct filename *name,
335 const struct dentry *dentry,
Richard Guy Briggs57d46572019-01-23 13:35:00 -0500336 unsigned int flags) {
Jeff Layton79f65302013-07-08 15:59:36 -0700337 if (unlikely(!audit_dummy_context())) {
Richard Guy Briggs57d46572019-01-23 13:35:00 -0500338 unsigned int aflags = 0;
339
340 if (flags & LOOKUP_PARENT)
341 aflags |= AUDIT_INODE_PARENT;
342 if (flags & LOOKUP_NO_EVAL)
343 aflags |= AUDIT_INODE_NOEVAL;
344 __audit_inode(name, dentry, aflags);
Jeff Layton79f65302013-07-08 15:59:36 -0700345 }
346}
Al Viro9f45f5b2014-10-31 17:44:57 -0400347static inline void audit_file(struct file *file)
348{
349 if (unlikely(!audit_dummy_context()))
350 __audit_file(file);
351}
Jeff Layton79f65302013-07-08 15:59:36 -0700352static inline void audit_inode_parent_hidden(struct filename *name,
353 const struct dentry *dentry)
354{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400355 if (unlikely(!audit_dummy_context()))
Jeff Layton79f65302013-07-08 15:59:36 -0700356 __audit_inode(name, dentry,
357 AUDIT_INODE_PARENT | AUDIT_INODE_HIDDEN);
Amy Griffis73241cc2005-11-03 16:00:25 +0000358}
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500359static inline void audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400360 const struct dentry *dentry,
361 const unsigned char type) {
Al Viro5ac3a9c2006-07-16 06:38:45 -0400362 if (unlikely(!audit_dummy_context()))
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400363 __audit_inode_child(parent, dentry, type);
Amy Griffis73241cc2005-11-03 16:00:25 +0000364}
Steve Grubb0a4ff8c2007-04-19 10:28:21 -0400365void audit_core_dumps(long signr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Al Viroa5cb0132007-03-20 13:58:35 -0400367static inline void audit_ptrace(struct task_struct *t)
368{
369 if (unlikely(!audit_dummy_context()))
370 __audit_ptrace(t);
371}
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 /* Private API (for audit.c only) */
Al Viroa33e6752008-12-10 03:40:06 -0500374extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
Al Viro2570ebb2011-07-27 14:03:22 -0400375extern 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 -0400376extern void __audit_bprm(struct linux_binprm *bprm);
Chen Gang2950fa92013-04-07 16:55:23 +0800377extern int __audit_socketcall(int nargs, unsigned long *args);
Eric Paris07c49412012-01-03 14:23:07 -0500378extern int __audit_sockaddr(int len, void *addr);
Al Viro157cf642008-12-14 04:57:47 -0500379extern void __audit_fd_pair(int fd1, int fd2);
Al Virodf0a4282011-07-26 05:26:10 -0400380extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
Deepa Dinamanib9047722017-08-02 19:51:11 -0700381extern 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 -0500382extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
Al Viro73929062008-12-10 06:58:59 -0500383extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
David Howellsd84f4f92008-11-14 10:39:23 +1100384extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
385 const struct cred *new,
386 const struct cred *old);
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700387extern void __audit_log_capset(const struct cred *new, const struct cred *old);
Al Viro120a7952010-10-30 02:54:44 -0400388extern void __audit_mmap_fd(int fd, int flags);
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500389extern void __audit_log_kern_module(char *name);
Steve Grubbde8cd832017-10-02 20:21:39 -0400390extern void __audit_fanotify(unsigned int response);
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200391extern void __audit_tk_injoffset(struct timespec64 offset);
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200392extern void __audit_ntp_log(const struct audit_ntp_data *ad);
Al Virod8945bb52006-05-18 16:01:30 -0400393
Al Viroa33e6752008-12-10 03:40:06 -0500394static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
Al Virod8945bb52006-05-18 16:01:30 -0400395{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400396 if (unlikely(!audit_dummy_context()))
Al Viroa33e6752008-12-10 03:40:06 -0500397 __audit_ipc_obj(ipcp);
Al Virod8945bb52006-05-18 16:01:30 -0400398}
Al Viro157cf642008-12-14 04:57:47 -0500399static inline void audit_fd_pair(int fd1, int fd2)
Al Virodb349502007-02-07 01:48:00 -0500400{
401 if (unlikely(!audit_dummy_context()))
Al Viro157cf642008-12-14 04:57:47 -0500402 __audit_fd_pair(fd1, fd2);
Al Virodb349502007-02-07 01:48:00 -0500403}
Al Viro2570ebb2011-07-27 14:03:22 -0400404static 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 -0400405{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400406 if (unlikely(!audit_dummy_context()))
Al Viroe816f372008-12-10 03:47:15 -0500407 __audit_ipc_set_perm(qbytes, uid, gid, mode);
Al Virod8945bb52006-05-18 16:01:30 -0400408}
Richard Guy Briggs9410d222013-10-30 18:05:24 -0400409static inline void audit_bprm(struct linux_binprm *bprm)
Eric Paris07c49412012-01-03 14:23:07 -0500410{
411 if (unlikely(!audit_dummy_context()))
Richard Guy Briggsd9cfea92013-10-30 17:56:13 -0400412 __audit_bprm(bprm);
Eric Paris07c49412012-01-03 14:23:07 -0500413}
Chen Gang2950fa92013-04-07 16:55:23 +0800414static inline int audit_socketcall(int nargs, unsigned long *args)
Eric Paris07c49412012-01-03 14:23:07 -0500415{
416 if (unlikely(!audit_dummy_context()))
Chen Gang2950fa92013-04-07 16:55:23 +0800417 return __audit_socketcall(nargs, args);
418 return 0;
Eric Paris07c49412012-01-03 14:23:07 -0500419}
Richard Guy Briggs62bc3062017-01-17 11:07:15 -0500420
421static inline int audit_socketcall_compat(int nargs, u32 *args)
422{
423 unsigned long a[AUDITSC_ARGS];
424 int i;
425
426 if (audit_dummy_context())
427 return 0;
428
429 for (i = 0; i < nargs; i++)
430 a[i] = (unsigned long)args[i];
431 return __audit_socketcall(nargs, a);
432}
433
Eric Paris07c49412012-01-03 14:23:07 -0500434static inline int audit_sockaddr(int len, void *addr)
435{
436 if (unlikely(!audit_dummy_context()))
437 return __audit_sockaddr(len, addr);
438 return 0;
439}
Al Virodf0a4282011-07-26 05:26:10 -0400440static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500441{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400442 if (unlikely(!audit_dummy_context()))
Al Viro564f6992008-12-14 04:02:26 -0500443 __audit_mq_open(oflag, mode, attr);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500444}
Deepa Dinamanib9047722017-08-02 19:51:11 -0700445static 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 -0500446{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400447 if (unlikely(!audit_dummy_context()))
Al Viroc32c8af2008-12-14 03:46:48 -0500448 __audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500449}
Al Viro20114f72008-12-10 07:16:12 -0500450static inline void audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500451{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400452 if (unlikely(!audit_dummy_context()))
Al Viro20114f72008-12-10 07:16:12 -0500453 __audit_mq_notify(mqdes, notification);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500454}
Al Viro73929062008-12-10 06:58:59 -0500455static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500456{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400457 if (unlikely(!audit_dummy_context()))
Al Viro73929062008-12-10 06:58:59 -0500458 __audit_mq_getsetattr(mqdes, mqstat);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500459}
Eric Paris3fc689e2008-11-11 21:48:18 +1100460
David Howellsd84f4f92008-11-14 10:39:23 +1100461static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
462 const struct cred *new,
463 const struct cred *old)
Eric Paris3fc689e2008-11-11 21:48:18 +1100464{
465 if (unlikely(!audit_dummy_context()))
David Howellsd84f4f92008-11-14 10:39:23 +1100466 return __audit_log_bprm_fcaps(bprm, new, old);
467 return 0;
Eric Paris3fc689e2008-11-11 21:48:18 +1100468}
469
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700470static inline void audit_log_capset(const struct cred *new,
David Howellsd84f4f92008-11-14 10:39:23 +1100471 const struct cred *old)
Eric Parise68b75a02008-11-11 21:48:22 +1100472{
473 if (unlikely(!audit_dummy_context()))
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700474 __audit_log_capset(new, old);
Eric Parise68b75a02008-11-11 21:48:22 +1100475}
476
Al Viro120a7952010-10-30 02:54:44 -0400477static inline void audit_mmap_fd(int fd, int flags)
478{
479 if (unlikely(!audit_dummy_context()))
480 __audit_mmap_fd(fd, flags);
481}
482
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500483static inline void audit_log_kern_module(char *name)
484{
485 if (!audit_dummy_context())
486 __audit_log_kern_module(name);
487}
488
Steve Grubbde8cd832017-10-02 20:21:39 -0400489static inline void audit_fanotify(unsigned int response)
490{
491 if (!audit_dummy_context())
492 __audit_fanotify(response);
493}
494
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200495static inline void audit_tk_injoffset(struct timespec64 offset)
496{
497 /* ignore no-op events */
498 if (offset.tv_sec == 0 && offset.tv_nsec == 0)
499 return;
500
501 if (!audit_dummy_context())
502 __audit_tk_injoffset(offset);
503}
504
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200505static inline void audit_ntp_init(struct audit_ntp_data *ad)
506{
507 memset(ad, 0, sizeof(*ad));
508}
509
510static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
511 enum audit_ntp_type type, long long val)
512{
513 ad->vals[type].oldval = val;
514}
515
516static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
517 enum audit_ntp_type type, long long val)
518{
519 ad->vals[type].newval = val;
520}
521
522static inline void audit_ntp_log(const struct audit_ntp_data *ad)
523{
524 if (!audit_dummy_context())
525 __audit_ntp_log(ad);
526}
527
Al Viro471a5c72006-07-10 08:29:24 -0400528extern int audit_n_rules;
Amy Griffise54dc242007-03-29 18:01:04 -0400529extern int audit_signals;
Eric Parisd7e75282012-01-03 14:23:06 -0500530#else /* CONFIG_AUDITSYSCALL */
Kees Cook9321d522012-10-04 17:11:11 -0700531static inline int audit_alloc(struct task_struct *task)
532{
533 return 0;
534}
535static inline void audit_free(struct task_struct *task)
536{ }
Eric Paris91397402014-03-11 13:29:28 -0400537static inline void audit_syscall_entry(int major, unsigned long a0,
Kees Cook9321d522012-10-04 17:11:11 -0700538 unsigned long a1, unsigned long a2,
539 unsigned long a3)
540{ }
541static inline void audit_syscall_exit(void *pt_regs)
542{ }
Yaowei Bai36734812015-11-04 08:23:51 -0500543static inline bool audit_dummy_context(void)
Kees Cook9321d522012-10-04 17:11:11 -0700544{
Yaowei Bai36734812015-11-04 08:23:51 -0500545 return true;
Kees Cook9321d522012-10-04 17:11:11 -0700546}
Richard Guy Briggsc0b0ae82018-05-12 21:58:21 -0400547static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
548{ }
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400549static inline struct audit_context *audit_context(void)
550{
551 return NULL;
552}
Jeff Layton7ac86262012-10-10 15:25:28 -0400553static inline struct filename *audit_reusename(const __user char *name)
554{
555 return NULL;
556}
Jeff Layton91a27b22012-10-10 15:25:28 -0400557static inline void audit_getname(struct filename *name)
Kees Cook9321d522012-10-04 17:11:11 -0700558{ }
Jeff Laytonadb5c242012-10-10 16:43:13 -0400559static inline void __audit_inode(struct filename *name,
560 const struct dentry *dentry,
Jeff Layton79f65302013-07-08 15:59:36 -0700561 unsigned int flags)
Kees Cook9321d522012-10-04 17:11:11 -0700562{ }
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500563static inline void __audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400564 const struct dentry *dentry,
565 const unsigned char type)
Kees Cook9321d522012-10-04 17:11:11 -0700566{ }
Jeff Laytonadb5c242012-10-10 16:43:13 -0400567static inline void audit_inode(struct filename *name,
568 const struct dentry *dentry,
Jeff Laytonbfcec702012-10-10 15:25:23 -0400569 unsigned int parent)
Kees Cook9321d522012-10-04 17:11:11 -0700570{ }
Al Viro9f45f5b2014-10-31 17:44:57 -0400571static inline void audit_file(struct file *file)
572{
573}
Jeff Layton79f65302013-07-08 15:59:36 -0700574static inline void audit_inode_parent_hidden(struct filename *name,
575 const struct dentry *dentry)
576{ }
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500577static inline void audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400578 const struct dentry *dentry,
579 const unsigned char type)
Kees Cook9321d522012-10-04 17:11:11 -0700580{ }
581static inline void audit_core_dumps(long signr)
582{ }
Kees Cook9321d522012-10-04 17:11:11 -0700583static inline void audit_seccomp(unsigned long syscall, long signr, int code)
584{ }
Tyler Hicksea6eca72018-05-04 01:08:14 +0000585static inline void audit_seccomp_actions_logged(const char *names,
586 const char *old_names, int res)
587{ }
Kees Cook9321d522012-10-04 17:11:11 -0700588static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
589{ }
590static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
591 gid_t gid, umode_t mode)
592{ }
Richard Guy Briggs9410d222013-10-30 18:05:24 -0400593static inline void audit_bprm(struct linux_binprm *bprm)
594{ }
Chen Gang2950fa92013-04-07 16:55:23 +0800595static inline int audit_socketcall(int nargs, unsigned long *args)
596{
597 return 0;
598}
Richard Guy Briggs62bc3062017-01-17 11:07:15 -0500599
600static inline int audit_socketcall_compat(int nargs, u32 *args)
601{
602 return 0;
603}
604
Kees Cook9321d522012-10-04 17:11:11 -0700605static inline void audit_fd_pair(int fd1, int fd2)
606{ }
607static inline int audit_sockaddr(int len, void *addr)
608{
609 return 0;
610}
611static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
612{ }
613static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
614 unsigned int msg_prio,
Deepa Dinamanib9047722017-08-02 19:51:11 -0700615 const struct timespec64 *abs_timeout)
Kees Cook9321d522012-10-04 17:11:11 -0700616{ }
617static inline void audit_mq_notify(mqd_t mqdes,
618 const struct sigevent *notification)
619{ }
620static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
621{ }
622static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
623 const struct cred *new,
624 const struct cred *old)
625{
626 return 0;
627}
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700628static inline void audit_log_capset(const struct cred *new,
629 const struct cred *old)
Kees Cook9321d522012-10-04 17:11:11 -0700630{ }
631static inline void audit_mmap_fd(int fd, int flags)
632{ }
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500633
634static inline void audit_log_kern_module(char *name)
635{
636}
637
Steve Grubbde8cd832017-10-02 20:21:39 -0400638static inline void audit_fanotify(unsigned int response)
639{ }
640
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200641static inline void audit_tk_injoffset(struct timespec64 offset)
642{ }
643
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200644static inline void audit_ntp_init(struct audit_ntp_data *ad)
645{ }
646
647static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
648 enum audit_ntp_type type, long long val)
649{ }
650
651static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
652 enum audit_ntp_type type, long long val)
653{ }
654
655static inline void audit_ntp_log(const struct audit_ntp_data *ad)
656{ }
657
Kees Cook9321d522012-10-04 17:11:11 -0700658static inline void audit_ptrace(struct task_struct *t)
659{ }
Al Viro471a5c72006-07-10 08:29:24 -0400660#define audit_n_rules 0
Amy Griffise54dc242007-03-29 18:01:04 -0400661#define audit_signals 0
Eric Parisd7e75282012-01-03 14:23:06 -0500662#endif /* CONFIG_AUDITSYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Eric W. Biederman780a7652013-04-09 02:22:10 -0700664static inline bool audit_loginuid_set(struct task_struct *tsk)
665{
666 return uid_valid(audit_get_loginuid(tsk));
667}
668
Kees Cook9321d522012-10-04 17:11:11 -0700669static inline void audit_log_string(struct audit_buffer *ab, const char *buf)
670{
671 audit_log_n_string(ab, buf, strlen(buf));
672}
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#endif