1avc_init(3) SELinux API documentation avc_init(3)
2
3
4
6 avc_init - legacy userspace SELinux AVC setup.
7
9 #include <selinux/selinux.h>
10
11 #include <selinux/avc.h>
12
13 int avc_init(const char *msgprefix,
14 const struct avc_memory_callback *mem_callbacks,
15
16 const struct avc_log_callback *log_callbacks,
17
18 const struct avc_thread_callback *thread_callbacks,
19
20 const struct avc_lock_callback *lock_callbacks);
21
23 avc_init is deprecated; please use avc_open(3) in conjunction with
24 selinux_set_callback(3) in all new code.
25
26 avc_init initializes the userspace AVC and must be called before any
27 other AVC operation can be performed. A non-NULL msgprefix will be
28 prepended to all audit messages produced by the userspace AVC. The
29 default is `uavc'. The remaining arguments, if non-NULL, specify call‐
30 backs to be used by the userspace AVC.
31
32
34 The userspace AVC can be directed how to perform memory allocation,
35 logging, thread creation, and locking via callback functions passed to
36 avc_init. The purpose of this functionality is to allow the userspace
37 AVC to be smoothly integrated into existing userspace object managers.
38
39 Use an avc_memory_callback structure to specify alternate functions for
40 dynamic memory allocation.
41
42 struct avc_memory_callback {
43 void *(*func_malloc)(size_t size);
44 void (*func_free)(void *ptr);
45 };
46
47 The two fields of the structure should be pointers to functions which
48 behave as malloc(3) and free(3), which are used by default.
49
50 Use an avc_log_callback structure to specify alternate functions for
51 logging.
52
53 struct avc_log_callback {
54 void (*func_log)(const char *fmt, ...);
55 void (*func_audit)(void *auditdata,
56 security_class_t class,
57 char *msgbuf, size_t msgbufsize);
58 };
59
60 The func_log callback should accept a printf(3) style format and argu‐
61 ments and log them as desired. The default behavior prints the message
62 on the standard error. The func_audit callback should interpret the
63 auditdata parameter for the given class, printing a human-readable
64 interpretation to msgbuf using no more than msgbufsize characters. The
65 default behavior is to ignore auditdata.
66
67 Use an avc_thread_callback structure to specify functions for starting
68 and manipulating threads.
69
70 struct avc_thread_callback {
71 void *(*func_create_thread)(void (*run)(void));
72 void (*func_stop_thread)(void *thread);
73 };
74
75 The func_create_thread callback should create a new thread and return a
76 pointer which references it. The thread should execute the run argu‐
77 ment, which does not return under normal conditions. The
78 func_stop_thread callback should cancel the running thread referenced
79 by thread. By default, threading is not used; see NETLINK NOTIFICATION
80 below.
81
82 Use an avc_lock_callback structure to specify functions to create,
83 obtain, and release locks for use by threads.
84
85 struct avc_lock_callback {
86 void *(*func_alloc_lock)(void);
87 void (*func_get_lock)(void *lock);
88 void (*func_release_lock)(void *lock);
89 void (*func_free_lock)(void *lock);
90 };
91
92 The func_alloc_lock callback should create a new lock, returning a
93 pointer which references it. The func_get_lock callback should obtain
94 lock, blocking if necessary. The func_release_lock callback should
95 release lock. The func_free_lock callback should destroy lock, freeing
96 any resources associated with it. The default behavior is not to per‐
97 form any locking. Note that undefined behavior may result if threading
98 is used without appropriate locking.
99
100
102 Beginning with version 2.6.4, the Linux kernel supports SELinux status
103 change notification via netlink. Two message types are currently
104 implemented, indicating changes to the enforcing mode and to the loaded
105 policy in the kernel, respectively. The userspace AVC listens for
106 these messages and takes the appropriate action, modifying the behavior
107 of avc_has_perm(3) to reflect the current enforcing mode and flushing
108 the cache on receipt of a policy load notification. Audit messages are
109 produced when netlink notifications are processed.
110
111 In the default single-threaded mode, the userspace AVC checks for new
112 netlink messages at the start of each permission query. If threading
113 and locking callbacks are passed to avc_init however, a dedicated
114 thread will be started to listen on the netlink socket. This may
115 increase performance and will ensure that log messages are generated
116 immediately rather than at the time of the next permission query.
117
118
120 Functions with a return value return zero on success. On error, -1 is
121 returned and errno is set appropriately.
122
123
125 The msgprefix argument to avc_init currently has a length limit of 15
126 characters and will be truncated if necessary.
127
128 If a provided func_malloc callback does not set errno appropriately on
129 error, userspace AVC calls may exhibit the same behavior.
130
131 If a netlink thread has been created and an error occurs on the socket
132 (such as an access error), the thread may terminate and cause the
133 userspace AVC to return EINVAL on all further permission checks until
134 avc_destroy is called.
135
136
138 Eamon Walsh <ewalsh@tycho.nsa.gov>
139
140
142 avc_open(3), selinux_set_callback(3), selinux(8)
143
144
145
146
147 27 May 2004 avc_init(3)