blob: 620e811696592ddec6fb221e2bec07d436f258b4 [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"
John Johansen637f6882017-06-09 08:14:28 -070025#include "label.h"
John Johansen67012e82010-07-29 14:47:58 -070026
Jan Engelhardt2d4cee72012-03-14 13:30:36 +010027extern const char *const audit_mode_names[];
John Johansen67012e82010-07-29 14:47:58 -070028#define AUDIT_MAX_INDEX 5
John Johansen67012e82010-07-29 14:47:58 -070029enum audit_mode {
30 AUDIT_NORMAL, /* follow normal auditing of accesses */
31 AUDIT_QUIET_DENIED, /* quiet all denied access messages */
32 AUDIT_QUIET, /* quiet all messages */
33 AUDIT_NOQUIET, /* do not quiet audit messages */
34 AUDIT_ALL /* audit all accesses */
35};
36
37enum audit_type {
38 AUDIT_APPARMOR_AUDIT,
39 AUDIT_APPARMOR_ALLOWED,
40 AUDIT_APPARMOR_DENIED,
41 AUDIT_APPARMOR_HINT,
42 AUDIT_APPARMOR_STATUS,
43 AUDIT_APPARMOR_ERROR,
John Johansenade3ddc2012-02-22 00:20:26 -080044 AUDIT_APPARMOR_KILL,
45 AUDIT_APPARMOR_AUTO
John Johansen67012e82010-07-29 14:47:58 -070046};
47
John Johansen47f6e5c2017-01-16 00:43:01 -080048#define OP_NULL NULL
John Johansen67012e82010-07-29 14:47:58 -070049
John Johansen47f6e5c2017-01-16 00:43:01 -080050#define OP_SYSCTL "sysctl"
51#define OP_CAPABLE "capable"
John Johansen67012e82010-07-29 14:47:58 -070052
John Johansen47f6e5c2017-01-16 00:43:01 -080053#define OP_UNLINK "unlink"
54#define OP_MKDIR "mkdir"
55#define OP_RMDIR "rmdir"
56#define OP_MKNOD "mknod"
57#define OP_TRUNC "truncate"
58#define OP_LINK "link"
59#define OP_SYMLINK "symlink"
60#define OP_RENAME_SRC "rename_src"
61#define OP_RENAME_DEST "rename_dest"
62#define OP_CHMOD "chmod"
63#define OP_CHOWN "chown"
64#define OP_GETATTR "getattr"
65#define OP_OPEN "open"
John Johansen67012e82010-07-29 14:47:58 -070066
John Johansen064dc942017-06-09 17:15:56 -070067#define OP_FRECEIVE "file_receive"
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 Johansen192ca6b2017-06-09 11:58:42 -070072#define OP_INHERIT "file_inherit"
John Johansen67012e82010-07-29 14:47:58 -070073
John Johansen2ea3ffb2017-07-18 23:04:47 -070074#define OP_PIVOTROOT "pivotroot"
75#define OP_MOUNT "mount"
76#define OP_UMOUNT "umount"
77
John Johansen47f6e5c2017-01-16 00:43:01 -080078#define OP_CREATE "create"
79#define OP_POST_CREATE "post_create"
80#define OP_BIND "bind"
81#define OP_CONNECT "connect"
82#define OP_LISTEN "listen"
83#define OP_ACCEPT "accept"
84#define OP_SENDMSG "sendmsg"
85#define OP_RECVMSG "recvmsg"
86#define OP_GETSOCKNAME "getsockname"
87#define OP_GETPEERNAME "getpeername"
88#define OP_GETSOCKOPT "getsockopt"
89#define OP_SETSOCKOPT "setsockopt"
90#define OP_SHUTDOWN "socket_shutdown"
John Johansen67012e82010-07-29 14:47:58 -070091
John Johansen47f6e5c2017-01-16 00:43:01 -080092#define OP_PTRACE "ptrace"
John Johansencd1dbf72017-07-18 22:56:22 -070093#define OP_SIGNAL "signal"
John Johansen67012e82010-07-29 14:47:58 -070094
John Johansen47f6e5c2017-01-16 00:43:01 -080095#define OP_EXEC "exec"
John Johansen67012e82010-07-29 14:47:58 -070096
John Johansen47f6e5c2017-01-16 00:43:01 -080097#define OP_CHANGE_HAT "change_hat"
98#define OP_CHANGE_PROFILE "change_profile"
99#define OP_CHANGE_ONEXEC "change_onexec"
John Johansen40cde7f2017-06-09 17:11:17 -0700100#define OP_STACK "stack"
101#define OP_STACK_ONEXEC "stack_onexec"
John Johansen67012e82010-07-29 14:47:58 -0700102
John Johansen47f6e5c2017-01-16 00:43:01 -0800103#define OP_SETPROCATTR "setprocattr"
104#define OP_SETRLIMIT "setrlimit"
105
106#define OP_PROF_REPL "profile_replace"
107#define OP_PROF_LOAD "profile_load"
108#define OP_PROF_RM "profile_remove"
John Johansen67012e82010-07-29 14:47:58 -0700109
110
Eric Paris3b3b0e42012-04-03 09:37:02 -0700111struct apparmor_audit_data {
112 int error;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700113 int type;
John Johansen637f6882017-06-09 08:14:28 -0700114 const char *op;
115 struct aa_label *label;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700116 const char *name;
117 const char *info;
John Johansenaa9aeea2017-05-29 12:16:04 -0700118 u32 request;
119 u32 denied;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700120 union {
John Johansenef88a7a2017-01-16 00:43:02 -0800121 /* these entries require a custom callback fn */
Eric Paris3b3b0e42012-04-03 09:37:02 -0700122 struct {
John Johansen637f6882017-06-09 08:14:28 -0700123 struct aa_label *peer;
Linus Torvalds80c094a2017-10-26 19:35:35 +0200124 struct {
125 const char *target;
126 kuid_t ouid;
127 } fs;
John Johansenef88a7a2017-01-16 00:43:02 -0800128 };
129 struct {
John Johansen2410aa92017-07-18 23:37:18 -0700130 struct aa_profile *profile;
John Johansenfc1c9fd2017-01-16 00:42:54 -0800131 const char *ns;
John Johansen2410aa92017-07-18 23:37:18 -0700132 long pos;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700133 } iface;
Linus Torvalds80c094a2017-10-26 19:35:35 +0200134 int signal;
135 struct {
136 int rlim;
137 unsigned long max;
138 } rlim;
John Johansen2ea3ffb2017-07-18 23:04:47 -0700139 struct {
140 const char *src_name;
141 const char *type;
142 const char *trans;
143 const char *data;
144 unsigned long flags;
145 } mnt;
Eric Paris3b3b0e42012-04-03 09:37:02 -0700146 };
147};
148
John Johansenef88a7a2017-01-16 00:43:02 -0800149/* macros for dealing with apparmor_audit_data structure */
150#define aad(SA) ((SA)->apparmor_audit_data)
151#define DEFINE_AUDIT_DATA(NAME, T, X) \
152 /* TODO: cleanup audit init so we don't need _aad = {0,} */ \
153 struct apparmor_audit_data NAME ## _aad = { .op = (X), }; \
154 struct common_audit_data NAME = \
155 { \
156 .type = (T), \
157 .u.tsk = NULL, \
158 }; \
159 NAME.apparmor_audit_data = &(NAME ## _aad)
John Johansen67012e82010-07-29 14:47:58 -0700160
161void aa_audit_msg(int type, struct common_audit_data *sa,
162 void (*cb) (struct audit_buffer *, void *));
John Johansenef88a7a2017-01-16 00:43:02 -0800163int aa_audit(int type, struct aa_profile *profile, struct common_audit_data *sa,
John Johansen67012e82010-07-29 14:47:58 -0700164 void (*cb) (struct audit_buffer *, void *));
165
John Johansenef88a7a2017-01-16 00:43:02 -0800166#define aa_audit_error(ERROR, SA, CB) \
167({ \
168 aad((SA))->error = (ERROR); \
169 aa_audit_msg(AUDIT_APPARMOR_ERROR, (SA), (CB)); \
170 aad((SA))->error; \
171})
172
173
John Johansen67012e82010-07-29 14:47:58 -0700174static inline int complain_error(int error)
175{
176 if (error == -EPERM || error == -EACCES)
177 return 0;
178 return error;
179}
180
181#endif /* __AA_AUDIT_H */