// SPDX-License-Identifier: GPL-2.0-or-later1/*2* NetLabel NETLINK Interface3*4* This file defines the NETLINK interface for the NetLabel system. The5* NetLabel system manages static and dynamic label mappings for network6* protocols such as CIPSO and RIPSO.7*8* Author: Paul Moore <[email protected]>9*/1011/*12* (c) Copyright Hewlett-Packard Development Company, L.P., 200613*/1415#include <linux/init.h>16#include <linux/types.h>17#include <linux/list.h>18#include <linux/socket.h>19#include <linux/audit.h>20#include <linux/tty.h>21#include <linux/security.h>22#include <linux/gfp.h>23#include <net/sock.h>24#include <net/netlink.h>25#include <net/genetlink.h>26#include <net/netlabel.h>27#include <asm/bug.h>2829#include "netlabel_mgmt.h"30#include "netlabel_unlabeled.h"31#include "netlabel_cipso_v4.h"32#include "netlabel_calipso.h"33#include "netlabel_user.h"3435/*36* NetLabel NETLINK Setup Functions37*/3839/**40* netlbl_netlink_init - Initialize the NETLINK communication channel41*42* Description:43* Call out to the NetLabel components so they can register their families and44* commands with the Generic NETLINK mechanism. Returns zero on success and45* non-zero on failure.46*47*/48int __init netlbl_netlink_init(void)49{50int ret_val;5152ret_val = netlbl_mgmt_genl_init();53if (ret_val != 0)54return ret_val;5556ret_val = netlbl_cipsov4_genl_init();57if (ret_val != 0)58return ret_val;5960ret_val = netlbl_calipso_genl_init();61if (ret_val != 0)62return ret_val;6364return netlbl_unlabel_genl_init();65}6667/*68* NetLabel Audit Functions69*/7071/**72* netlbl_audit_start_common - Start an audit message73* @type: audit message type74* @audit_info: NetLabel audit information75*76* Description:77* Start an audit message using the type specified in @type and fill the audit78* message with some fields common to all NetLabel audit messages. Returns79* a pointer to the audit buffer on success, NULL on failure.80*81*/82struct audit_buffer *netlbl_audit_start_common(int type,83struct netlbl_audit *audit_info)84{85struct audit_buffer *audit_buf;86struct lsm_context ctx;8788if (audit_enabled == AUDIT_OFF)89return NULL;9091audit_buf = audit_log_start(audit_context(), GFP_ATOMIC, type);92if (audit_buf == NULL)93return NULL;9495audit_log_format(audit_buf, "netlabel: auid=%u ses=%u",96from_kuid(&init_user_ns, audit_info->loginuid),97audit_info->sessionid);9899if (lsmprop_is_set(&audit_info->prop) &&100security_lsmprop_to_secctx(&audit_info->prop, &ctx) > 0) {101audit_log_format(audit_buf, " subj=%s", ctx.context);102security_release_secctx(&ctx);103}104105return audit_buf;106}107108109