blob: 97d0925454dff33cac393801dea7a3c8a885786f [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>
Richard Guy Briggs57d46572019-01-23 13:35:00 -050014#include <linux/namei.h> /* LOOKUP_* */
David Howells607ca462012-10-13 10:46:48 +010015#include <uapi/linux/audit.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;
Al Viroe1396062006-05-25 10:19:47 -040023 char ctx[0];
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
Eric Parisb0fed402013-05-22 12:54:49 -040098extern int is_audit_feature_set(int which);
99
Al Virob9155432006-07-01 03:56:16 -0400100extern int __init audit_register_class(int class, unsigned *list);
Al Viro55669bf2006-08-31 19:26:40 -0400101extern int audit_classify_syscall(int abi, unsigned syscall);
Amy Griffise54dc242007-03-29 18:01:04 -0400102extern int audit_classify_arch(int arch);
AKASHI Takahiro4b588412014-03-15 14:48:00 +0900103/* only for compat system calls */
104extern unsigned compat_write_class[];
105extern unsigned compat_read_class[];
106extern unsigned compat_dir_class[];
107extern unsigned compat_chattr_class[];
108extern unsigned compat_signal_class[];
109
Bjorn Helgaas9e8beeb2014-10-13 18:58:48 -0600110extern int audit_classify_compat_syscall(int abi, unsigned syscall);
Jeff Layton78e2e802012-10-10 15:25:22 -0400111
112/* audit_names->type values */
113#define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
114#define AUDIT_TYPE_NORMAL 1 /* a "normal" audit record */
Jeff Laytonbfcec702012-10-10 15:25:23 -0400115#define AUDIT_TYPE_PARENT 2 /* a parent audit record */
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400116#define AUDIT_TYPE_CHILD_DELETE 3 /* a child being deleted */
117#define AUDIT_TYPE_CHILD_CREATE 4 /* a child being created */
Jeff Layton78e2e802012-10-10 15:25:22 -0400118
Chen Gang2950fa92013-04-07 16:55:23 +0800119/* maximized args number that audit_socketcall can process */
120#define AUDITSC_ARGS 6
121
Peter Hurley2e28d382016-01-09 22:55:33 -0800122/* bit values for ->signal->audit_tty */
123#define AUDIT_TTY_ENABLE BIT(0)
124#define AUDIT_TTY_LOG_PASSWD BIT(1)
125
Jeff Layton91a27b22012-10-10 15:25:28 -0400126struct filename;
127
Richard Guy Briggsf7859592018-06-05 19:20:39 -0400128#define AUDIT_OFF 0
129#define AUDIT_ON 1
130#define AUDIT_LOCKED 2
Paul Moore96368702016-01-13 09:18:55 -0500131#ifdef CONFIG_AUDIT
132/* These are defined in audit.c */
133 /* Public API */
134extern __printf(4, 5)
135void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
136 const char *fmt, ...);
137
138extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
139extern __printf(2, 3)
140void audit_log_format(struct audit_buffer *ab, const char *fmt, ...);
141extern void audit_log_end(struct audit_buffer *ab);
142extern bool audit_string_contains_control(const char *string,
143 size_t len);
144extern void audit_log_n_hex(struct audit_buffer *ab,
145 const unsigned char *buf,
146 size_t len);
147extern void audit_log_n_string(struct audit_buffer *ab,
148 const char *buf,
149 size_t n);
150extern void audit_log_n_untrustedstring(struct audit_buffer *ab,
151 const char *string,
152 size_t n);
153extern void audit_log_untrustedstring(struct audit_buffer *ab,
154 const char *string);
155extern void audit_log_d_path(struct audit_buffer *ab,
156 const char *prefix,
157 const struct path *path);
158extern void audit_log_key(struct audit_buffer *ab,
159 char *key);
Richard Guy Briggs94b9d9b2018-03-21 04:42:20 -0400160extern void audit_log_link_denied(const char *operation);
Paul Moore96368702016-01-13 09:18:55 -0500161extern void audit_log_lost(const char *message);
Paul Moore96368702016-01-13 09:18:55 -0500162
163extern int audit_log_task_context(struct audit_buffer *ab);
Paul Moore2a1fe212018-11-26 18:40:07 -0500164extern void audit_log_task_info(struct audit_buffer *ab);
Paul Moore96368702016-01-13 09:18:55 -0500165
166extern int audit_update_lsm_rules(void);
167
168 /* Private API (for audit.c only) */
Paul Moore45a06422017-05-02 10:16:05 -0400169extern int audit_rule_change(int type, int seq, void *data, size_t datasz);
Paul Moore96368702016-01-13 09:18:55 -0500170extern int audit_list_rules_send(struct sk_buff *request_skb, int seq);
171
Richard Guy Briggs4b7d2482019-01-22 17:06:39 -0500172extern int audit_set_loginuid(kuid_t loginuid);
173
174static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
175{
176 return tsk->loginuid;
177}
178
179static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
180{
181 return tsk->sessionid;
182}
183
Paul Moore96368702016-01-13 09:18:55 -0500184extern u32 audit_enabled;
Richard Guy Briggsb48345a2019-05-10 12:21:49 -0400185
186extern int audit_signal_info(int sig, struct task_struct *t);
187
Paul Moore96368702016-01-13 09:18:55 -0500188#else /* CONFIG_AUDIT */
189static inline __printf(4, 5)
190void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
191 const char *fmt, ...)
192{ }
193static inline struct audit_buffer *audit_log_start(struct audit_context *ctx,
194 gfp_t gfp_mask, int type)
195{
196 return NULL;
197}
198static inline __printf(2, 3)
199void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
200{ }
201static inline void audit_log_end(struct audit_buffer *ab)
202{ }
203static inline void audit_log_n_hex(struct audit_buffer *ab,
204 const unsigned char *buf, size_t len)
205{ }
206static inline void audit_log_n_string(struct audit_buffer *ab,
207 const char *buf, size_t n)
208{ }
209static inline void audit_log_n_untrustedstring(struct audit_buffer *ab,
210 const char *string, size_t n)
211{ }
212static inline void audit_log_untrustedstring(struct audit_buffer *ab,
213 const char *string)
214{ }
215static inline void audit_log_d_path(struct audit_buffer *ab,
216 const char *prefix,
217 const struct path *path)
218{ }
219static inline void audit_log_key(struct audit_buffer *ab, char *key)
220{ }
Richard Guy Briggs94b9d9b2018-03-21 04:42:20 -0400221static inline void audit_log_link_denied(const char *string)
Paul Moore96368702016-01-13 09:18:55 -0500222{ }
Paul Moore96368702016-01-13 09:18:55 -0500223static inline int audit_log_task_context(struct audit_buffer *ab)
224{
225 return 0;
226}
Paul Moore2a1fe212018-11-26 18:40:07 -0500227static inline void audit_log_task_info(struct audit_buffer *ab)
Paul Moore96368702016-01-13 09:18:55 -0500228{ }
Richard Guy Briggs4b7d2482019-01-22 17:06:39 -0500229
230static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
231{
232 return INVALID_UID;
233}
234
235static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
236{
237 return AUDIT_SID_UNSET;
238}
239
Richard Guy Briggsf7859592018-06-05 19:20:39 -0400240#define audit_enabled AUDIT_OFF
Richard Guy Briggsb48345a2019-05-10 12:21:49 -0400241
242static inline int audit_signal_info(int sig, struct task_struct *t)
243{
244 return 0;
245}
246
Paul Moore96368702016-01-13 09:18:55 -0500247#endif /* CONFIG_AUDIT */
248
Chris Metcalf312103d2014-03-25 09:25:41 -0400249#ifdef CONFIG_AUDIT_COMPAT_GENERIC
Eric Paris356750e2014-03-24 12:13:48 -0400250#define audit_is_compat(arch) (!((arch) & __AUDIT_ARCH_64BIT))
251#else
252#define audit_is_compat(arch) false
253#endif
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#ifdef CONFIG_AUDITSYSCALL
Eric Parisa9ebe0b2014-04-22 11:46:16 -0400256#include <asm/syscall.h> /* for syscall_get_arch() */
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* These are defined in auditsc.c */
259 /* Public API */
260extern int audit_alloc(struct task_struct *task);
Eric Parisa4ff8db2012-01-03 14:23:07 -0500261extern void __audit_free(struct task_struct *task);
Richard Guy Briggsb4f0d372014-03-04 10:38:06 -0500262extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
Eric Parisb05d8442012-01-03 14:23:06 -0500263 unsigned long a2, unsigned long a3);
Eric Parisd7e75282012-01-03 14:23:06 -0500264extern void __audit_syscall_exit(int ret_success, long ret_value);
Jeff Layton7ac86262012-10-10 15:25:28 -0400265extern struct filename *__audit_reusename(const __user char *uptr);
Jeff Layton91a27b22012-10-10 15:25:28 -0400266extern void __audit_getname(struct filename *name);
Jeff Layton79f65302013-07-08 15:59:36 -0700267
268#define AUDIT_INODE_PARENT 1 /* dentry represents the parent */
269#define AUDIT_INODE_HIDDEN 2 /* audit record should be hidden */
Richard Guy Briggs57d46572019-01-23 13:35:00 -0500270#define AUDIT_INODE_NOEVAL 4 /* audit record incomplete */
Jeff Laytonadb5c242012-10-10 16:43:13 -0400271extern void __audit_inode(struct filename *name, const struct dentry *dentry,
Jeff Layton79f65302013-07-08 15:59:36 -0700272 unsigned int flags);
Al Viro9f45f5b2014-10-31 17:44:57 -0400273extern void __audit_file(const struct file *);
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500274extern void __audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400275 const struct dentry *dentry,
276 const unsigned char type);
Tyler Hicks326bee02018-05-04 01:08:15 +0000277extern void audit_seccomp(unsigned long syscall, long signr, int code);
Tyler Hicksea6eca72018-05-04 01:08:14 +0000278extern void audit_seccomp_actions_logged(const char *names,
279 const char *old_names, int res);
Al Viroa5cb0132007-03-20 13:58:35 -0400280extern void __audit_ptrace(struct task_struct *t);
281
Richard Guy Briggsc0b0ae82018-05-12 21:58:21 -0400282static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
283{
284 task->audit_context = ctx;
285}
286
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400287static inline struct audit_context *audit_context(void)
288{
289 return current->audit_context;
290}
291
Yaowei Bai36734812015-11-04 08:23:51 -0500292static inline bool audit_dummy_context(void)
Al Virod51374a2006-08-03 10:59:26 -0400293{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400294 void *p = audit_context();
Al Virod51374a2006-08-03 10:59:26 -0400295 return !p || *(int *)p;
296}
Eric Parisa4ff8db2012-01-03 14:23:07 -0500297static inline void audit_free(struct task_struct *task)
298{
299 if (unlikely(task->audit_context))
300 __audit_free(task);
301}
Eric Paris91397402014-03-11 13:29:28 -0400302static inline void audit_syscall_entry(int major, unsigned long a0,
Eric Parisb05d8442012-01-03 14:23:06 -0500303 unsigned long a1, unsigned long a2,
304 unsigned long a3)
305{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400306 if (unlikely(audit_context()))
Richard Guy Briggsb4f0d372014-03-04 10:38:06 -0500307 __audit_syscall_entry(major, a0, a1, a2, a3);
Eric Parisb05d8442012-01-03 14:23:06 -0500308}
Eric Parisd7e75282012-01-03 14:23:06 -0500309static inline void audit_syscall_exit(void *pt_regs)
310{
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400311 if (unlikely(audit_context())) {
Eric Parisd7e75282012-01-03 14:23:06 -0500312 int success = is_syscall_success(pt_regs);
AKASHI Takahiro06bdadd2014-01-13 13:33:09 -0800313 long return_code = regs_return_value(pt_regs);
Eric Parisd7e75282012-01-03 14:23:06 -0500314
315 __audit_syscall_exit(success, return_code);
316 }
317}
Jeff Layton7ac86262012-10-10 15:25:28 -0400318static inline struct filename *audit_reusename(const __user char *name)
319{
320 if (unlikely(!audit_dummy_context()))
321 return __audit_reusename(name);
322 return NULL;
323}
Jeff Layton91a27b22012-10-10 15:25:28 -0400324static inline void audit_getname(struct filename *name)
Al Virod8945bb52006-05-18 16:01:30 -0400325{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400326 if (unlikely(!audit_dummy_context()))
Al Virod8945bb52006-05-18 16:01:30 -0400327 __audit_getname(name);
328}
Jeff Layton79f65302013-07-08 15:59:36 -0700329static inline void audit_inode(struct filename *name,
330 const struct dentry *dentry,
Richard Guy Briggs57d46572019-01-23 13:35:00 -0500331 unsigned int flags) {
Jeff Layton79f65302013-07-08 15:59:36 -0700332 if (unlikely(!audit_dummy_context())) {
Richard Guy Briggs57d46572019-01-23 13:35:00 -0500333 unsigned int aflags = 0;
334
335 if (flags & LOOKUP_PARENT)
336 aflags |= AUDIT_INODE_PARENT;
337 if (flags & LOOKUP_NO_EVAL)
338 aflags |= AUDIT_INODE_NOEVAL;
339 __audit_inode(name, dentry, aflags);
Jeff Layton79f65302013-07-08 15:59:36 -0700340 }
341}
Al Viro9f45f5b2014-10-31 17:44:57 -0400342static inline void audit_file(struct file *file)
343{
344 if (unlikely(!audit_dummy_context()))
345 __audit_file(file);
346}
Jeff Layton79f65302013-07-08 15:59:36 -0700347static inline void audit_inode_parent_hidden(struct filename *name,
348 const struct dentry *dentry)
349{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400350 if (unlikely(!audit_dummy_context()))
Jeff Layton79f65302013-07-08 15:59:36 -0700351 __audit_inode(name, dentry,
352 AUDIT_INODE_PARENT | AUDIT_INODE_HIDDEN);
Amy Griffis73241cc2005-11-03 16:00:25 +0000353}
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500354static inline void audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400355 const struct dentry *dentry,
356 const unsigned char type) {
Al Viro5ac3a9c2006-07-16 06:38:45 -0400357 if (unlikely(!audit_dummy_context()))
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400358 __audit_inode_child(parent, dentry, type);
Amy Griffis73241cc2005-11-03 16:00:25 +0000359}
Steve Grubb0a4ff8c2007-04-19 10:28:21 -0400360void audit_core_dumps(long signr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Al Viroa5cb0132007-03-20 13:58:35 -0400362static inline void audit_ptrace(struct task_struct *t)
363{
364 if (unlikely(!audit_dummy_context()))
365 __audit_ptrace(t);
366}
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /* Private API (for audit.c only) */
Al Viroa33e6752008-12-10 03:40:06 -0500369extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
Al Viro2570ebb2011-07-27 14:03:22 -0400370extern 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 -0400371extern void __audit_bprm(struct linux_binprm *bprm);
Chen Gang2950fa92013-04-07 16:55:23 +0800372extern int __audit_socketcall(int nargs, unsigned long *args);
Eric Paris07c49412012-01-03 14:23:07 -0500373extern int __audit_sockaddr(int len, void *addr);
Al Viro157cf642008-12-14 04:57:47 -0500374extern void __audit_fd_pair(int fd1, int fd2);
Al Virodf0a4282011-07-26 05:26:10 -0400375extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
Deepa Dinamanib9047722017-08-02 19:51:11 -0700376extern 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 -0500377extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
Al Viro73929062008-12-10 06:58:59 -0500378extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
David Howellsd84f4f92008-11-14 10:39:23 +1100379extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
380 const struct cred *new,
381 const struct cred *old);
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700382extern void __audit_log_capset(const struct cred *new, const struct cred *old);
Al Viro120a7952010-10-30 02:54:44 -0400383extern void __audit_mmap_fd(int fd, int flags);
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500384extern void __audit_log_kern_module(char *name);
Steve Grubbde8cd832017-10-02 20:21:39 -0400385extern void __audit_fanotify(unsigned int response);
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200386extern void __audit_tk_injoffset(struct timespec64 offset);
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200387extern void __audit_ntp_log(const struct audit_ntp_data *ad);
Al Virod8945bb52006-05-18 16:01:30 -0400388
Al Viroa33e6752008-12-10 03:40:06 -0500389static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
Al Virod8945bb52006-05-18 16:01:30 -0400390{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400391 if (unlikely(!audit_dummy_context()))
Al Viroa33e6752008-12-10 03:40:06 -0500392 __audit_ipc_obj(ipcp);
Al Virod8945bb52006-05-18 16:01:30 -0400393}
Al Viro157cf642008-12-14 04:57:47 -0500394static inline void audit_fd_pair(int fd1, int fd2)
Al Virodb349502007-02-07 01:48:00 -0500395{
396 if (unlikely(!audit_dummy_context()))
Al Viro157cf642008-12-14 04:57:47 -0500397 __audit_fd_pair(fd1, fd2);
Al Virodb349502007-02-07 01:48:00 -0500398}
Al Viro2570ebb2011-07-27 14:03:22 -0400399static 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 -0400400{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400401 if (unlikely(!audit_dummy_context()))
Al Viroe816f372008-12-10 03:47:15 -0500402 __audit_ipc_set_perm(qbytes, uid, gid, mode);
Al Virod8945bb52006-05-18 16:01:30 -0400403}
Richard Guy Briggs9410d222013-10-30 18:05:24 -0400404static inline void audit_bprm(struct linux_binprm *bprm)
Eric Paris07c49412012-01-03 14:23:07 -0500405{
406 if (unlikely(!audit_dummy_context()))
Richard Guy Briggsd9cfea92013-10-30 17:56:13 -0400407 __audit_bprm(bprm);
Eric Paris07c49412012-01-03 14:23:07 -0500408}
Chen Gang2950fa92013-04-07 16:55:23 +0800409static inline int audit_socketcall(int nargs, unsigned long *args)
Eric Paris07c49412012-01-03 14:23:07 -0500410{
411 if (unlikely(!audit_dummy_context()))
Chen Gang2950fa92013-04-07 16:55:23 +0800412 return __audit_socketcall(nargs, args);
413 return 0;
Eric Paris07c49412012-01-03 14:23:07 -0500414}
Richard Guy Briggs62bc3062017-01-17 11:07:15 -0500415
416static inline int audit_socketcall_compat(int nargs, u32 *args)
417{
418 unsigned long a[AUDITSC_ARGS];
419 int i;
420
421 if (audit_dummy_context())
422 return 0;
423
424 for (i = 0; i < nargs; i++)
425 a[i] = (unsigned long)args[i];
426 return __audit_socketcall(nargs, a);
427}
428
Eric Paris07c49412012-01-03 14:23:07 -0500429static inline int audit_sockaddr(int len, void *addr)
430{
431 if (unlikely(!audit_dummy_context()))
432 return __audit_sockaddr(len, addr);
433 return 0;
434}
Al Virodf0a4282011-07-26 05:26:10 -0400435static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500436{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400437 if (unlikely(!audit_dummy_context()))
Al Viro564f6992008-12-14 04:02:26 -0500438 __audit_mq_open(oflag, mode, attr);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500439}
Deepa Dinamanib9047722017-08-02 19:51:11 -0700440static 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 -0500441{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400442 if (unlikely(!audit_dummy_context()))
Al Viroc32c8af2008-12-14 03:46:48 -0500443 __audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500444}
Al Viro20114f72008-12-10 07:16:12 -0500445static inline void audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500446{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400447 if (unlikely(!audit_dummy_context()))
Al Viro20114f72008-12-10 07:16:12 -0500448 __audit_mq_notify(mqdes, notification);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500449}
Al Viro73929062008-12-10 06:58:59 -0500450static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
George C. Wilson20ca73b2006-05-24 16:09:55 -0500451{
Al Viro5ac3a9c2006-07-16 06:38:45 -0400452 if (unlikely(!audit_dummy_context()))
Al Viro73929062008-12-10 06:58:59 -0500453 __audit_mq_getsetattr(mqdes, mqstat);
George C. Wilson20ca73b2006-05-24 16:09:55 -0500454}
Eric Paris3fc689e2008-11-11 21:48:18 +1100455
David Howellsd84f4f92008-11-14 10:39:23 +1100456static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
457 const struct cred *new,
458 const struct cred *old)
Eric Paris3fc689e2008-11-11 21:48:18 +1100459{
460 if (unlikely(!audit_dummy_context()))
David Howellsd84f4f92008-11-14 10:39:23 +1100461 return __audit_log_bprm_fcaps(bprm, new, old);
462 return 0;
Eric Paris3fc689e2008-11-11 21:48:18 +1100463}
464
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700465static inline void audit_log_capset(const struct cred *new,
David Howellsd84f4f92008-11-14 10:39:23 +1100466 const struct cred *old)
Eric Parise68b75a02008-11-11 21:48:22 +1100467{
468 if (unlikely(!audit_dummy_context()))
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700469 __audit_log_capset(new, old);
Eric Parise68b75a02008-11-11 21:48:22 +1100470}
471
Al Viro120a7952010-10-30 02:54:44 -0400472static inline void audit_mmap_fd(int fd, int flags)
473{
474 if (unlikely(!audit_dummy_context()))
475 __audit_mmap_fd(fd, flags);
476}
477
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500478static inline void audit_log_kern_module(char *name)
479{
480 if (!audit_dummy_context())
481 __audit_log_kern_module(name);
482}
483
Steve Grubbde8cd832017-10-02 20:21:39 -0400484static inline void audit_fanotify(unsigned int response)
485{
486 if (!audit_dummy_context())
487 __audit_fanotify(response);
488}
489
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200490static inline void audit_tk_injoffset(struct timespec64 offset)
491{
492 /* ignore no-op events */
493 if (offset.tv_sec == 0 && offset.tv_nsec == 0)
494 return;
495
496 if (!audit_dummy_context())
497 __audit_tk_injoffset(offset);
498}
499
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200500static inline void audit_ntp_init(struct audit_ntp_data *ad)
501{
502 memset(ad, 0, sizeof(*ad));
503}
504
505static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
506 enum audit_ntp_type type, long long val)
507{
508 ad->vals[type].oldval = val;
509}
510
511static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
512 enum audit_ntp_type type, long long val)
513{
514 ad->vals[type].newval = val;
515}
516
517static inline void audit_ntp_log(const struct audit_ntp_data *ad)
518{
519 if (!audit_dummy_context())
520 __audit_ntp_log(ad);
521}
522
Al Viro471a5c72006-07-10 08:29:24 -0400523extern int audit_n_rules;
Amy Griffise54dc242007-03-29 18:01:04 -0400524extern int audit_signals;
Eric Parisd7e75282012-01-03 14:23:06 -0500525#else /* CONFIG_AUDITSYSCALL */
Kees Cook9321d522012-10-04 17:11:11 -0700526static inline int audit_alloc(struct task_struct *task)
527{
528 return 0;
529}
530static inline void audit_free(struct task_struct *task)
531{ }
Eric Paris91397402014-03-11 13:29:28 -0400532static inline void audit_syscall_entry(int major, unsigned long a0,
Kees Cook9321d522012-10-04 17:11:11 -0700533 unsigned long a1, unsigned long a2,
534 unsigned long a3)
535{ }
536static inline void audit_syscall_exit(void *pt_regs)
537{ }
Yaowei Bai36734812015-11-04 08:23:51 -0500538static inline bool audit_dummy_context(void)
Kees Cook9321d522012-10-04 17:11:11 -0700539{
Yaowei Bai36734812015-11-04 08:23:51 -0500540 return true;
Kees Cook9321d522012-10-04 17:11:11 -0700541}
Richard Guy Briggsc0b0ae82018-05-12 21:58:21 -0400542static inline void audit_set_context(struct task_struct *task, struct audit_context *ctx)
543{ }
Richard Guy Briggscdfb6b32018-05-12 21:58:20 -0400544static inline struct audit_context *audit_context(void)
545{
546 return NULL;
547}
Jeff Layton7ac86262012-10-10 15:25:28 -0400548static inline struct filename *audit_reusename(const __user char *name)
549{
550 return NULL;
551}
Jeff Layton91a27b22012-10-10 15:25:28 -0400552static inline void audit_getname(struct filename *name)
Kees Cook9321d522012-10-04 17:11:11 -0700553{ }
Jeff Laytonadb5c242012-10-10 16:43:13 -0400554static inline void __audit_inode(struct filename *name,
555 const struct dentry *dentry,
Jeff Layton79f65302013-07-08 15:59:36 -0700556 unsigned int flags)
Kees Cook9321d522012-10-04 17:11:11 -0700557{ }
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500558static inline void __audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400559 const struct dentry *dentry,
560 const unsigned char type)
Kees Cook9321d522012-10-04 17:11:11 -0700561{ }
Jeff Laytonadb5c242012-10-10 16:43:13 -0400562static inline void audit_inode(struct filename *name,
563 const struct dentry *dentry,
Jeff Laytonbfcec702012-10-10 15:25:23 -0400564 unsigned int parent)
Kees Cook9321d522012-10-04 17:11:11 -0700565{ }
Al Viro9f45f5b2014-10-31 17:44:57 -0400566static inline void audit_file(struct file *file)
567{
568}
Jeff Layton79f65302013-07-08 15:59:36 -0700569static inline void audit_inode_parent_hidden(struct filename *name,
570 const struct dentry *dentry)
571{ }
Andreas Gruenbacherd6335d72015-12-24 11:09:39 -0500572static inline void audit_inode_child(struct inode *parent,
Jeff Layton4fa6b5e2012-10-10 15:25:25 -0400573 const struct dentry *dentry,
574 const unsigned char type)
Kees Cook9321d522012-10-04 17:11:11 -0700575{ }
576static inline void audit_core_dumps(long signr)
577{ }
Kees Cook9321d522012-10-04 17:11:11 -0700578static inline void audit_seccomp(unsigned long syscall, long signr, int code)
579{ }
Tyler Hicksea6eca72018-05-04 01:08:14 +0000580static inline void audit_seccomp_actions_logged(const char *names,
581 const char *old_names, int res)
582{ }
Kees Cook9321d522012-10-04 17:11:11 -0700583static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
584{ }
585static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
586 gid_t gid, umode_t mode)
587{ }
Richard Guy Briggs9410d222013-10-30 18:05:24 -0400588static inline void audit_bprm(struct linux_binprm *bprm)
589{ }
Chen Gang2950fa92013-04-07 16:55:23 +0800590static inline int audit_socketcall(int nargs, unsigned long *args)
591{
592 return 0;
593}
Richard Guy Briggs62bc3062017-01-17 11:07:15 -0500594
595static inline int audit_socketcall_compat(int nargs, u32 *args)
596{
597 return 0;
598}
599
Kees Cook9321d522012-10-04 17:11:11 -0700600static inline void audit_fd_pair(int fd1, int fd2)
601{ }
602static inline int audit_sockaddr(int len, void *addr)
603{
604 return 0;
605}
606static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
607{ }
608static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
609 unsigned int msg_prio,
Deepa Dinamanib9047722017-08-02 19:51:11 -0700610 const struct timespec64 *abs_timeout)
Kees Cook9321d522012-10-04 17:11:11 -0700611{ }
612static inline void audit_mq_notify(mqd_t mqdes,
613 const struct sigevent *notification)
614{ }
615static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
616{ }
617static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
618 const struct cred *new,
619 const struct cred *old)
620{
621 return 0;
622}
Eric W. Biedermanca24a232013-03-19 00:02:25 -0700623static inline void audit_log_capset(const struct cred *new,
624 const struct cred *old)
Kees Cook9321d522012-10-04 17:11:11 -0700625{ }
626static inline void audit_mmap_fd(int fd, int flags)
627{ }
Richard Guy Briggsca86cad2017-02-04 13:10:38 -0500628
629static inline void audit_log_kern_module(char *name)
630{
631}
632
Steve Grubbde8cd832017-10-02 20:21:39 -0400633static inline void audit_fanotify(unsigned int response)
634{ }
635
Ondrej Mosnacek2d87a062019-04-10 11:14:19 +0200636static inline void audit_tk_injoffset(struct timespec64 offset)
637{ }
638
Ondrej Mosnacek7e8eda72019-04-10 11:14:20 +0200639static inline void audit_ntp_init(struct audit_ntp_data *ad)
640{ }
641
642static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
643 enum audit_ntp_type type, long long val)
644{ }
645
646static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
647 enum audit_ntp_type type, long long val)
648{ }
649
650static inline void audit_ntp_log(const struct audit_ntp_data *ad)
651{ }
652
Kees Cook9321d522012-10-04 17:11:11 -0700653static inline void audit_ptrace(struct task_struct *t)
654{ }
Al Viro471a5c72006-07-10 08:29:24 -0400655#define audit_n_rules 0
Amy Griffise54dc242007-03-29 18:01:04 -0400656#define audit_signals 0
Eric Parisd7e75282012-01-03 14:23:06 -0500657#endif /* CONFIG_AUDITSYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
Eric W. Biederman780a7652013-04-09 02:22:10 -0700659static inline bool audit_loginuid_set(struct task_struct *tsk)
660{
661 return uid_valid(audit_get_loginuid(tsk));
662}
663
Kees Cook9321d522012-10-04 17:11:11 -0700664static inline void audit_log_string(struct audit_buffer *ab, const char *buf)
665{
666 audit_log_n_string(ab, buf, strlen(buf));
667}
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669#endif