fptr_wlist.c revision 307729
1239268Sgonzo/* 2239268Sgonzo * util/fptr_wlist.c - function pointer whitelists. 3239268Sgonzo * 4239268Sgonzo * Copyright (c) 2007, NLnet Labs. All rights reserved. 5239268Sgonzo * 6239268Sgonzo * This software is open source. 7239268Sgonzo * 8239268Sgonzo * Redistribution and use in source and binary forms, with or without 9239268Sgonzo * modification, are permitted provided that the following conditions 10239268Sgonzo * are met: 11239268Sgonzo * 12239268Sgonzo * Redistributions of source code must retain the above copyright notice, 13239268Sgonzo * this list of conditions and the following disclaimer. 14239268Sgonzo * 15239268Sgonzo * Redistributions in binary form must reproduce the above copyright notice, 16239268Sgonzo * this list of conditions and the following disclaimer in the documentation 17239268Sgonzo * and/or other materials provided with the distribution. 18239268Sgonzo * 19239268Sgonzo * Neither the name of the NLNET LABS nor the names of its contributors may 20239268Sgonzo * be used to endorse or promote products derived from this software without 21239268Sgonzo * specific prior written permission. 22239268Sgonzo * 23239268Sgonzo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24239268Sgonzo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25239268Sgonzo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26239268Sgonzo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27239268Sgonzo * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28239268Sgonzo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29239268Sgonzo * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30239268Sgonzo * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31239268Sgonzo * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32239268Sgonzo * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33239268Sgonzo * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34239268Sgonzo */ 35239268Sgonzo 36239268Sgonzo/** 37239268Sgonzo * \file 38239268Sgonzo * 39239268Sgonzo * This file contains functions that check function pointers. 40239268Sgonzo * The functions contain a whitelist of known good callback values. 41239268Sgonzo * Any other values lead to an error. 42239268Sgonzo * 43239268Sgonzo * Due to the listing nature, this file violates all the modularization 44239268Sgonzo * boundaries in the program. 45239268Sgonzo */ 46239268Sgonzo#include "config.h" 47239268Sgonzo#include "util/fptr_wlist.h" 48239268Sgonzo#include "util/mini_event.h" 49239268Sgonzo#include "services/outside_network.h" 50239268Sgonzo#include "services/mesh.h" 51239268Sgonzo#include "services/localzone.h" 52239268Sgonzo#include "services/cache/infra.h" 53239268Sgonzo#include "services/cache/rrset.h" 54239268Sgonzo#include "dns64/dns64.h" 55239268Sgonzo#include "iterator/iterator.h" 56239268Sgonzo#include "iterator/iter_fwd.h" 57239268Sgonzo#include "validator/validator.h" 58239268Sgonzo#include "validator/val_anchor.h" 59239268Sgonzo#include "validator/val_nsec3.h" 60239268Sgonzo#include "validator/val_sigcrypt.h" 61239268Sgonzo#include "validator/val_kentry.h" 62239268Sgonzo#include "validator/val_neg.h" 63239268Sgonzo#include "validator/autotrust.h" 64239268Sgonzo#include "util/data/msgreply.h" 65239268Sgonzo#include "util/data/packed_rrset.h" 66239268Sgonzo#include "util/storage/slabhash.h" 67239268Sgonzo#include "util/storage/dnstree.h" 68239268Sgonzo#include "util/locks.h" 69239268Sgonzo#include "libunbound/libworker.h" 70239268Sgonzo#include "libunbound/context.h" 71239268Sgonzo#include "libunbound/worker.h" 72239268Sgonzo#include "util/tube.h" 73239268Sgonzo#include "util/config_file.h" 74239268Sgonzo#ifdef UB_ON_WINDOWS 75239268Sgonzo#include "winrc/win_svc.h" 76239268Sgonzo#endif 77239268Sgonzo 78239268Sgonzo#ifdef WITH_PYTHONMODULE 79239268Sgonzo#include "pythonmod/pythonmod.h" 80239268Sgonzo#endif 81239268Sgonzo#ifdef USE_CACHEDB 82239268Sgonzo#include "cachedb/cachedb.h" 83239268Sgonzo#endif 84239268Sgonzo 85239268Sgonzoint 86239268Sgonzofptr_whitelist_comm_point(comm_point_callback_t *fptr) 87239268Sgonzo{ 88239268Sgonzo if(fptr == &worker_handle_request) return 1; 89239268Sgonzo else if(fptr == &outnet_udp_cb) return 1; 90239268Sgonzo else if(fptr == &outnet_tcp_cb) return 1; 91239268Sgonzo else if(fptr == &tube_handle_listen) return 1; 92239268Sgonzo return 0; 93239268Sgonzo} 94239268Sgonzo 95239268Sgonzoint 96239268Sgonzofptr_whitelist_comm_point_raw(comm_point_callback_t *fptr) 97239268Sgonzo{ 98239268Sgonzo if(fptr == &tube_handle_listen) return 1; 99239268Sgonzo else if(fptr == &tube_handle_write) return 1; 100239268Sgonzo else if(fptr == &remote_accept_callback) return 1; 101239268Sgonzo else if(fptr == &remote_control_callback) return 1; 102239268Sgonzo return 0; 103239268Sgonzo} 104239268Sgonzo 105239268Sgonzoint 106239268Sgonzofptr_whitelist_comm_timer(void (*fptr)(void*)) 107239268Sgonzo{ 108239268Sgonzo if(fptr == &pending_udp_timer_cb) return 1; 109239268Sgonzo else if(fptr == &outnet_tcptimer) return 1; 110239268Sgonzo else if(fptr == &pending_udp_timer_delay_cb) return 1; 111239268Sgonzo else if(fptr == &worker_stat_timer_cb) return 1; 112239268Sgonzo else if(fptr == &worker_probe_timer_cb) return 1; 113239268Sgonzo#ifdef UB_ON_WINDOWS 114239268Sgonzo else if(fptr == &wsvc_cron_cb) return 1; 115239268Sgonzo#endif 116239268Sgonzo return 0; 117239268Sgonzo} 118239268Sgonzo 119239268Sgonzoint 120239268Sgonzofptr_whitelist_comm_signal(void (*fptr)(int, void*)) 121239268Sgonzo{ 122239268Sgonzo if(fptr == &worker_sighandler) return 1; 123239268Sgonzo return 0; 124239268Sgonzo} 125239268Sgonzo 126239268Sgonzoint fptr_whitelist_start_accept(void (*fptr)(void*)) 127239268Sgonzo{ 128239268Sgonzo if(fptr == &worker_start_accept) return 1; 129239268Sgonzo return 0; 130239268Sgonzo} 131239268Sgonzo 132239268Sgonzoint fptr_whitelist_stop_accept(void (*fptr)(void*)) 133239268Sgonzo{ 134239268Sgonzo if(fptr == &worker_stop_accept) return 1; 135239268Sgonzo return 0; 136239268Sgonzo} 137239268Sgonzo 138239268Sgonzoint 139239268Sgonzofptr_whitelist_event(void (*fptr)(int, short, void *)) 140239268Sgonzo{ 141239268Sgonzo if(fptr == &comm_point_udp_callback) return 1; 142239268Sgonzo else if(fptr == &comm_point_udp_ancil_callback) return 1; 143239268Sgonzo else if(fptr == &comm_point_tcp_accept_callback) return 1; 144239268Sgonzo else if(fptr == &comm_point_tcp_handle_callback) return 1; 145239268Sgonzo else if(fptr == &comm_timer_callback) return 1; 146239268Sgonzo else if(fptr == &comm_signal_callback) return 1; 147239268Sgonzo else if(fptr == &comm_point_local_handle_callback) return 1; 148239268Sgonzo else if(fptr == &comm_point_raw_handle_callback) return 1; 149239268Sgonzo else if(fptr == &tube_handle_signal) return 1; 150239268Sgonzo else if(fptr == &comm_base_handle_slow_accept) return 1; 151239268Sgonzo#ifdef UB_ON_WINDOWS 152239268Sgonzo else if(fptr == &worker_win_stop_cb) return 1; 153239268Sgonzo#endif 154239268Sgonzo return 0; 155239268Sgonzo} 156239268Sgonzo 157239268Sgonzoint 158239268Sgonzofptr_whitelist_pending_udp(comm_point_callback_t *fptr) 159239268Sgonzo{ 160239268Sgonzo if(fptr == &serviced_udp_callback) return 1; 161239268Sgonzo else if(fptr == &worker_handle_reply) return 1; 162239268Sgonzo else if(fptr == &libworker_handle_reply) return 1; 163239268Sgonzo return 0; 164239268Sgonzo} 165239268Sgonzo 166239268Sgonzoint 167239268Sgonzofptr_whitelist_pending_tcp(comm_point_callback_t *fptr) 168239268Sgonzo{ 169239268Sgonzo if(fptr == &serviced_tcp_callback) return 1; 170239268Sgonzo else if(fptr == &worker_handle_reply) return 1; 171239268Sgonzo else if(fptr == &libworker_handle_reply) return 1; 172239268Sgonzo return 0; 173239268Sgonzo} 174239268Sgonzo 175239268Sgonzoint 176239268Sgonzofptr_whitelist_serviced_query(comm_point_callback_t *fptr) 177239268Sgonzo{ 178239268Sgonzo if(fptr == &worker_handle_service_reply) return 1; 179239268Sgonzo else if(fptr == &libworker_handle_service_reply) return 1; 180239268Sgonzo return 0; 181239268Sgonzo} 182239268Sgonzo 183239268Sgonzoint 184239268Sgonzofptr_whitelist_rbtree_cmp(int (*fptr) (const void *, const void *)) 185239268Sgonzo{ 186239268Sgonzo if(fptr == &mesh_state_compare) return 1; 187239268Sgonzo else if(fptr == &mesh_state_ref_compare) return 1; 188239268Sgonzo else if(fptr == &addr_tree_compare) return 1; 189239268Sgonzo else if(fptr == &local_zone_cmp) return 1; 190239268Sgonzo else if(fptr == &local_data_cmp) return 1; 191239268Sgonzo else if(fptr == &fwd_cmp) return 1; 192239268Sgonzo else if(fptr == &pending_cmp) return 1; 193239268Sgonzo else if(fptr == &serviced_cmp) return 1; 194239268Sgonzo else if(fptr == &name_tree_compare) return 1; 195239268Sgonzo else if(fptr == &order_lock_cmp) return 1; 196239268Sgonzo else if(fptr == &codeline_cmp) return 1; 197239268Sgonzo else if(fptr == &nsec3_hash_cmp) return 1; 198239268Sgonzo else if(fptr == &mini_ev_cmp) return 1; 199239268Sgonzo else if(fptr == &anchor_cmp) return 1; 200239268Sgonzo else if(fptr == &canonical_tree_compare) return 1; 201239268Sgonzo else if(fptr == &context_query_cmp) return 1; 202239268Sgonzo else if(fptr == &val_neg_data_compare) return 1; 203239268Sgonzo else if(fptr == &val_neg_zone_compare) return 1; 204239268Sgonzo else if(fptr == &probetree_cmp) return 1; 205239268Sgonzo else if(fptr == &replay_var_compare) return 1; 206239268Sgonzo return 0; 207239268Sgonzo} 208239268Sgonzo 209239268Sgonzoint 210239268Sgonzofptr_whitelist_hash_sizefunc(lruhash_sizefunc_t fptr) 211239268Sgonzo{ 212239268Sgonzo if(fptr == &msgreply_sizefunc) return 1; 213239268Sgonzo else if(fptr == &ub_rrset_sizefunc) return 1; 214239268Sgonzo else if(fptr == &infra_sizefunc) return 1; 215239268Sgonzo else if(fptr == &key_entry_sizefunc) return 1; 216239268Sgonzo else if(fptr == &rate_sizefunc) return 1; 217239268Sgonzo else if(fptr == &test_slabhash_sizefunc) return 1; 218239268Sgonzo return 0; 219239268Sgonzo} 220239268Sgonzo 221239268Sgonzoint 222239268Sgonzofptr_whitelist_hash_compfunc(lruhash_compfunc_t fptr) 223239268Sgonzo{ 224239268Sgonzo if(fptr == &query_info_compare) return 1; 225239268Sgonzo else if(fptr == &ub_rrset_compare) return 1; 226239268Sgonzo else if(fptr == &infra_compfunc) return 1; 227239268Sgonzo else if(fptr == &key_entry_compfunc) return 1; 228239268Sgonzo else if(fptr == &rate_compfunc) return 1; 229239268Sgonzo else if(fptr == &test_slabhash_compfunc) return 1; 230239268Sgonzo return 0; 231239268Sgonzo} 232239268Sgonzo 233239268Sgonzoint 234239268Sgonzofptr_whitelist_hash_delkeyfunc(lruhash_delkeyfunc_t fptr) 235239268Sgonzo{ 236239268Sgonzo if(fptr == &query_entry_delete) return 1; 237239268Sgonzo else if(fptr == &ub_rrset_key_delete) return 1; 238239268Sgonzo else if(fptr == &infra_delkeyfunc) return 1; 239239268Sgonzo else if(fptr == &key_entry_delkeyfunc) return 1; 240239268Sgonzo else if(fptr == &rate_delkeyfunc) return 1; 241239268Sgonzo else if(fptr == &test_slabhash_delkey) return 1; 242239268Sgonzo return 0; 243239268Sgonzo} 244239268Sgonzo 245239268Sgonzoint 246239268Sgonzofptr_whitelist_hash_deldatafunc(lruhash_deldatafunc_t fptr) 247239268Sgonzo{ 248239268Sgonzo if(fptr == &reply_info_delete) return 1; 249239268Sgonzo else if(fptr == &rrset_data_delete) return 1; 250239268Sgonzo else if(fptr == &infra_deldatafunc) return 1; 251239268Sgonzo else if(fptr == &key_entry_deldatafunc) return 1; 252239268Sgonzo else if(fptr == &rate_deldatafunc) return 1; 253239268Sgonzo else if(fptr == &test_slabhash_deldata) return 1; 254239268Sgonzo return 0; 255239268Sgonzo} 256239268Sgonzo 257239268Sgonzoint 258239268Sgonzofptr_whitelist_hash_markdelfunc(lruhash_markdelfunc_t fptr) 259239268Sgonzo{ 260239268Sgonzo if(fptr == NULL) return 1; 261239268Sgonzo else if(fptr == &rrset_markdel) return 1; 262239268Sgonzo return 0; 263239268Sgonzo} 264239268Sgonzo 265239268Sgonzo/** whitelist env->send_query callbacks */ 266239268Sgonzoint 267239268Sgonzofptr_whitelist_modenv_send_query(struct outbound_entry* (*fptr)( 268239268Sgonzo uint8_t* qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, 269239268Sgonzo uint16_t flags, int dnssec, int want_dnssec, int nocaps, 270239268Sgonzo struct edns_option* opt_list, struct sockaddr_storage* addr, 271239268Sgonzo socklen_t addrlen, uint8_t* zone, size_t zonelen, 272239268Sgonzo struct module_qstate* q)) 273239268Sgonzo{ 274239268Sgonzo if(fptr == &worker_send_query) return 1; 275239268Sgonzo else if(fptr == &libworker_send_query) return 1; 276239268Sgonzo return 0; 277239268Sgonzo} 278239268Sgonzo 279239268Sgonzoint 280239268Sgonzofptr_whitelist_modenv_detach_subs(void (*fptr)( 281239268Sgonzo struct module_qstate* qstate)) 282239268Sgonzo{ 283239268Sgonzo if(fptr == &mesh_detach_subs) return 1; 284239268Sgonzo return 0; 285239268Sgonzo} 286239268Sgonzo 287239268Sgonzoint 288239268Sgonzofptr_whitelist_modenv_attach_sub(int (*fptr)( 289239268Sgonzo struct module_qstate* qstate, struct query_info* qinfo, 290239268Sgonzo uint16_t qflags, int prime, int valrec, struct module_qstate** newq)) 291239268Sgonzo{ 292239268Sgonzo if(fptr == &mesh_attach_sub) return 1; 293239268Sgonzo return 0; 294239268Sgonzo} 295239268Sgonzo 296239268Sgonzoint 297239268Sgonzofptr_whitelist_modenv_kill_sub(void (*fptr)(struct module_qstate* newq)) 298239268Sgonzo{ 299239268Sgonzo if(fptr == &mesh_state_delete) return 1; 300239268Sgonzo return 0; 301239268Sgonzo} 302239268Sgonzo 303239268Sgonzoint 304239268Sgonzofptr_whitelist_modenv_detect_cycle(int (*fptr)( 305239268Sgonzo struct module_qstate* qstate, struct query_info* qinfo, 306239268Sgonzo uint16_t flags, int prime, int valrec)) 307239268Sgonzo{ 308239268Sgonzo if(fptr == &mesh_detect_cycle) return 1; 309239268Sgonzo return 0; 310239268Sgonzo} 311239268Sgonzo 312239268Sgonzoint 313239268Sgonzofptr_whitelist_mod_init(int (*fptr)(struct module_env* env, int id)) 314239268Sgonzo{ 315239268Sgonzo if(fptr == &iter_init) return 1; 316239268Sgonzo else if(fptr == &val_init) return 1; 317239268Sgonzo else if(fptr == &dns64_init) return 1; 318239268Sgonzo#ifdef WITH_PYTHONMODULE 319239268Sgonzo else if(fptr == &pythonmod_init) return 1; 320239268Sgonzo#endif 321239268Sgonzo#ifdef USE_CACHEDB 322239268Sgonzo else if(fptr == &cachedb_init) return 1; 323239268Sgonzo#endif 324239268Sgonzo return 0; 325239268Sgonzo} 326239268Sgonzo 327239268Sgonzoint 328239268Sgonzofptr_whitelist_mod_deinit(void (*fptr)(struct module_env* env, int id)) 329239268Sgonzo{ 330239268Sgonzo if(fptr == &iter_deinit) return 1; 331239268Sgonzo else if(fptr == &val_deinit) return 1; 332239268Sgonzo else if(fptr == &dns64_deinit) return 1; 333239268Sgonzo#ifdef WITH_PYTHONMODULE 334239268Sgonzo else if(fptr == &pythonmod_deinit) return 1; 335239268Sgonzo#endif 336239268Sgonzo#ifdef USE_CACHEDB 337239268Sgonzo else if(fptr == &cachedb_deinit) return 1; 338239268Sgonzo#endif 339239268Sgonzo return 0; 340239268Sgonzo} 341239268Sgonzo 342239268Sgonzoint 343239268Sgonzofptr_whitelist_mod_operate(void (*fptr)(struct module_qstate* qstate, 344239268Sgonzo enum module_ev event, int id, struct outbound_entry* outbound)) 345239268Sgonzo{ 346239268Sgonzo if(fptr == &iter_operate) return 1; 347239268Sgonzo else if(fptr == &val_operate) return 1; 348239268Sgonzo else if(fptr == &dns64_operate) return 1; 349239268Sgonzo#ifdef WITH_PYTHONMODULE 350239268Sgonzo else if(fptr == &pythonmod_operate) return 1; 351239268Sgonzo#endif 352239268Sgonzo#ifdef USE_CACHEDB 353239268Sgonzo else if(fptr == &cachedb_operate) return 1; 354239268Sgonzo#endif 355239268Sgonzo return 0; 356239268Sgonzo} 357239268Sgonzo 358239268Sgonzoint 359239268Sgonzofptr_whitelist_mod_inform_super(void (*fptr)( 360239268Sgonzo struct module_qstate* qstate, int id, struct module_qstate* super)) 361239268Sgonzo{ 362239268Sgonzo if(fptr == &iter_inform_super) return 1; 363239268Sgonzo else if(fptr == &val_inform_super) return 1; 364239268Sgonzo else if(fptr == &dns64_inform_super) return 1; 365239268Sgonzo#ifdef WITH_PYTHONMODULE 366239268Sgonzo else if(fptr == &pythonmod_inform_super) return 1; 367239268Sgonzo#endif 368239268Sgonzo#ifdef USE_CACHEDB 369239268Sgonzo else if(fptr == &cachedb_inform_super) return 1; 370239268Sgonzo#endif 371239268Sgonzo return 0; 372239268Sgonzo} 373239268Sgonzo 374239268Sgonzoint 375239268Sgonzofptr_whitelist_mod_clear(void (*fptr)(struct module_qstate* qstate, 376239268Sgonzo int id)) 377239268Sgonzo{ 378239268Sgonzo if(fptr == &iter_clear) return 1; 379239268Sgonzo else if(fptr == &val_clear) return 1; 380239268Sgonzo else if(fptr == &dns64_clear) return 1; 381239268Sgonzo#ifdef WITH_PYTHONMODULE 382239268Sgonzo else if(fptr == &pythonmod_clear) return 1; 383239268Sgonzo#endif 384239268Sgonzo#ifdef USE_CACHEDB 385239268Sgonzo else if(fptr == &cachedb_clear) return 1; 386239268Sgonzo#endif 387239268Sgonzo return 0; 388239268Sgonzo} 389239268Sgonzo 390239268Sgonzoint 391239268Sgonzofptr_whitelist_mod_get_mem(size_t (*fptr)(struct module_env* env, int id)) 392239268Sgonzo{ 393239268Sgonzo if(fptr == &iter_get_mem) return 1; 394239268Sgonzo else if(fptr == &val_get_mem) return 1; 395239268Sgonzo else if(fptr == &dns64_get_mem) return 1; 396239268Sgonzo#ifdef WITH_PYTHONMODULE 397239268Sgonzo else if(fptr == &pythonmod_get_mem) return 1; 398239268Sgonzo#endif 399239268Sgonzo#ifdef USE_CACHEDB 400239268Sgonzo else if(fptr == &cachedb_get_mem) return 1; 401239268Sgonzo#endif 402239268Sgonzo return 0; 403239268Sgonzo} 404239268Sgonzo 405239268Sgonzoint 406239268Sgonzofptr_whitelist_alloc_cleanup(void (*fptr)(void*)) 407239268Sgonzo{ 408239268Sgonzo if(fptr == &worker_alloc_cleanup) return 1; 409239268Sgonzo return 0; 410239268Sgonzo} 411239268Sgonzo 412239268Sgonzoint fptr_whitelist_tube_listen(tube_callback_t* fptr) 413239268Sgonzo{ 414239268Sgonzo if(fptr == &worker_handle_control_cmd) return 1; 415239268Sgonzo else if(fptr == &libworker_handle_control_cmd) return 1; 416239268Sgonzo return 0; 417239268Sgonzo} 418239268Sgonzo 419239268Sgonzoint fptr_whitelist_mesh_cb(mesh_cb_func_t fptr) 420239268Sgonzo{ 421239268Sgonzo if(fptr == &libworker_fg_done_cb) return 1; 422239268Sgonzo else if(fptr == &libworker_bg_done_cb) return 1; 423239268Sgonzo else if(fptr == &libworker_event_done_cb) return 1; 424239268Sgonzo else if(fptr == &probe_answer_cb) return 1; 425239268Sgonzo return 0; 426239268Sgonzo} 427239268Sgonzo 428239268Sgonzoint fptr_whitelist_print_func(void (*fptr)(char*,void*)) 429239268Sgonzo{ 430239268Sgonzo if(fptr == &config_print_func) return 1; 431239268Sgonzo else if(fptr == &config_collate_func) return 1; 432239268Sgonzo else if(fptr == &remote_get_opt_ssl) return 1; 433239268Sgonzo return 0; 434239268Sgonzo} 435239268Sgonzo