|
Chris PeBenito |
473ea7 |
/*
|
|
Chris PeBenito |
473ea7 |
* This file describes the internal interface used by the AVC
|
|
Chris PeBenito |
473ea7 |
* for calling the user-supplied memory allocation, supplemental
|
|
Chris PeBenito |
473ea7 |
* auditing, and locking routine, as well as incrementing the
|
|
Chris PeBenito |
473ea7 |
* statistics fields.
|
|
Chris PeBenito |
473ea7 |
*
|
|
Chris PeBenito |
473ea7 |
* Author : Eamon Walsh <ewalsh@epoch.ncsc.mil>
|
|
Chris PeBenito |
473ea7 |
*/
|
|
Chris PeBenito |
473ea7 |
#ifndef _SELINUX_AVC_INTERNAL_H_
|
|
Chris PeBenito |
473ea7 |
#define _SELINUX_AVC_INTERNAL_H_
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
#include <stdio.h>
|
|
Chris PeBenito |
473ea7 |
#include <stdlib.h>
|
|
Chris PeBenito |
473ea7 |
#include <string.h>
|
|
Chris PeBenito |
473ea7 |
#include <selinux/avc.h>
|
|
Chris PeBenito |
473ea7 |
#include "dso.h"
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
typedef u_int32_t u32;
|
|
Chris PeBenito |
473ea7 |
typedef u_int16_t u16;
|
|
Chris PeBenito |
473ea7 |
typedef u_int8_t u8;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* SID reference counter manipulation */
|
|
Chris PeBenito |
473ea7 |
static inline int sid_inc_refcnt(security_id_t sid) {
|
|
Chris PeBenito |
473ea7 |
return sid->refcnt = (sid->refcnt > 0) ? sid->refcnt+1 : 0;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline int sid_dec_refcnt(security_id_t sid) {
|
|
Chris PeBenito |
473ea7 |
return sid->refcnt = (sid->refcnt > 0) ? sid->refcnt-1 : 0;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* callback pointers */
|
|
Chris PeBenito |
473ea7 |
extern void *(*avc_func_malloc)(size_t) hidden;
|
|
Chris PeBenito |
473ea7 |
extern void (*avc_func_free)(void*) hidden;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
extern void (*avc_func_log)(const char*, ...) hidden;
|
|
Chris PeBenito |
473ea7 |
extern void (*avc_func_audit)(void*, security_class_t, char*, size_t) hidden;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
extern int avc_using_threads hidden;
|
|
Chris PeBenito |
473ea7 |
extern void *(*avc_func_create_thread)(void (*)(void)) hidden;
|
|
Chris PeBenito |
473ea7 |
extern void (*avc_func_stop_thread)(void*) hidden;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
extern void *(*avc_func_alloc_lock)(void) hidden;
|
|
Chris PeBenito |
473ea7 |
extern void (*avc_func_get_lock)(void*) hidden;
|
|
Chris PeBenito |
473ea7 |
extern void (*avc_func_release_lock)(void*) hidden;
|
|
Chris PeBenito |
473ea7 |
extern void (*avc_func_free_lock)(void*) hidden;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void set_callbacks(const struct avc_memory_callback *mem_cb,
|
|
Chris PeBenito |
473ea7 |
const struct avc_log_callback *log_cb,
|
|
Chris PeBenito |
473ea7 |
const struct avc_thread_callback *thread_cb,
|
|
Chris PeBenito |
473ea7 |
const struct avc_lock_callback *lock_cb)
|
|
Chris PeBenito |
473ea7 |
{
|
|
Chris PeBenito |
473ea7 |
if (mem_cb) {
|
|
Chris PeBenito |
473ea7 |
avc_func_malloc = mem_cb->func_malloc;
|
|
Chris PeBenito |
473ea7 |
avc_func_free = mem_cb->func_free;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
if (log_cb) {
|
|
Chris PeBenito |
473ea7 |
avc_func_log = log_cb->func_log;
|
|
Chris PeBenito |
473ea7 |
avc_func_audit = log_cb->func_audit;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
if (thread_cb) {
|
|
Chris PeBenito |
473ea7 |
avc_using_threads = 1;
|
|
Chris PeBenito |
473ea7 |
avc_func_create_thread = thread_cb->func_create_thread;
|
|
Chris PeBenito |
473ea7 |
avc_func_stop_thread = thread_cb->func_stop_thread;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
if (lock_cb) {
|
|
Chris PeBenito |
473ea7 |
avc_func_alloc_lock = lock_cb->func_alloc_lock;
|
|
Chris PeBenito |
473ea7 |
avc_func_get_lock = lock_cb->func_get_lock;
|
|
Chris PeBenito |
473ea7 |
avc_func_release_lock = lock_cb->func_release_lock;
|
|
Chris PeBenito |
473ea7 |
avc_func_free_lock = lock_cb->func_free_lock;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* message prefix and enforcing mode*/
|
|
Chris PeBenito |
473ea7 |
#define AVC_PREFIX_SIZE 16
|
|
Chris PeBenito |
473ea7 |
extern char avc_prefix[AVC_PREFIX_SIZE] hidden;
|
|
Chris PeBenito |
473ea7 |
extern int avc_enforcing hidden;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* user-supplied callback interface for avc */
|
|
Chris PeBenito |
473ea7 |
static inline void *avc_malloc(size_t size) {
|
|
Chris PeBenito |
473ea7 |
return avc_func_malloc ? avc_func_malloc(size) : malloc(size);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void avc_free(void *ptr) {
|
|
Chris PeBenito |
473ea7 |
if (avc_func_free)
|
|
Chris PeBenito |
473ea7 |
avc_func_free(ptr);
|
|
Chris PeBenito |
473ea7 |
else
|
|
Chris PeBenito |
473ea7 |
free(ptr);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* this is a macro in order to use the variadic capability. */
|
|
Chris PeBenito |
473ea7 |
#define avc_log(format...) \
|
|
Chris PeBenito |
473ea7 |
if (avc_func_log) \
|
|
Chris PeBenito |
473ea7 |
avc_func_log(format); \
|
|
Chris PeBenito |
473ea7 |
else \
|
|
Chris PeBenito |
473ea7 |
fprintf(stderr, format)
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void avc_suppl_audit(void *ptr, security_class_t class,
|
|
Chris PeBenito |
473ea7 |
char *buf, size_t len) {
|
|
Chris PeBenito |
473ea7 |
if (avc_func_audit)
|
|
Chris PeBenito |
473ea7 |
avc_func_audit(ptr, class, buf, len);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void* avc_create_thread(void (*run)(void)) {
|
|
Chris PeBenito |
473ea7 |
return avc_func_create_thread ?
|
|
Chris PeBenito |
473ea7 |
avc_func_create_thread(run) : NULL;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void avc_stop_thread(void *thread) {
|
|
Chris PeBenito |
473ea7 |
if (avc_func_stop_thread)
|
|
Chris PeBenito |
473ea7 |
avc_func_stop_thread(thread);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void* avc_alloc_lock(void) {
|
|
Chris PeBenito |
473ea7 |
return avc_func_alloc_lock ? avc_func_alloc_lock() : NULL;
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void avc_get_lock(void *lock) {
|
|
Chris PeBenito |
473ea7 |
if (avc_func_get_lock)
|
|
Chris PeBenito |
473ea7 |
avc_func_get_lock(lock);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void avc_release_lock(void *lock) {
|
|
Chris PeBenito |
473ea7 |
if (avc_func_release_lock)
|
|
Chris PeBenito |
473ea7 |
avc_func_release_lock(lock);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
static inline void avc_free_lock(void *lock) {
|
|
Chris PeBenito |
473ea7 |
if (avc_func_free_lock)
|
|
Chris PeBenito |
473ea7 |
avc_func_free_lock(lock);
|
|
Chris PeBenito |
473ea7 |
}
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* statistics helper routines */
|
|
Chris PeBenito |
473ea7 |
#ifdef AVC_CACHE_STATS
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
#define avc_cache_stats_incr(field) \
|
|
Chris PeBenito |
473ea7 |
cache_stats.field ++;
|
|
Chris PeBenito |
473ea7 |
#define avc_cache_stats_add(field, num) \
|
|
Chris PeBenito |
473ea7 |
cache_stats.field += num;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
#else
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
#define avc_cache_stats_incr(field)
|
|
Chris PeBenito |
473ea7 |
#define avc_cache_stats_add(field, num)
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
#endif
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* logging helper routines */
|
|
Chris PeBenito |
473ea7 |
#define AVC_AUDIT_BUFSIZE 1024
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* again, we need the variadic capability here */
|
|
Chris PeBenito |
473ea7 |
#define log_append(buf,format...) \
|
|
Chris PeBenito |
473ea7 |
snprintf(buf+strlen(buf), AVC_AUDIT_BUFSIZE-strlen(buf), format)
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* internal callbacks */
|
|
Chris PeBenito |
473ea7 |
int avc_ss_grant(security_id_t ssid, security_id_t tsid,
|
|
Chris PeBenito |
473ea7 |
security_class_t tclass, access_vector_t perms,
|
|
Chris PeBenito |
473ea7 |
u_int32_t seqno) hidden;
|
|
Chris PeBenito |
473ea7 |
int avc_ss_try_revoke(security_id_t ssid, security_id_t tsid,
|
|
Chris PeBenito |
473ea7 |
security_class_t tclass,
|
|
Chris PeBenito |
473ea7 |
access_vector_t perms, u_int32_t seqno,
|
|
Chris PeBenito |
473ea7 |
access_vector_t *out_retained) hidden;
|
|
Chris PeBenito |
473ea7 |
int avc_ss_revoke(security_id_t ssid, security_id_t tsid,
|
|
Chris PeBenito |
473ea7 |
security_class_t tclass, access_vector_t perms,
|
|
Chris PeBenito |
473ea7 |
u_int32_t seqno) hidden;
|
|
Chris PeBenito |
473ea7 |
int avc_ss_reset(u_int32_t seqno) hidden;
|
|
Chris PeBenito |
473ea7 |
int avc_ss_set_auditallow(security_id_t ssid, security_id_t tsid,
|
|
Chris PeBenito |
473ea7 |
security_class_t tclass, access_vector_t perms,
|
|
Chris PeBenito |
473ea7 |
u_int32_t seqno, u_int32_t enable) hidden;
|
|
Chris PeBenito |
473ea7 |
int avc_ss_set_auditdeny(security_id_t ssid, security_id_t tsid,
|
|
Chris PeBenito |
473ea7 |
security_class_t tclass, access_vector_t perms,
|
|
Chris PeBenito |
473ea7 |
u_int32_t seqno, u_int32_t enable) hidden;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
/* netlink kernel message code */
|
|
Chris PeBenito |
473ea7 |
extern int avc_netlink_trouble hidden;
|
|
Chris PeBenito |
473ea7 |
int avc_netlink_open(int blocking) hidden;
|
|
Chris PeBenito |
473ea7 |
int avc_netlink_check_nb(void) hidden;
|
|
Chris PeBenito |
473ea7 |
void avc_netlink_loop(void) hidden;
|
|
Chris PeBenito |
473ea7 |
void avc_netlink_close(void) hidden;
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
hidden_proto(avc_av_stats)
|
|
Chris PeBenito |
473ea7 |
hidden_proto(avc_cleanup)
|
|
Chris PeBenito |
473ea7 |
hidden_proto(avc_reset)
|
|
Chris PeBenito |
473ea7 |
hidden_proto(avc_audit)
|
|
Chris PeBenito |
473ea7 |
hidden_proto(avc_has_perm_noaudit)
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
#endif /* _SELINUX_AVC_INTERNAL_H_ */
|