blob: bbaceab83a654e804e7b2bd1dcc4f4f232c605ea [file] [log] [blame]
Etienne Basset6e837fb2009-04-08 20:39:40 +02001/*
2 * Common LSM logging functions
3 * Heavily borrowed from selinux/avc.h
4 *
5 * Author : Etienne BASSET <etienne.basset@ensta.org>
6 *
7 * All credits to : Stephen Smalley, <sds@epoch.ncsc.mil>
8 * All BUGS to : Etienne BASSET <etienne.basset@ensta.org>
9 */
10#ifndef _LSM_COMMON_LOGGING_
11#define _LSM_COMMON_LOGGING_
12
13#include <linux/stddef.h>
14#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <linux/kdev_t.h>
17#include <linux/spinlock.h>
18#include <linux/init.h>
19#include <linux/audit.h>
20#include <linux/in6.h>
21#include <linux/path.h>
22#include <linux/key.h>
23#include <linux/skbuff.h>
24#include <asm/system.h>
25
26
27/* Auxiliary data to use in generating the audit record. */
28struct common_audit_data {
Eric Parisdd8dbf22009-11-03 16:35:32 +110029 char type;
Eric Parisf48b7392011-04-25 12:54:27 -040030#define LSM_AUDIT_DATA_PATH 1
Eric Parisdd8dbf22009-11-03 16:35:32 +110031#define LSM_AUDIT_DATA_NET 2
32#define LSM_AUDIT_DATA_CAP 3
33#define LSM_AUDIT_DATA_IPC 4
34#define LSM_AUDIT_DATA_TASK 5
35#define LSM_AUDIT_DATA_KEY 6
Eric Pariscb84aa92010-04-27 17:20:38 -040036#define LSM_AUDIT_DATA_NONE 7
Eric Parisdd8dbf22009-11-03 16:35:32 +110037#define LSM_AUDIT_DATA_KMOD 8
Eric Parisf48b7392011-04-25 12:54:27 -040038#define LSM_AUDIT_DATA_INODE 9
Etienne Basset6e837fb2009-04-08 20:39:40 +020039 struct task_struct *tsk;
40 union {
Eric Parisf48b7392011-04-25 12:54:27 -040041 struct path path;
42 struct inode *inode;
Etienne Basset6e837fb2009-04-08 20:39:40 +020043 struct {
44 int netif;
45 struct sock *sk;
46 u16 family;
47 __be16 dport;
48 __be16 sport;
49 union {
50 struct {
51 __be32 daddr;
52 __be32 saddr;
53 } v4;
54 struct {
55 struct in6_addr daddr;
56 struct in6_addr saddr;
57 } v6;
58 } fam;
59 } net;
60 int cap;
61 int ipc_id;
62 struct task_struct *tsk;
63#ifdef CONFIG_KEYS
64 struct {
65 key_serial_t key;
66 char *key_desc;
67 } key_struct;
68#endif
Eric Parisdd8dbf22009-11-03 16:35:32 +110069 char *kmod_name;
Etienne Basset6e837fb2009-04-08 20:39:40 +020070 } u;
Etienne Basset6e837fb2009-04-08 20:39:40 +020071 /* this union contains LSM specific data */
72 union {
Thomas Liu65c3f0a2009-07-09 10:00:31 -040073#ifdef CONFIG_SECURITY_SMACK
Etienne Basset6e837fb2009-04-08 20:39:40 +020074 /* SMACK data */
75 struct smack_audit_data {
Thomas Liued5215a2009-07-09 10:00:29 -040076 const char *function;
Etienne Basset6e837fb2009-04-08 20:39:40 +020077 char *subject;
78 char *object;
79 char *request;
80 int result;
81 } smack_audit_data;
Thomas Liu65c3f0a2009-07-09 10:00:31 -040082#endif
83#ifdef CONFIG_SECURITY_SELINUX
Etienne Basset6e837fb2009-04-08 20:39:40 +020084 /* SELinux data */
85 struct {
86 u32 ssid;
87 u32 tsid;
88 u16 tclass;
89 u32 requested;
90 u32 audited;
Thomas Liu2bf49692009-07-14 12:14:09 -040091 u32 denied;
Eric Parisb782e0a2010-07-23 11:44:03 -040092 /*
93 * auditdeny is a bit tricky and unintuitive. See the
94 * comments in avc.c for it's meaning and usage.
95 */
96 u32 auditdeny;
Etienne Basset6e837fb2009-04-08 20:39:40 +020097 struct av_decision *avd;
98 int result;
99 } selinux_audit_data;
Thomas Liu65c3f0a2009-07-09 10:00:31 -0400100#endif
John Johansen67012e82010-07-29 14:47:58 -0700101#ifdef CONFIG_SECURITY_APPARMOR
102 struct {
103 int error;
104 int op;
105 int type;
106 void *profile;
107 const char *name;
108 const char *info;
109 union {
110 void *target;
111 struct {
112 long pos;
113 void *target;
114 } iface;
115 struct {
116 int rlim;
117 unsigned long max;
118 } rlim;
119 struct {
120 const char *target;
121 u32 request;
122 u32 denied;
123 uid_t ouid;
124 } fs;
125 };
126 } apparmor_audit_data;
127#endif
Thomas Liud4131de2009-07-09 10:00:30 -0400128 };
Etienne Basset6e837fb2009-04-08 20:39:40 +0200129 /* these callback will be implemented by a specific LSM */
130 void (*lsm_pre_audit)(struct audit_buffer *, void *);
131 void (*lsm_post_audit)(struct audit_buffer *, void *);
132};
133
134#define v4info fam.v4
135#define v6info fam.v6
136
137int ipv4_skb_to_auditdata(struct sk_buff *skb,
138 struct common_audit_data *ad, u8 *proto);
139
140int ipv6_skb_to_auditdata(struct sk_buff *skb,
141 struct common_audit_data *ad, u8 *proto);
142
143/* Initialize an LSM audit data structure. */
144#define COMMON_AUDIT_DATA_INIT(_d, _t) \
145 { memset((_d), 0, sizeof(struct common_audit_data)); \
Thomas Liued5215a2009-07-09 10:00:29 -0400146 (_d)->type = LSM_AUDIT_DATA_##_t; }
Etienne Basset6e837fb2009-04-08 20:39:40 +0200147
148void common_lsm_audit(struct common_audit_data *a);
149
150#endif