2 * util/fptr_wlist.h - function pointer whitelists.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * This file contains functions that check function pointers.
40 * The functions contain a whitelist of known good callback values.
41 * Any other values lead to an error.
43 * This prevent heap overflow based exploits, where the callback pointer
44 * is overwritten by a buffer overflow (apart from this defense, buffer
45 * overflows should be fixed of course).
47 * Function pointers are used in
48 * o network code callbacks.
49 * o rbtree, lruhash, region data manipulation
50 * in lruhash, the assertions are before the critical regions.
51 * in other places, assertions are before the callback.
52 * o module operations.
55 #ifndef UTIL_FPTR_WLIST_H
56 #define UTIL_FPTR_WLIST_H
57 #include "util/netevent.h"
58 #include "util/storage/lruhash.h"
59 #include "util/module.h"
60 #include "util/tube.h"
61 #include "services/mesh.h"
64 * Macro to perform an assertion check for fptr wlist checks.
65 * Does not get disabled in optimize mode. Check adds security by layers.
67 #if defined(EXPORT_ALL_SYMBOLS)
68 #define fptr_ok(x) /* nothing, dll-exe memory layout on win disables it */
72 fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
73 __FILE__, __LINE__, __func__, #x); \
78 * Check function pointer whitelist for comm_point callback values.
80 * @param fptr: function pointer to check.
81 * @return false if not in whitelist.
83 int fptr_whitelist_comm_point(comm_point_callback_type *fptr);
86 * Check function pointer whitelist for raw comm_point callback values.
88 * @param fptr: function pointer to check.
89 * @return false if not in whitelist.
91 int fptr_whitelist_comm_point_raw(comm_point_callback_type *fptr);
94 * Check function pointer whitelist for comm_timer callback values.
96 * @param fptr: function pointer to check.
97 * @return false if not in whitelist.
99 int fptr_whitelist_comm_timer(void (*fptr)(void*));
102 * Check function pointer whitelist for comm_signal callback values.
104 * @param fptr: function pointer to check.
105 * @return false if not in whitelist.
107 int fptr_whitelist_comm_signal(void (*fptr)(int, void*));
110 * Check function pointer whitelist for start_accept callback values.
112 * @param fptr: function pointer to check.
113 * @return false if not in whitelist.
115 int fptr_whitelist_start_accept(void (*fptr)(void*));
118 * Check function pointer whitelist for stop_accept callback values.
120 * @param fptr: function pointer to check.
121 * @return false if not in whitelist.
123 int fptr_whitelist_stop_accept(void (*fptr)(void*));
126 * Check function pointer whitelist for event structure callback values.
127 * This is not called by libevent itself, but checked by netevent.
129 * @param fptr: function pointer to check.
130 * @return false if not in whitelist.
132 int fptr_whitelist_event(void (*fptr)(int, short, void *));
135 * Check function pointer whitelist for pending udp callback values.
137 * @param fptr: function pointer to check.
138 * @return false if not in whitelist.
140 int fptr_whitelist_pending_udp(comm_point_callback_type *fptr);
143 * Check function pointer whitelist for pending tcp callback values.
145 * @param fptr: function pointer to check.
146 * @return false if not in whitelist.
148 int fptr_whitelist_pending_tcp(comm_point_callback_type *fptr);
151 * Check function pointer whitelist for serviced query callback values.
153 * @param fptr: function pointer to check.
154 * @return false if not in whitelist.
156 int fptr_whitelist_serviced_query(comm_point_callback_type *fptr);
159 * Check function pointer whitelist for rbtree cmp callback values.
161 * @param fptr: function pointer to check.
162 * @return false if not in whitelist.
164 int fptr_whitelist_rbtree_cmp(int (*fptr) (const void *, const void *));
167 * Check function pointer whitelist for lruhash sizefunc callback values.
169 * @param fptr: function pointer to check.
170 * @return false if not in whitelist.
172 int fptr_whitelist_hash_sizefunc(lruhash_sizefunc_type fptr);
175 * Check function pointer whitelist for lruhash compfunc callback values.
177 * @param fptr: function pointer to check.
178 * @return false if not in whitelist.
180 int fptr_whitelist_hash_compfunc(lruhash_compfunc_type fptr);
183 * Check function pointer whitelist for lruhash delkeyfunc callback values.
185 * @param fptr: function pointer to check.
186 * @return false if not in whitelist.
188 int fptr_whitelist_hash_delkeyfunc(lruhash_delkeyfunc_type fptr);
191 * Check function pointer whitelist for lruhash deldata callback values.
193 * @param fptr: function pointer to check.
194 * @return false if not in whitelist.
196 int fptr_whitelist_hash_deldatafunc(lruhash_deldatafunc_type fptr);
199 * Check function pointer whitelist for lruhash markdel callback values.
201 * @param fptr: function pointer to check.
202 * @return false if not in whitelist.
204 int fptr_whitelist_hash_markdelfunc(lruhash_markdelfunc_type fptr);
207 * Check function pointer whitelist for module_env send_query callback values.
209 * @param fptr: function pointer to check.
210 * @return false if not in whitelist.
212 int fptr_whitelist_modenv_send_query(struct outbound_entry* (*fptr)(
213 struct query_info* qinfo, uint16_t flags, int dnssec, int want_dnssec,
214 int nocaps, struct sockaddr_storage* addr, socklen_t addrlen,
215 uint8_t* zone, size_t zonelen, int ssl_upstream, char* tls_auth_name,
216 struct module_qstate* q));
219 * Check function pointer whitelist for module_env detach_subs callback values.
221 * @param fptr: function pointer to check.
222 * @return false if not in whitelist.
224 int fptr_whitelist_modenv_detach_subs(void (*fptr)(
225 struct module_qstate* qstate));
228 * Check function pointer whitelist for module_env attach_sub callback values.
230 * @param fptr: function pointer to check.
231 * @return false if not in whitelist.
233 int fptr_whitelist_modenv_attach_sub(int (*fptr)(
234 struct module_qstate* qstate, struct query_info* qinfo,
235 uint16_t qflags, int prime, int valrec, struct module_qstate** newq));
238 * Check function pointer whitelist for module_env add_sub callback values.
240 * @param fptr: function pointer to check.
241 * @return false if not in whitelist.
243 int fptr_whitelist_modenv_add_sub(int (*fptr)(struct module_qstate* qstate,
244 struct query_info* qinfo, uint16_t qflags, int prime, int valrec,
245 struct module_qstate** newq, struct mesh_state** sub));
247 * Check function pointer whitelist for module_env kill_sub callback values.
249 * @param fptr: function pointer to check.
250 * @return false if not in whitelist.
252 int fptr_whitelist_modenv_kill_sub(void (*fptr)(struct module_qstate* newq));
255 * Check function pointer whitelist for module_env detect_cycle callback values.
257 * @param fptr: function pointer to check.
258 * @return false if not in whitelist.
260 int fptr_whitelist_modenv_detect_cycle(int (*fptr)(
261 struct module_qstate* qstate, struct query_info* qinfo,
262 uint16_t flags, int prime, int valrec));
265 * Check function pointer whitelist for module init call values.
267 * @param fptr: function pointer to check.
268 * @return false if not in whitelist.
270 int fptr_whitelist_mod_init(int (*fptr)(struct module_env* env, int id));
273 * Check function pointer whitelist for module deinit call values.
275 * @param fptr: function pointer to check.
276 * @return false if not in whitelist.
278 int fptr_whitelist_mod_deinit(void (*fptr)(struct module_env* env, int id));
281 * Check function pointer whitelist for module operate call values.
283 * @param fptr: function pointer to check.
284 * @return false if not in whitelist.
286 int fptr_whitelist_mod_operate(void (*fptr)(struct module_qstate* qstate,
287 enum module_ev event, int id, struct outbound_entry* outbound));
290 * Check function pointer whitelist for module inform_super call values.
292 * @param fptr: function pointer to check.
293 * @return false if not in whitelist.
295 int fptr_whitelist_mod_inform_super(void (*fptr)(
296 struct module_qstate* qstate, int id, struct module_qstate* super));
299 * Check function pointer whitelist for module clear call values.
301 * @param fptr: function pointer to check.
302 * @return false if not in whitelist.
304 int fptr_whitelist_mod_clear(void (*fptr)(struct module_qstate* qstate,
308 * Check function pointer whitelist for module get_mem call values.
310 * @param fptr: function pointer to check.
311 * @return false if not in whitelist.
313 int fptr_whitelist_mod_get_mem(size_t (*fptr)(struct module_env* env, int id));
316 * Check function pointer whitelist for alloc clear on id overflow call values.
318 * @param fptr: function pointer to check.
319 * @return false if not in whitelist.
321 int fptr_whitelist_alloc_cleanup(void (*fptr)(void*));
324 * Check function pointer whitelist for tube listen handler values.
326 * @param fptr: function pointer to check.
327 * @return false if not in whitelist.
329 int fptr_whitelist_tube_listen(tube_callback_type* fptr);
332 * Check function pointer whitelist for mesh state callback values.
334 * @param fptr: function pointer to check.
335 * @return false if not in whitelist.
337 int fptr_whitelist_mesh_cb(mesh_cb_func_type fptr);
340 * Check function pointer whitelist for config_get_option func values.
341 * @param fptr: function pointer to check.
342 * @return false if not in whitelist.
344 int fptr_whitelist_print_func(void (*fptr)(char*,void*));
347 * Check function pointer whitelist for inplace_cb_reply,
348 * inplace_cb_reply_cache, inplace_cb_reply_local and inplace_cb_reply_servfail
350 * @param fptr: function pointer to check.
351 * @param type: the type of the callback function.
352 * @return false if not in whitelist.
354 int fptr_whitelist_inplace_cb_reply_generic(inplace_cb_reply_func_type* fptr,
355 enum inplace_cb_list_type type);
358 * Check function pointer whitelist for inplace_cb_query func values.
359 * @param fptr: function pointer to check.
360 * @return false if not in whitelist.
362 int fptr_whitelist_inplace_cb_query(inplace_cb_query_func_type* fptr);
365 * Check function pointer whitelist for inplace_cb_edns_back_parsed func values.
366 * @param fptr: function pointer to check.
367 * @return false if not in whitelist.
369 int fptr_whitelist_inplace_cb_edns_back_parsed(
370 inplace_cb_edns_back_parsed_func_type* fptr);
373 * Check function pointer whitelist for inplace_cb_query_response func values.
374 * @param fptr: function pointer to check.
375 * @return false if not in whitelist.
377 int fptr_whitelist_inplace_cb_query_response(
378 inplace_cb_query_response_func_type* fptr);
380 /** Due to module breakage by fptr wlist, these test app declarations
381 * are presented here */
383 * compare two order_ids from lock-verify test app
384 * @param e1: first order_id
385 * @param e2: second order_id
386 * @return compare code -1, 0, +1 (like memcmp).
388 int order_lock_cmp(const void* e1, const void* e2);
391 * compare two codeline structs for rbtree from memstats test app
394 * @return compare code -1, 0, +1 (like memcmp).
396 int codeline_cmp(const void* a, const void* b);
398 /** compare two replay_vars */
399 int replay_var_compare(const void* a, const void* b);
401 #endif /* UTIL_FPTR_WLIST_H */