0001
0002
0003
0004
0005
0006
0007 #ifndef _SELINUX_AVC_H_
0008 #define _SELINUX_AVC_H_
0009
0010 #include <linux/stddef.h>
0011 #include <linux/errno.h>
0012 #include <linux/kernel.h>
0013 #include <linux/kdev_t.h>
0014 #include <linux/spinlock.h>
0015 #include <linux/init.h>
0016 #include <linux/audit.h>
0017 #include <linux/lsm_audit.h>
0018 #include <linux/in6.h>
0019 #include "flask.h"
0020 #include "av_permissions.h"
0021 #include "security.h"
0022
0023
0024
0025
0026 struct avc_entry;
0027
0028 struct task_struct;
0029 struct inode;
0030 struct sock;
0031 struct sk_buff;
0032
0033
0034
0035
0036 struct avc_cache_stats {
0037 unsigned int lookups;
0038 unsigned int misses;
0039 unsigned int allocations;
0040 unsigned int reclaims;
0041 unsigned int frees;
0042 };
0043
0044
0045
0046
0047 struct selinux_audit_data {
0048 u32 ssid;
0049 u32 tsid;
0050 u16 tclass;
0051 u32 requested;
0052 u32 audited;
0053 u32 denied;
0054 int result;
0055 struct selinux_state *state;
0056 } __randomize_layout;
0057
0058
0059
0060
0061
0062 void __init avc_init(void);
0063
0064 static inline u32 avc_audit_required(u32 requested,
0065 struct av_decision *avd,
0066 int result,
0067 u32 auditdeny,
0068 u32 *deniedp)
0069 {
0070 u32 denied, audited;
0071 denied = requested & ~avd->allowed;
0072 if (unlikely(denied)) {
0073 audited = denied & avd->auditdeny;
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 if (auditdeny && !(auditdeny & avd->auditdeny))
0091 audited = 0;
0092 } else if (result)
0093 audited = denied = requested;
0094 else
0095 audited = requested & avd->auditallow;
0096 *deniedp = denied;
0097 return audited;
0098 }
0099
0100 int slow_avc_audit(struct selinux_state *state,
0101 u32 ssid, u32 tsid, u16 tclass,
0102 u32 requested, u32 audited, u32 denied, int result,
0103 struct common_audit_data *a);
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 static inline int avc_audit(struct selinux_state *state,
0126 u32 ssid, u32 tsid,
0127 u16 tclass, u32 requested,
0128 struct av_decision *avd,
0129 int result,
0130 struct common_audit_data *a)
0131 {
0132 u32 audited, denied;
0133 audited = avc_audit_required(requested, avd, result, 0, &denied);
0134 if (likely(!audited))
0135 return 0;
0136 return slow_avc_audit(state, ssid, tsid, tclass,
0137 requested, audited, denied, result,
0138 a);
0139 }
0140
0141 #define AVC_STRICT 1
0142 #define AVC_EXTENDED_PERMS 2
0143 int avc_has_perm_noaudit(struct selinux_state *state,
0144 u32 ssid, u32 tsid,
0145 u16 tclass, u32 requested,
0146 unsigned flags,
0147 struct av_decision *avd);
0148
0149 int avc_has_perm(struct selinux_state *state,
0150 u32 ssid, u32 tsid,
0151 u16 tclass, u32 requested,
0152 struct common_audit_data *auditdata);
0153
0154 int avc_has_extended_perms(struct selinux_state *state,
0155 u32 ssid, u32 tsid, u16 tclass, u32 requested,
0156 u8 driver, u8 perm, struct common_audit_data *ad);
0157
0158
0159 u32 avc_policy_seqno(struct selinux_state *state);
0160
0161 #define AVC_CALLBACK_GRANT 1
0162 #define AVC_CALLBACK_TRY_REVOKE 2
0163 #define AVC_CALLBACK_REVOKE 4
0164 #define AVC_CALLBACK_RESET 8
0165 #define AVC_CALLBACK_AUDITALLOW_ENABLE 16
0166 #define AVC_CALLBACK_AUDITALLOW_DISABLE 32
0167 #define AVC_CALLBACK_AUDITDENY_ENABLE 64
0168 #define AVC_CALLBACK_AUDITDENY_DISABLE 128
0169 #define AVC_CALLBACK_ADD_XPERMS 256
0170
0171 int avc_add_callback(int (*callback)(u32 event), u32 events);
0172
0173
0174 struct selinux_avc;
0175 int avc_get_hash_stats(struct selinux_avc *avc, char *page);
0176 unsigned int avc_get_cache_threshold(struct selinux_avc *avc);
0177 void avc_set_cache_threshold(struct selinux_avc *avc,
0178 unsigned int cache_threshold);
0179
0180
0181 void avc_disable(void);
0182
0183 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
0184 DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
0185 #endif
0186
0187 #endif
0188