lsm_audit.h 2.7 KB
Newer Older
E
Etienne Basset 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Common LSM logging functions
 * Heavily borrowed from selinux/avc.h
 *
 * Author : Etienne BASSET  <etienne.basset@ensta.org>
 *
 * All credits to : Stephen Smalley, <sds@epoch.ncsc.mil>
 * All BUGS to : Etienne BASSET  <etienne.basset@ensta.org>
 */
#ifndef _LSM_COMMON_LOGGING_
#define _LSM_COMMON_LOGGING_

#include <linux/stddef.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/kdev_t.h>
#include <linux/spinlock.h>
#include <linux/init.h>
#include <linux/audit.h>
#include <linux/in6.h>
#include <linux/path.h>
#include <linux/key.h>
#include <linux/skbuff.h>
24
#include <rdma/ib_verbs.h>
E
Etienne Basset 已提交
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
struct lsm_network_audit {
	int netif;
	struct sock *sk;
	u16 family;
	__be16 dport;
	__be16 sport;
	union {
		struct {
			__be32 daddr;
			__be32 saddr;
		} v4;
		struct {
			struct in6_addr daddr;
			struct in6_addr saddr;
		} v6;
	} fam;
};
E
Etienne Basset 已提交
43

44 45 46 47 48
struct lsm_ioctlop_audit {
	struct path path;
	u16 cmd;
};

49 50 51 52 53
struct lsm_ibpkey_audit {
	u64	subnet_prefix;
	u16	pkey;
};

54 55 56 57 58
struct lsm_ibendport_audit {
	char	dev_name[IB_DEVICE_NAME_MAX];
	u8	port;
};

E
Etienne Basset 已提交
59 60
/* Auxiliary data to use in generating the audit record. */
struct common_audit_data {
61
	char type;
62
#define LSM_AUDIT_DATA_PATH	1
63 64 65 66 67
#define LSM_AUDIT_DATA_NET	2
#define LSM_AUDIT_DATA_CAP	3
#define LSM_AUDIT_DATA_IPC	4
#define LSM_AUDIT_DATA_TASK	5
#define LSM_AUDIT_DATA_KEY	6
68
#define LSM_AUDIT_DATA_NONE	7
69
#define LSM_AUDIT_DATA_KMOD	8
70
#define LSM_AUDIT_DATA_INODE	9
71
#define LSM_AUDIT_DATA_DENTRY	10
72
#define LSM_AUDIT_DATA_IOCTL_OP	11
73
#define LSM_AUDIT_DATA_FILE	12
74
#define LSM_AUDIT_DATA_IBPKEY	13
75
#define LSM_AUDIT_DATA_IBENDPORT 14
E
Etienne Basset 已提交
76
	union 	{
77
		struct path path;
78
		struct dentry *dentry;
79
		struct inode *inode;
80
		struct lsm_network_audit *net;
E
Etienne Basset 已提交
81 82 83 84 85 86 87 88 89
		int cap;
		int ipc_id;
		struct task_struct *tsk;
#ifdef CONFIG_KEYS
		struct {
			key_serial_t key;
			char *key_desc;
		} key_struct;
#endif
90
		char *kmod_name;
91
		struct lsm_ioctlop_audit *op;
92
		struct file *file;
93
		struct lsm_ibpkey_audit *ibpkey;
94
		struct lsm_ibendport_audit *ibendport;
E
Etienne Basset 已提交
95 96 97
	} u;
	/* this union contains LSM specific data */
	union {
98
#ifdef CONFIG_SECURITY_SMACK
99
		struct smack_audit_data *smack_audit_data;
100 101
#endif
#ifdef CONFIG_SECURITY_SELINUX
102
		struct selinux_audit_data *selinux_audit_data;
103 104
#endif
#ifdef CONFIG_SECURITY_APPARMOR
105
		struct apparmor_audit_data *apparmor_audit_data;
106
#endif
107
	}; /* per LSM data pointer union */
E
Etienne Basset 已提交
108 109 110 111 112 113 114 115 116 117 118
};

#define v4info fam.v4
#define v6info fam.v6

int ipv4_skb_to_auditdata(struct sk_buff *skb,
		struct common_audit_data *ad, u8 *proto);

int ipv6_skb_to_auditdata(struct sk_buff *skb,
		struct common_audit_data *ad, u8 *proto);

119 120 121
void common_lsm_audit(struct common_audit_data *a,
	void (*pre_audit)(struct audit_buffer *, void *),
	void (*post_audit)(struct audit_buffer *, void *));
E
Etienne Basset 已提交
122 123

#endif