Debian Codegraph @

libselinux/man/man3/avc_init.3

raw
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Author: Eamon Walsh ([email protected]) 2004
4 .TH "avc_init" "3" "27 May 2004" "" "SELinux API documentation"
5 .SH "NAME"
6 avc_init \- legacy userspace SELinux AVC setup
7 .
8 .SH "SYNOPSIS"
9 .B #include <selinux/selinux.h>
10 .br
11 .B #include <selinux/avc.h>
12 .sp
13 .BI "int avc_init(const char *" msgprefix ,
14 .in +\w'int avc_init('u
15 .BI "const struct avc_memory_callback *" mem_callbacks ,
16 .br
17 .BI "const struct avc_log_callback *" log_callbacks ,
18 .br
19 .BI "const struct avc_thread_callback *" thread_callbacks ,
20 .br
21 .BI "const struct avc_lock_callback *" lock_callbacks ");"
22 .
23 .SH "DESCRIPTION"
24 .BR avc_init ()
25 is deprecated; please use
26 .BR avc_open (3)
27 in conjunction with
28 .BR selinux_set_callback (3)
29 in all new code.
30
31 .BR avc_init ()
32 initializes the userspace AVC and must be called before any other AVC operation can be performed. A non-NULL
33 .I msgprefix
34 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.
35 .
36 .SH "CALLBACKS"
37 The userspace AVC can be directed how to perform memory allocation, logging, thread creation, and locking via callback functions passed to
38 .BR avc_init ().
39 The purpose of this functionality is to allow the userspace AVC to be smoothly integrated into existing userspace object managers.
40
41 Use an
42 .B avc_memory_callback
43 structure to specify alternate functions for dynamic memory allocation.
44
45 .RS
46 .ta 4n 10n 24n
47 .nf
48 struct avc_memory_callback {
49 void *(*func_malloc)(size_t size);
50 void (*func_free)(void *ptr);
51 };
52 .fi
53 .ta
54 .RE
55
56 The two fields of the structure should be pointers to functions which behave as
57 .BR malloc (3)
58 and
59 .BR free (3),
60 which are used by default.
61
62 Use an
63 .B avc_log_callback
64 structure to specify alternate functions for logging.
65
66 .RS
67 .ta 4n 10n 24n
68 .nf
69 struct avc_log_callback {
70 void (*func_log)(const char *fmt, ...);
71 void (*func_audit)(void *auditdata,
72 security_class_t class,
73 char *msgbuf, size_t msgbufsize);
74 };
75 .fi
76 .ta
77 .RE
78
79 The
80 .B func_log
81 callback should accept a
82 .BR printf (3)
83 style format and arguments and log them as desired. The default behavior prints the message on the standard error. The
84 .B func_audit
85 callback should interpret the
86 .I auditdata
87 parameter for the given
88 .IR class ,
89 printing a human-readable interpretation to
90 .I msgbuf
91 using no more than
92 .I msgbufsize
93 characters. The default behavior is to ignore
94 .IR auditdata .
95
96 Use an
97 .B avc_thread_callback
98 structure to specify functions for starting and manipulating threads.
99
100 .RS
101 .ta 4n 10n 24n
102 .nf
103 struct avc_thread_callback {
104 void *(*func_create_thread)(void (*run)(void));
105 void (*func_stop_thread)(void *thread);
106 };
107 .fi
108 .ta
109 .RE
110
111 The
112 .B func_create_thread
113 callback should create a new thread and return a pointer which references it. The thread should execute the
114 .I run
115 argument, which does not return under normal conditions. The
116 .B func_stop_thread
117 callback should cancel the running thread referenced by
118 .IR thread .
119 By default, threading is not used; see
120 .B NETLINK NOTIFICATION
121 below.
122
123 Use an
124 .B avc_lock_callback
125 structure to specify functions to create, obtain, and release locks for use by threads.
126
127 .RS
128 .ta 4n 10n 24n
129 .nf
130 struct avc_lock_callback {
131 void *(*func_alloc_lock)(void);
132 void (*func_get_lock)(void *lock);
133 void (*func_release_lock)(void *lock);
134 void (*func_free_lock)(void *lock);
135 };
136 .fi
137 .ta
138 .RE
139
140 The
141 .B func_alloc_lock
142 callback should create a new lock, returning a pointer which references it. The
143 .B func_get_lock
144 callback should obtain
145 .IR lock ,
146 blocking if necessary. The
147 .B func_release_lock
148 callback should release
149 .IR lock .
150 The
151 .B func_free_lock
152 callback should destroy
153 .IR lock ,
154 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.
155 .
156 .SH "NETLINK NOTIFICATION"
157 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
158 .BR avc_has_perm (3)
159 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.
160
161 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
162 .BR avc_init ()
163 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.
164 .
165 .SH "RETURN VALUE"
166 Functions with a return value return zero on success. On error, \-1 is returned and
167 .I errno
168 is set appropriately.
169 .
170 .SH "NOTES"
171 The
172 .I msgprefix
173 argument to
174 .BR avc_init ()
175 currently has a length limit of 15 characters and will be truncated if necessary.
176
177 If a provided
178 .B func_malloc
179 callback does not set
180 .I errno
181 appropriately on error, userspace AVC calls may exhibit the
182 same behavior.
183
184 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
185 .B EINVAL
186 on all further permission checks until
187 .B avc_destroy
188 is called.
189 .
190 .SH "AUTHOR"
191 Eamon Walsh <[email protected]>
192 .
193 .SH "SEE ALSO"
194 .BR avc_open (3),
195 .BR selinux_set_callback (3),
196 .BR selinux (8)