|
Chris PeBenito |
473ea7 |
.\" Hey Emacs! This file is -*- nroff -*- source.
|
|
Chris PeBenito |
473ea7 |
.\"
|
|
Chris PeBenito |
473ea7 |
.\" Author: Eamon Walsh (ewalsh@epoch.ncsc.mil) 2004
|
|
Chris PeBenito |
473ea7 |
.TH "avc_init" "3" "27 May 2004" "" "SE Linux API documentation"
|
|
Chris PeBenito |
473ea7 |
.SH "NAME"
|
|
Chris PeBenito |
473ea7 |
avc_init, avc_destroy, avc_reset, avc_cleanup \- userspace AVC setup and teardown.
|
|
Chris PeBenito |
473ea7 |
.SH "SYNOPSIS"
|
|
Chris PeBenito |
473ea7 |
.B #include <selinux/selinux.h>
|
|
Chris PeBenito |
473ea7 |
.br
|
|
Chris PeBenito |
473ea7 |
.B #include <selinux/avc.h>
|
|
Chris PeBenito |
473ea7 |
.sp
|
|
Chris PeBenito |
473ea7 |
.BI "int avc_init(const char *" msgprefix ,
|
|
Chris PeBenito |
473ea7 |
.in +\w'int avc_init('u
|
|
Chris PeBenito |
473ea7 |
.BI "const struct avc_memory_callback *" mem_callbacks ,
|
|
Chris PeBenito |
473ea7 |
.br
|
|
Chris PeBenito |
473ea7 |
.BI "const struct avc_log_callback *" log_callbacks ,
|
|
Chris PeBenito |
473ea7 |
.br
|
|
Chris PeBenito |
473ea7 |
.BI "const struct avc_thread_callback *" thread_callbacks ,
|
|
Chris PeBenito |
473ea7 |
.br
|
|
Chris PeBenito |
473ea7 |
.BI "const struct avc_lock_callback *" lock_callbacks ");"
|
|
Chris PeBenito |
473ea7 |
.in
|
|
Chris PeBenito |
473ea7 |
.sp
|
|
Chris PeBenito |
473ea7 |
.BI "void avc_destroy(void);"
|
|
Chris PeBenito |
473ea7 |
.sp
|
|
Chris PeBenito |
473ea7 |
.BI "int avc_reset(void);"
|
|
Chris PeBenito |
473ea7 |
.sp
|
|
Chris PeBenito |
473ea7 |
.BI "void avc_cleanup(void);"
|
|
Chris PeBenito |
473ea7 |
.SH "DESCRIPTION"
|
|
Chris PeBenito |
473ea7 |
.B avc_init
|
|
Chris PeBenito |
473ea7 |
initializes the userspace AVC and must be called before any other AVC operation can be performed. A non-NULL
|
|
Chris PeBenito |
473ea7 |
.I msgprefix
|
|
Chris PeBenito |
473ea7 |
will be prepended to all audit messages produced by the userspace AVC. The default is `uavc'. The remaining arguments, if non-NULL, specify callbacks to be used by the userspace AVC. See
|
|
Chris PeBenito |
473ea7 |
.B CALLBACKS
|
|
Chris PeBenito |
473ea7 |
below.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.B avc_destroy
|
|
Chris PeBenito |
473ea7 |
destroys the userspace AVC, freeing all internal memory structures. After this call has been made,
|
|
Chris PeBenito |
473ea7 |
.B avc_init
|
|
Chris PeBenito |
473ea7 |
must be called again before any AVC operations can be performed.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.B avc_reset
|
|
Chris PeBenito |
473ea7 |
flushes the userspace AVC, causing it to forget any cached access decisions. The userspace AVC normally calls this function automatically when needed, see
|
|
Chris PeBenito |
473ea7 |
.B NETLINK NOTIFICATION
|
|
Chris PeBenito |
473ea7 |
below.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.B avc_cleanup
|
|
Chris PeBenito |
473ea7 |
forces the userspace AVC to search for and free all unused SID's and any access decision entries that refer to them. Normally, the userspace AVC lazily reclaims unused SID's.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.SH "CALLBACKS"
|
|
Chris PeBenito |
473ea7 |
The userspace AVC can be directed how to perform memory allocation, logging, thread creation, and locking via callback functions passed to
|
|
Chris PeBenito |
473ea7 |
.BR avc_init .
|
|
Chris PeBenito |
473ea7 |
The purpose of this functionality is to allow the userspace AVC to be smoothly integrated into existing userspace object managers.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
Use an
|
|
Chris PeBenito |
473ea7 |
.B avc_memory_callback
|
|
Chris PeBenito |
473ea7 |
structure to specify alternate functions for dynamic memory allocation.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.RS
|
|
Chris PeBenito |
473ea7 |
.ta 4n 10n 24n
|
|
Chris PeBenito |
473ea7 |
.nf
|
|
Chris PeBenito |
473ea7 |
struct avc_memory_callback {
|
|
Chris PeBenito |
473ea7 |
void *(*func_malloc)(size_t size);
|
|
Chris PeBenito |
473ea7 |
void (*func_free)(void *ptr);
|
|
Chris PeBenito |
473ea7 |
};
|
|
Chris PeBenito |
473ea7 |
.fi
|
|
Chris PeBenito |
473ea7 |
.ta
|
|
Chris PeBenito |
473ea7 |
.RE
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
The two fields of the structure should be pointers to functions which behave as
|
|
Chris PeBenito |
473ea7 |
.BR malloc (3)
|
|
Chris PeBenito |
473ea7 |
and
|
|
Chris PeBenito |
473ea7 |
.BR free (3),
|
|
Chris PeBenito |
473ea7 |
which are used by default.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
Use an
|
|
Chris PeBenito |
473ea7 |
.B avc_log_callback
|
|
Chris PeBenito |
473ea7 |
structure to specify alternate functions for logging.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.RS
|
|
Chris PeBenito |
473ea7 |
.ta 4n 10n 24n
|
|
Chris PeBenito |
473ea7 |
.nf
|
|
Chris PeBenito |
473ea7 |
struct avc_log_callback {
|
|
Chris PeBenito |
473ea7 |
void (*func_log)(const char *fmt, ...);
|
|
Chris PeBenito |
473ea7 |
void (*func_audit)(void *auditdata,
|
|
Chris PeBenito |
473ea7 |
security_class_t class,
|
|
Chris PeBenito |
473ea7 |
char *msgbuf, size_t msgbufsize);
|
|
Chris PeBenito |
473ea7 |
};
|
|
Chris PeBenito |
473ea7 |
.fi
|
|
Chris PeBenito |
473ea7 |
.ta
|
|
Chris PeBenito |
473ea7 |
.RE
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
The
|
|
Chris PeBenito |
473ea7 |
.B func_log
|
|
Chris PeBenito |
473ea7 |
callback should accept a
|
|
Chris PeBenito |
473ea7 |
.BR printf (3)
|
|
Chris PeBenito |
473ea7 |
style format and arguments and log them as desired. The default behavior prints the message on the standard error. The
|
|
Chris PeBenito |
473ea7 |
.B func_audit
|
|
Chris PeBenito |
473ea7 |
callback should interpret the
|
|
Chris PeBenito |
473ea7 |
.I auditdata
|
|
Chris PeBenito |
473ea7 |
parameter for the given
|
|
Chris PeBenito |
473ea7 |
.IR class ,
|
|
Chris PeBenito |
473ea7 |
printing a human-readable interpretation to
|
|
Chris PeBenito |
473ea7 |
.I msgbuf
|
|
Chris PeBenito |
473ea7 |
using no more than
|
|
Chris PeBenito |
473ea7 |
.I msgbufsize
|
|
Chris PeBenito |
473ea7 |
characters. The default behavior is to ignore
|
|
Chris PeBenito |
473ea7 |
.IR auditdata .
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
Use an
|
|
Chris PeBenito |
473ea7 |
.B avc_thread_callback
|
|
Chris PeBenito |
473ea7 |
structure to specify functions for starting and manipulating threads.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.RS
|
|
Chris PeBenito |
473ea7 |
.ta 4n 10n 24n
|
|
Chris PeBenito |
473ea7 |
.nf
|
|
Chris PeBenito |
473ea7 |
struct avc_thread_callback {
|
|
Chris PeBenito |
473ea7 |
void *(*func_create_thread)(void (*run)(void));
|
|
Chris PeBenito |
473ea7 |
void (*func_stop_thread)(void *thread);
|
|
Chris PeBenito |
473ea7 |
};
|
|
Chris PeBenito |
473ea7 |
.fi
|
|
Chris PeBenito |
473ea7 |
.ta
|
|
Chris PeBenito |
473ea7 |
.RE
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
The
|
|
Chris PeBenito |
473ea7 |
.B func_create_thread
|
|
Chris PeBenito |
473ea7 |
callback should create a new thread and return a pointer which references it. The thread should execute the
|
|
Chris PeBenito |
473ea7 |
.I run
|
|
Chris PeBenito |
473ea7 |
argument, which does not return under normal conditions. The
|
|
Chris PeBenito |
473ea7 |
.B func_stop_thread
|
|
Chris PeBenito |
473ea7 |
callback should cancel the running thread referenced by
|
|
Chris PeBenito |
473ea7 |
.IR thread .
|
|
Chris PeBenito |
473ea7 |
By default, threading is not used; see
|
|
Chris PeBenito |
473ea7 |
.B NETLINK NOTIFICATION
|
|
Chris PeBenito |
473ea7 |
below.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
Use an
|
|
Chris PeBenito |
473ea7 |
.B avc_lock_callback
|
|
Chris PeBenito |
473ea7 |
structure to specify functions to create, obtain, and release locks for use by threads.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.RS
|
|
Chris PeBenito |
473ea7 |
.ta 4n 10n 24n
|
|
Chris PeBenito |
473ea7 |
.nf
|
|
Chris PeBenito |
473ea7 |
struct avc_lock_callback {
|
|
Chris PeBenito |
473ea7 |
void *(*func_alloc_lock)(void);
|
|
Chris PeBenito |
473ea7 |
void (*func_get_lock)(void *lock);
|
|
Chris PeBenito |
473ea7 |
void (*func_release_lock)(void *lock);
|
|
Chris PeBenito |
473ea7 |
void (*func_free_lock)(void *lock);
|
|
Chris PeBenito |
473ea7 |
};
|
|
Chris PeBenito |
473ea7 |
.fi
|
|
Chris PeBenito |
473ea7 |
.ta
|
|
Chris PeBenito |
473ea7 |
.RE
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
The
|
|
Chris PeBenito |
473ea7 |
.B func_alloc_lock
|
|
Chris PeBenito |
473ea7 |
callback should create a new lock, returning a pointer which references it. The
|
|
Chris PeBenito |
473ea7 |
.B func_get_lock
|
|
Chris PeBenito |
473ea7 |
callback should obtain
|
|
Chris PeBenito |
473ea7 |
.IR lock ,
|
|
Chris PeBenito |
473ea7 |
blocking if necessary. The
|
|
Chris PeBenito |
473ea7 |
.B func_release_lock
|
|
Chris PeBenito |
473ea7 |
callback should release
|
|
Chris PeBenito |
473ea7 |
.IR lock .
|
|
Chris PeBenito |
473ea7 |
The
|
|
Chris PeBenito |
473ea7 |
.B func_free_lock
|
|
Chris PeBenito |
473ea7 |
callback should destroy
|
|
Chris PeBenito |
473ea7 |
.IR lock ,
|
|
Chris PeBenito |
473ea7 |
freeing any resources associated with it. The default behavior is not to perform any locking. Note that undefined behavior may result if threading is used without appropriate locking.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.SH "NETLINK NOTIFICATION"
|
|
Chris PeBenito |
473ea7 |
Beginning with version 2.6.4, the Linux kernel supports SELinux status change notification via netlink. Two message types are currently implemented, indicating changes to the enforcing mode and to the loaded policy in the kernel, respectively. The userspace AVC listens for these messages and takes the appropriate action, modifying the behavior of
|
|
Chris PeBenito |
473ea7 |
.BR avc_has_perm (3)
|
|
Chris PeBenito |
473ea7 |
to reflect the current enforcing mode and flushing the cache on receipt of a policy load notification. Audit messages are produced when netlink notifications are processed.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
In the default single-threaded mode, the userspace AVC checks for new netlink messages at the start of each permission query. If threading and locking callbacks are passed to
|
|
Chris PeBenito |
473ea7 |
.B avc_init
|
|
Chris PeBenito |
473ea7 |
however, a dedicated thread will be started to listen on the netlink socket. This may increase performance and will ensure that log messages are generated immediately rather than at the time of the next permission query.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.SH "RETURN VALUE"
|
|
Chris PeBenito |
473ea7 |
Functions with a return value return zero on success. On error, \-1 is returned and
|
|
Chris PeBenito |
473ea7 |
.I errno
|
|
Chris PeBenito |
473ea7 |
is set appropriately.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.SH "NOTES"
|
|
Chris PeBenito |
473ea7 |
The
|
|
Chris PeBenito |
473ea7 |
.I msgprefix
|
|
Chris PeBenito |
473ea7 |
argument to
|
|
Chris PeBenito |
473ea7 |
.B avc_init
|
|
Chris PeBenito |
473ea7 |
currently has a length limit of 15 characters and will be truncated if necessary.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
If a provided
|
|
Chris PeBenito |
473ea7 |
.B func_malloc
|
|
Chris PeBenito |
473ea7 |
callback does not set
|
|
Chris PeBenito |
473ea7 |
.I errno
|
|
Chris PeBenito |
473ea7 |
appropriately on error, userspace AVC calls may exhibit the
|
|
Chris PeBenito |
473ea7 |
same behavior.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
If a netlink thread has been created and an error occurs on the socket (such as an access error), the thread may terminate and cause the userspace AVC to return
|
|
Chris PeBenito |
473ea7 |
.B EINVAL
|
|
Chris PeBenito |
473ea7 |
on all further permission checks until
|
|
Chris PeBenito |
473ea7 |
.B avc_destroy
|
|
Chris PeBenito |
473ea7 |
is called.
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.SH "AUTHOR"
|
|
Chris PeBenito |
473ea7 |
Eamon Walsh <ewalsh@epoch.ncsc.mil>
|
|
Chris PeBenito |
473ea7 |
|
|
Chris PeBenito |
473ea7 |
.SH "SEE ALSO"
|
|
Chris PeBenito |
473ea7 |
.BR avc_has_perm (3),
|
|
Chris PeBenito |
473ea7 |
.BR avc_context_to_sid (3),
|
|
Chris PeBenito |
473ea7 |
.BR avc_cache_stats (3),
|
|
Chris PeBenito |
473ea7 |
.BR avc_add_callback (3),
|
|
Chris PeBenito |
473ea7 |
.BR security_compute_av (3)
|