1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * NetLabel NETLINK Interface
5 * This file defines the NETLINK interface for the NetLabel system. The
6 * NetLabel system manages static and dynamic label mappings for network
7 * protocols such as CIPSO and RIPSO.
9 * Author: Paul Moore <paul@paul-moore.com>
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
16 #include <linux/init.h>
17 #include <linux/types.h>
18 #include <linux/list.h>
19 #include <linux/socket.h>
20 #include <linux/audit.h>
21 #include <linux/tty.h>
22 #include <linux/security.h>
23 #include <linux/gfp.h>
25 #include <net/netlink.h>
26 #include <net/genetlink.h>
27 #include <net/netlabel.h>
30 #include "netlabel_mgmt.h"
31 #include "netlabel_unlabeled.h"
32 #include "netlabel_cipso_v4.h"
33 #include "netlabel_calipso.h"
34 #include "netlabel_user.h"
37 * NetLabel NETLINK Setup Functions
41 * netlbl_netlink_init - Initialize the NETLINK communication channel
44 * Call out to the NetLabel components so they can register their families and
45 * commands with the Generic NETLINK mechanism. Returns zero on success and
46 * non-zero on failure.
49 int __init
netlbl_netlink_init(void)
53 ret_val
= netlbl_mgmt_genl_init();
57 ret_val
= netlbl_cipsov4_genl_init();
61 ret_val
= netlbl_calipso_genl_init();
65 return netlbl_unlabel_genl_init();
69 * NetLabel Audit Functions
73 * netlbl_audit_start_common - Start an audit message
74 * @type: audit message type
75 * @audit_info: NetLabel audit information
78 * Start an audit message using the type specified in @type and fill the audit
79 * message with some fields common to all NetLabel audit messages. Returns
80 * a pointer to the audit buffer on success, NULL on failure.
83 struct audit_buffer
*netlbl_audit_start_common(int type
,
84 struct netlbl_audit
*audit_info
)
86 struct audit_buffer
*audit_buf
;
90 if (audit_enabled
== AUDIT_OFF
)
93 audit_buf
= audit_log_start(audit_context(), GFP_ATOMIC
, type
);
94 if (audit_buf
== NULL
)
97 audit_log_format(audit_buf
, "netlabel: auid=%u ses=%u",
98 from_kuid(&init_user_ns
, audit_info
->loginuid
),
99 audit_info
->sessionid
);
101 if (lsmprop_is_set(&audit_info
->prop
) &&
102 security_lsmprop_to_secctx(&audit_info
->prop
, &secctx
,
104 audit_log_format(audit_buf
, " subj=%s", secctx
);
105 security_release_secctx(secctx
, secctx_len
);