xref: /freebsd/sys/security/mac/mac_kdb.c (revision cab10561)
12449b9e5SMitchell Horne /*-
22449b9e5SMitchell Horne  * SPDX-License-Identifier: BSD-2-Clause
32449b9e5SMitchell Horne  *
42449b9e5SMitchell Horne  * Copyright (c) 2021-2022 Klara Systems
52449b9e5SMitchell Horne  *
62449b9e5SMitchell Horne  * This software was developed by Mitchell Horne <mhorne@FreeBSD.org>
72449b9e5SMitchell Horne  * under sponsorship from Juniper Networks and Klara Systems.
82449b9e5SMitchell Horne  *
92449b9e5SMitchell Horne  * Redistribution and use in source and binary forms, with or without
102449b9e5SMitchell Horne  * modification, are permitted provided that the following conditions
112449b9e5SMitchell Horne  * are met:
122449b9e5SMitchell Horne  *
132449b9e5SMitchell Horne  * 1. Redistributions of source code must retain the above copyright
142449b9e5SMitchell Horne  *    notice, this list of conditions and the following disclaimer.
152449b9e5SMitchell Horne  * 2. Redistributions in binary form must reproduce the above copyright
162449b9e5SMitchell Horne  *    notice, this list of conditions and the following disclaimer in the
172449b9e5SMitchell Horne  *    documentation and/or other materials provided with the distribution.
182449b9e5SMitchell Horne  *
192449b9e5SMitchell Horne  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
202449b9e5SMitchell Horne  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
212449b9e5SMitchell Horne  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
222449b9e5SMitchell Horne  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
232449b9e5SMitchell Horne  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
242449b9e5SMitchell Horne  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
252449b9e5SMitchell Horne  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
262449b9e5SMitchell Horne  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
272449b9e5SMitchell Horne  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
282449b9e5SMitchell Horne  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292449b9e5SMitchell Horne  */
302449b9e5SMitchell Horne #include "opt_mac.h"
312449b9e5SMitchell Horne 
322449b9e5SMitchell Horne #include <sys/param.h>
332449b9e5SMitchell Horne #include <sys/kernel.h>
342449b9e5SMitchell Horne #include <sys/module.h>
352449b9e5SMitchell Horne 
362449b9e5SMitchell Horne #include <ddb/ddb.h>
372449b9e5SMitchell Horne 
382449b9e5SMitchell Horne #include <security/mac/mac_framework.h>
392449b9e5SMitchell Horne #include <security/mac/mac_internal.h>
402449b9e5SMitchell Horne #include <security/mac/mac_policy.h>
412449b9e5SMitchell Horne 
422449b9e5SMitchell Horne int
mac_kdb_grant_backend(struct kdb_dbbe * be)43cab10561SMark Johnston mac_kdb_grant_backend(struct kdb_dbbe *be)
44cab10561SMark Johnston {
45cab10561SMark Johnston 	int error = 0;
46cab10561SMark Johnston 
47cab10561SMark Johnston 	MAC_POLICY_GRANT_NOSLEEP(kdb_check_backend, be);
48cab10561SMark Johnston 	return (error);
49cab10561SMark Johnston }
50cab10561SMark Johnston 
51cab10561SMark Johnston int
mac_kdb_check_backend(struct kdb_dbbe * be)522449b9e5SMitchell Horne mac_kdb_check_backend(struct kdb_dbbe *be)
532449b9e5SMitchell Horne {
542449b9e5SMitchell Horne 	int error = 0;
552449b9e5SMitchell Horne 
562449b9e5SMitchell Horne 	MAC_POLICY_CHECK_NOSLEEP(kdb_check_backend, be);
572449b9e5SMitchell Horne 	return (error);
582449b9e5SMitchell Horne }
592449b9e5SMitchell Horne 
602449b9e5SMitchell Horne int
mac_ddb_command_register(struct db_command_table * table,struct db_command * cmd)612449b9e5SMitchell Horne mac_ddb_command_register(struct db_command_table *table, struct db_command *cmd)
622449b9e5SMitchell Horne {
632449b9e5SMitchell Horne 	int error = 0;
642449b9e5SMitchell Horne 
652449b9e5SMitchell Horne 	MAC_POLICY_CHECK_NOSLEEP(ddb_command_register, table, cmd);
662449b9e5SMitchell Horne 	return (error);
672449b9e5SMitchell Horne }
682449b9e5SMitchell Horne 
692449b9e5SMitchell Horne int
mac_ddb_command_exec(struct db_command * cmd,db_expr_t addr,bool have_addr,db_expr_t count,char * modif)702449b9e5SMitchell Horne mac_ddb_command_exec(struct db_command *cmd, db_expr_t addr,
712449b9e5SMitchell Horne     bool have_addr, db_expr_t count, char *modif)
722449b9e5SMitchell Horne {
732449b9e5SMitchell Horne 	int error = 0;
742449b9e5SMitchell Horne 
752449b9e5SMitchell Horne 	MAC_POLICY_CHECK_NOSLEEP(ddb_command_exec, cmd, addr, have_addr,
762449b9e5SMitchell Horne 	    count, modif);
772449b9e5SMitchell Horne 	return (error);
782449b9e5SMitchell Horne }
79