blob: 956c0b16a30f3fb3fdfcdb2ccb704d6168626c7e [file] [log] [blame]
John Johansen67012e82010-07-29 14:47:58 -07001/*
2 * AppArmor security module
3 *
4 * This file contains AppArmor auditing function definitions.
5 *
6 * Copyright (C) 1998-2008 Novell/SUSE
7 * Copyright 2009-2010 Canonical Ltd.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2 of the
12 * License.
13 */
14
15#ifndef __AA_AUDIT_H
16#define __AA_AUDIT_H
17
18#include <linux/audit.h>
19#include <linux/fs.h>
20#include <linux/lsm_audit.h>
21#include <linux/sched.h>
22#include <linux/slab.h>
23
24#include "file.h"
25
26struct aa_profile;
27
Jan Engelhardt2d4cee72012-03-14 13:30:36 +010028extern const char *const audit_mode_names[];
John Johansen67012e82010-07-29 14:47:58 -070029#define AUDIT_MAX_INDEX 5
John Johansen67012e82010-07-29 14:47:58 -070030enum audit_mode {
31 AUDIT_NORMAL, /* follow normal auditing of accesses */
32 AUDIT_QUIET_DENIED, /* quiet all denied access messages */
33 AUDIT_QUIET, /* quiet all messages */
34 AUDIT_NOQUIET, /* do not quiet audit messages */
35 AUDIT_ALL /* audit all accesses */
36};
37
38enum audit_type {
39 AUDIT_APPARMOR_AUDIT,
40 AUDIT_APPARMOR_ALLOWED,
41 AUDIT_APPARMOR_DENIED,
42 AUDIT_APPARMOR_HINT,
43 AUDIT_APPARMOR_STATUS,
44 AUDIT_APPARMOR_ERROR,
John Johansenade3ddc2012-02-22 00:20:26 -080045 AUDIT_APPARMOR_KILL,
46 AUDIT_APPARMOR_AUTO
John Johansen67012e82010-07-29 14:47:58 -070047};
48
John Johansen47f6e5c2017-01-16 00:43:01 -080049#define OP_NULL NULL
John Johansen67012e82010-07-29 14:47:58 -070050
John Johansen47f6e5c2017-01-16 00:43:01 -080051#define OP_SYSCTL "sysctl"
52#define OP_CAPABLE "capable"
John Johansen67012e82010-07-29 14:47:58 -070053
John Johansen47f6e5c2017-01-16 00:43:01 -080054#define OP_UNLINK "unlink"
55#define OP_MKDIR "mkdir"
56#define OP_RMDIR "rmdir"
57#define OP_MKNOD "mknod"
58#define OP_TRUNC "truncate"
59#define OP_LINK "link"
60#define OP_SYMLINK "symlink"
61#define OP_RENAME_SRC "rename_src"
62#define OP_RENAME_DEST "rename_dest"
63#define OP_CHMOD "chmod"
64#define OP_CHOWN "chown"
65#define OP_GETATTR "getattr"
66#define OP_OPEN "open"
John Johansen67012e82010-07-29 14:47:58 -070067
John Johansen47f6e5c2017-01-16 00:43:01 -080068#define OP_FPERM "file_perm"
69#define OP_FLOCK "file_lock"
70#define OP_FMMAP "file_mmap"
71#define OP_FMPROT "file_mprotect"
John Johansen67012e82010-07-29 14:47:58 -070072
John Johansen47f6e5c2017-01-16 00:43:01 -080073#define OP_CREATE "create"
74#define OP_POST_CREATE "post_create"
75#define OP_BIND "bind"
76#define OP_CONNECT "connect"
77#define OP_LISTEN "listen"
78#define OP_ACCEPT "accept"
79#define OP_SENDMSG "sendmsg"
80#define OP_RECVMSG "recvmsg"
81#define OP_GETSOCKNAME "getsockname"
82#define OP_GETPEERNAME "getpeername"
83#define OP_GETSOCKOPT "getsockopt"
84#define OP_SETSOCKOPT "setsockopt"
85#define OP_SHUTDOWN "socket_shutdown"
John Johansen67012e82010-07-29 14:47:58 -070086
John Johansen47f6e5c2017-01-16 00:43:01 -080087#define OP_PTRACE "ptrace"
John Johansen67012e82010-07-29 14:47:58 -070088
John Johansen47f6e5c2017-01-16 00:43:01 -080089#define OP_EXEC "exec"
John Johansen67012e82010-07-29 14:47:58 -070090
John Johansen47f6e5c2017-01-16 00:43:01 -080091#define OP_CHANGE_HAT "change_hat"
92#define OP_CHANGE_PROFILE "change_profile"
93#define OP_CHANGE_ONEXEC "change_onexec"
John Johansen67012e82010-07-29 14:47:58 -070094
John Johansen47f6e5c2017-01-16 00:43:01 -080095#define OP_SETPROCATTR "setprocattr"
96#define OP_SETRLIMIT "setrlimit"
97
98#define OP_PROF_REPL "profile_replace"
99#define OP_PROF_LOAD "profile_load"
100#define OP_PROF_RM "profile_remove"
John Johansen67012e82010-07-29 14:47:58 -0700101
102
Eric Paris3b3b0e42012-04-03 09:37:02 -0700103struct apparmor_audit_data {
104 int error;
John Johansen47f6e5c2017-01-16 00:43:01 -0800105 const char *op;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700106 int type;
107 void *profile;
108 const char *name;
109 const char *info;
110 union {
111 void *target;
112 struct {
113 long pos;
John Johansenfc1c9fd2017-01-16 00:42:54 -0800114 const char *ns;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700115 void *target;
116 } iface;
117 struct {
118 int rlim;
119 unsigned long max;
120 } rlim;
121 struct {
122 const char *target;
123 u32 request;
124 u32 denied;
Eric W. Biederman2db81452012-02-07 16:33:13 -0800125 kuid_t ouid;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700126 } fs;
127 };
128};
129
130/* define a short hand for apparmor_audit_data structure */
John Johansen67012e82010-07-29 14:47:58 -0700131#define aad apparmor_audit_data
132
133void aa_audit_msg(int type, struct common_audit_data *sa,
134 void (*cb) (struct audit_buffer *, void *));
135int aa_audit(int type, struct aa_profile *profile, gfp_t gfp,
136 struct common_audit_data *sa,
137 void (*cb) (struct audit_buffer *, void *));
138
139static inline int complain_error(int error)
140{
141 if (error == -EPERM || error == -EACCES)
142 return 0;
143 return error;
144}
145
146#endif /* __AA_AUDIT_H */