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_add_callback" "3" "9 June 2004" "" "SE Linux API documentation"
Chris PeBenito 473ea7
.SH "NAME"
Chris PeBenito 473ea7
avc_add_callback \- additional event notification for userspace object managers.
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_add_callback(int (*" callback ")(u_int32_t " event , 
Chris PeBenito 473ea7
.in +\w'int avc_add_callback(int (*callback)('u
Chris PeBenito 473ea7
.BI "security_id_t " ssid ,
Chris PeBenito 473ea7
.br
Chris PeBenito 473ea7
.BI "security_id_t " tsid ,
Chris PeBenito 473ea7
.br
Chris PeBenito 473ea7
.BI "security_class_t " tclass ,
Chris PeBenito 473ea7
.br
Chris PeBenito 473ea7
.BI "access_vector_t " perms ,
Chris PeBenito 473ea7
.br
Chris PeBenito 473ea7
.BI "access_vector_t *" out_retained "),"
Chris PeBenito 473ea7
.in
Chris PeBenito 473ea7
.in +\w'int avc_add_callback('u
Chris PeBenito 473ea7
.BI "u_int32_t " events ", security_id_t " ssid , 
Chris PeBenito 473ea7
.br
Chris PeBenito 473ea7
.BI "security_id_t " tsid ", security_class_t " tclass ,
Chris PeBenito 473ea7
.br
Chris PeBenito 473ea7
.BI "access_vector_t " perms ");"
Chris PeBenito 473ea7
.in
Chris PeBenito 473ea7
.SH "DESCRIPTION"
Chris PeBenito 473ea7
.B avc_add_callback
Chris PeBenito 473ea7
is used to register callback functions on security events.  The purpose of this functionality is to allow userspace object managers to take additional action when a policy change, usually a policy reload, causes permissions to be granted or revoked.
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.I events
Chris PeBenito 473ea7
is the
Chris PeBenito 473ea7
.RI bitwise- or
Chris PeBenito 473ea7
of security events on which to register the callback; see
Chris PeBenito 473ea7
.B SECURITY EVENTS
Chris PeBenito 473ea7
below.
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.IR tsid ,
Chris PeBenito 473ea7
.IR tclass ,
Chris PeBenito 473ea7
and
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
specify the source and target SID's, target class, and specific permissions that the callback wishes to monitor.  The special symbol
Chris PeBenito 473ea7
.B SECSID_WILD
Chris PeBenito 473ea7
may be passed as the
Chris PeBenito 473ea7
.I source
Chris PeBenito 473ea7
or
Chris PeBenito 473ea7
.I target
Chris PeBenito 473ea7
and will cause any SID to match.
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.I callback
Chris PeBenito 473ea7
is the callback function provided by the userspace object manager.  The
Chris PeBenito 473ea7
.I event
Chris PeBenito 473ea7
argument indicates the security event which occured; the remaining arguments are interpreted according to the event as described below.  The return value of the callback should be zero on success, \-1 on error with errno set appropriately (but see
Chris PeBenito 473ea7
.B RETURN VALUE
Chris PeBenito 473ea7
below).
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.SH "SECURITY EVENTS"
Chris PeBenito 473ea7
In all cases below,
Chris PeBenito 473ea7
.I ssid
Chris PeBenito 473ea7
and/or
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
may be set to
Chris PeBenito 473ea7
.BR SECSID_WILD ,
Chris PeBenito 473ea7
indicating that the change applies to all source and/or target SID's.  Unless otherwise indicated, the
Chris PeBenito 473ea7
.I out_retained
Chris PeBenito 473ea7
parameter is unused.
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_GRANT
Chris PeBenito 473ea7
Previously denied permissions are now granted for
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
with respect to
Chris PeBenito 473ea7
.IR tclass .
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
indicates the permissions to grant.
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_TRY_REVOKE
Chris PeBenito 473ea7
Previously granted permissions are now conditionally revoked for
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
with respect to
Chris PeBenito 473ea7
.IR tclass .
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
indicates the permissions to revoke.  The callback should set
Chris PeBenito 473ea7
.I out_retained
Chris PeBenito 473ea7
to the subset of
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
which are retained as migrated permissions.  Note that
Chris PeBenito 473ea7
.I out_retained
Chris PeBenito 473ea7
is ignored if the callback returns \-1.
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_REVOKE
Chris PeBenito 473ea7
Previously granted permissions are now unconditionally revoked for
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
with respect to
Chris PeBenito 473ea7
.IR tclass .
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
indicates the permissions to revoke.
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_RESET
Chris PeBenito 473ea7
Indicates that the cache was flushed.  The SID, class, and permission arguments are unused and are set to NULL.
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_AUDITALLOW_ENABLE
Chris PeBenito 473ea7
The permissions given by
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
should now be audited when granted for
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
with respect to
Chris PeBenito 473ea7
.IR tclass .
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_AUDITALLOW_DISABLE
Chris PeBenito 473ea7
The permissions given by
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
should no longer be audited when granted for
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
with respect to
Chris PeBenito 473ea7
.IR tclass .
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_AUDITDENY_ENABLE
Chris PeBenito 473ea7
The permissions given by
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
should now be audited when denied for
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
with respect to
Chris PeBenito 473ea7
.IR tclass .
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B AVC_CALLBACK_AUDITDENY_DISABLE
Chris PeBenito 473ea7
The permissions given by
Chris PeBenito 473ea7
.I perms
Chris PeBenito 473ea7
should no longer be audited when denied for
Chris PeBenito 473ea7
.IR ssid ,
Chris PeBenito 473ea7
.I tsid
Chris PeBenito 473ea7
with respect to
Chris PeBenito 473ea7
.IR tclass .
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.SH "RETURN VALUE"
Chris PeBenito 473ea7
On success,
Chris PeBenito 473ea7
.B avc_add_callback
Chris PeBenito 473ea7
returns zero.  On error, \-1 is returned and
Chris PeBenito 473ea7
.I errno
Chris PeBenito 473ea7
is set appropriately.
Chris PeBenito 473ea7
Chris PeBenito 473ea7
A return value of \-1 from a callback is interpreted as a failed policy operation.  If such a return value is encountered, all remaining callbacks registered on the event are called.  In threaded mode, the netlink handler thread may then 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
.BR avc_destroy (3)
Chris PeBenito 473ea7
is called.  In non-threaded mode, the permission check on which the error occurred will return \-1 and the value of 
Chris PeBenito 473ea7
.I errno
Chris PeBenito 473ea7
encountered to the caller.  In both cases, a log message is produced and the kernel may be notified of the error.
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.SH "ERRORS"
Chris PeBenito 473ea7
.TP
Chris PeBenito 473ea7
.B ENOMEM
Chris PeBenito 473ea7
An attempt to allocate memory failed.
Chris PeBenito 473ea7
Chris PeBenito 473ea7
.SH "NOTES"
Chris PeBenito 473ea7
If the userspace AVC is running in threaded mode, callbacks registered via
Chris PeBenito 473ea7
.B avc_add_callback
Chris PeBenito 473ea7
may be executed in the context of the netlink handler thread.  This will likely introduce synchronization issues requiring the use of locks.  See
Chris PeBenito 473ea7
.BR avc_init (3).
Chris PeBenito 473ea7
Chris PeBenito 473ea7
Support for dynamic revocation and retained permissions is mostly unimplemented in the SELinux kernel module.  The only security event that currently gets excercised is
Chris PeBenito 473ea7
.BR AVC_CALLBACK_RESET .
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_init (3),
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 security_compute_av (3)