blob: 915330abf6e58fc2ecf494c498b7d266b0d56448 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Etienne Basset6e837fb2009-04-08 20:39:40 +02002/*
3 * Common LSM logging functions
4 * Heavily borrowed from selinux/avc.h
5 *
6 * Author : Etienne BASSET <etienne.basset@ensta.org>
7 *
Stephen Smalley5d728012017-08-17 13:32:37 -04008 * All credits to : Stephen Smalley, <sds@tycho.nsa.gov>
Etienne Basset6e837fb2009-04-08 20:39:40 +02009 * All BUGS to : Etienne BASSET <etienne.basset@ensta.org>
10 */
11#ifndef _LSM_COMMON_LOGGING_
12#define _LSM_COMMON_LOGGING_
13
14#include <linux/stddef.h>
15#include <linux/errno.h>
16#include <linux/kernel.h>
17#include <linux/kdev_t.h>
18#include <linux/spinlock.h>
19#include <linux/init.h>
20#include <linux/audit.h>
21#include <linux/in6.h>
22#include <linux/path.h>
23#include <linux/key.h>
24#include <linux/skbuff.h>
Daniel Jurgensab861df2017-05-19 15:48:58 +030025#include <rdma/ib_verbs.h>
Etienne Basset6e837fb2009-04-08 20:39:40 +020026
Eric Paris48c62af2012-04-02 13:15:44 -040027struct lsm_network_audit {
28 int netif;
29 struct sock *sk;
30 u16 family;
31 __be16 dport;
32 __be16 sport;
33 union {
34 struct {
35 __be32 daddr;
36 __be32 saddr;
37 } v4;
38 struct {
39 struct in6_addr daddr;
40 struct in6_addr saddr;
41 } v6;
42 } fam;
43};
Etienne Basset6e837fb2009-04-08 20:39:40 +020044
Jeff Vander Stoep671a2782015-07-10 17:19:55 -040045struct lsm_ioctlop_audit {
46 struct path path;
47 u16 cmd;
48};
49
Daniel Jurgenscfc4d882017-05-19 15:48:57 +030050struct lsm_ibpkey_audit {
51 u64 subnet_prefix;
52 u16 pkey;
53};
54
Daniel Jurgensab861df2017-05-19 15:48:58 +030055struct lsm_ibendport_audit {
56 char dev_name[IB_DEVICE_NAME_MAX];
57 u8 port;
58};
59
Etienne Basset6e837fb2009-04-08 20:39:40 +020060/* Auxiliary data to use in generating the audit record. */
61struct common_audit_data {
Eric Parisdd8dbf22009-11-03 16:35:32 +110062 char type;
Eric Parisf48b7392011-04-25 12:54:27 -040063#define LSM_AUDIT_DATA_PATH 1
Eric Parisdd8dbf22009-11-03 16:35:32 +110064#define LSM_AUDIT_DATA_NET 2
65#define LSM_AUDIT_DATA_CAP 3
66#define LSM_AUDIT_DATA_IPC 4
67#define LSM_AUDIT_DATA_TASK 5
68#define LSM_AUDIT_DATA_KEY 6
Eric Pariscb84aa92010-04-27 17:20:38 -040069#define LSM_AUDIT_DATA_NONE 7
Eric Parisdd8dbf22009-11-03 16:35:32 +110070#define LSM_AUDIT_DATA_KMOD 8
Eric Parisf48b7392011-04-25 12:54:27 -040071#define LSM_AUDIT_DATA_INODE 9
Eric Parisa2694342011-04-25 13:10:27 -040072#define LSM_AUDIT_DATA_DENTRY 10
Jeff Vander Stoep671a2782015-07-10 17:19:55 -040073#define LSM_AUDIT_DATA_IOCTL_OP 11
Vivek Goyal43af5de2016-09-09 11:37:49 -040074#define LSM_AUDIT_DATA_FILE 12
Daniel Jurgenscfc4d882017-05-19 15:48:57 +030075#define LSM_AUDIT_DATA_IBPKEY 13
Daniel Jurgensab861df2017-05-19 15:48:58 +030076#define LSM_AUDIT_DATA_IBENDPORT 14
Etienne Basset6e837fb2009-04-08 20:39:40 +020077 union {
Eric Parisf48b7392011-04-25 12:54:27 -040078 struct path path;
Eric Parisa2694342011-04-25 13:10:27 -040079 struct dentry *dentry;
Eric Parisf48b7392011-04-25 12:54:27 -040080 struct inode *inode;
Eric Paris48c62af2012-04-02 13:15:44 -040081 struct lsm_network_audit *net;
Etienne Basset6e837fb2009-04-08 20:39:40 +020082 int cap;
83 int ipc_id;
84 struct task_struct *tsk;
85#ifdef CONFIG_KEYS
86 struct {
87 key_serial_t key;
88 char *key_desc;
89 } key_struct;
90#endif
Eric Parisdd8dbf22009-11-03 16:35:32 +110091 char *kmod_name;
Jeff Vander Stoep671a2782015-07-10 17:19:55 -040092 struct lsm_ioctlop_audit *op;
Vivek Goyal43af5de2016-09-09 11:37:49 -040093 struct file *file;
Daniel Jurgenscfc4d882017-05-19 15:48:57 +030094 struct lsm_ibpkey_audit *ibpkey;
Daniel Jurgensab861df2017-05-19 15:48:58 +030095 struct lsm_ibendport_audit *ibendport;
Etienne Basset6e837fb2009-04-08 20:39:40 +020096 } u;
Etienne Basset6e837fb2009-04-08 20:39:40 +020097 /* this union contains LSM specific data */
98 union {
Thomas Liu65c3f0a2009-07-09 10:00:31 -040099#ifdef CONFIG_SECURITY_SMACK
Eric Paris3b3b0e42012-04-03 09:37:02 -0700100 struct smack_audit_data *smack_audit_data;
Thomas Liu65c3f0a2009-07-09 10:00:31 -0400101#endif
102#ifdef CONFIG_SECURITY_SELINUX
Eric Paris3b3b0e42012-04-03 09:37:02 -0700103 struct selinux_audit_data *selinux_audit_data;
Thomas Liu65c3f0a2009-07-09 10:00:31 -0400104#endif
John Johansen67012e82010-07-29 14:47:58 -0700105#ifdef CONFIG_SECURITY_APPARMOR
Eric Paris3b3b0e42012-04-03 09:37:02 -0700106 struct apparmor_audit_data *apparmor_audit_data;
John Johansen67012e82010-07-29 14:47:58 -0700107#endif
Eric Paris3b3b0e42012-04-03 09:37:02 -0700108 }; /* per LSM data pointer union */
Etienne Basset6e837fb2009-04-08 20:39:40 +0200109};
110
111#define v4info fam.v4
112#define v6info fam.v6
113
114int ipv4_skb_to_auditdata(struct sk_buff *skb,
115 struct common_audit_data *ad, u8 *proto);
116
117int ipv6_skb_to_auditdata(struct sk_buff *skb,
118 struct common_audit_data *ad, u8 *proto);
119
Linus Torvaldsb61c37f2012-04-02 15:48:12 -0700120void common_lsm_audit(struct common_audit_data *a,
121 void (*pre_audit)(struct audit_buffer *, void *),
122 void (*post_audit)(struct audit_buffer *, void *));
Etienne Basset6e837fb2009-04-08 20:39:40 +0200123
124#endif