Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * NetLabel NETLINK Interface
4 *
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.
8 *
9 * Author: Paul Moore <paul@paul-moore.com>
10 */
11
12/*
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
14 */
15
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>
24#include <net/sock.h>
25#include <net/netlink.h>
26#include <net/genetlink.h>
27#include <net/netlabel.h>
28#include <asm/bug.h>
29
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"
35
36/*
37 * NetLabel NETLINK Setup Functions
38 */
39
40/**
41 * netlbl_netlink_init - Initialize the NETLINK communication channel
42 *
43 * Description:
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.
47 *
48 */
49int __init netlbl_netlink_init(void)
50{
51 int ret_val;
52
53 ret_val = netlbl_mgmt_genl_init();
54 if (ret_val != 0)
55 return ret_val;
56
57 ret_val = netlbl_cipsov4_genl_init();
58 if (ret_val != 0)
59 return ret_val;
60
61 ret_val = netlbl_calipso_genl_init();
62 if (ret_val != 0)
63 return ret_val;
64
65 return netlbl_unlabel_genl_init();
66}
67
68/*
69 * NetLabel Audit Functions
70 */
71
72/**
73 * netlbl_audit_start_common - Start an audit message
74 * @type: audit message type
75 * @audit_info: NetLabel audit information
76 *
77 * Description:
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.
81 *
82 */
83struct audit_buffer *netlbl_audit_start_common(int type,
84 struct netlbl_audit *audit_info)
85{
86 struct audit_buffer *audit_buf;
87 char *secctx;
88 u32 secctx_len;
89
90 if (audit_enabled == AUDIT_OFF)
91 return NULL;
92
93 audit_buf = audit_log_start(audit_context(), GFP_ATOMIC, type);
94 if (audit_buf == NULL)
95 return NULL;
96
97 audit_log_format(audit_buf, "netlabel: auid=%u ses=%u",
98 from_kuid(&init_user_ns, audit_info->loginuid),
99 audit_info->sessionid);
100
101 if (audit_info->secid != 0 &&
102 security_secid_to_secctx(audit_info->secid,
103 &secctx,
104 &secctx_len) == 0) {
105 audit_log_format(audit_buf, " subj=%s", secctx);
106 security_release_secctx(secctx, secctx_len);
107 }
108
109 return audit_buf;
110}
1/*
2 * NetLabel NETLINK Interface
3 *
4 * This file defines the NETLINK interface for the NetLabel system. The
5 * NetLabel system manages static and dynamic label mappings for network
6 * protocols such as CIPSO and RIPSO.
7 *
8 * Author: Paul Moore <paul@paul-moore.com>
9 *
10 */
11
12/*
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
23 * the GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 *
28 */
29
30#include <linux/init.h>
31#include <linux/types.h>
32#include <linux/list.h>
33#include <linux/socket.h>
34#include <linux/audit.h>
35#include <linux/tty.h>
36#include <linux/security.h>
37#include <linux/gfp.h>
38#include <net/sock.h>
39#include <net/netlink.h>
40#include <net/genetlink.h>
41#include <net/netlabel.h>
42#include <asm/bug.h>
43
44#include "netlabel_mgmt.h"
45#include "netlabel_unlabeled.h"
46#include "netlabel_cipso_v4.h"
47#include "netlabel_user.h"
48
49/*
50 * NetLabel NETLINK Setup Functions
51 */
52
53/**
54 * netlbl_netlink_init - Initialize the NETLINK communication channel
55 *
56 * Description:
57 * Call out to the NetLabel components so they can register their families and
58 * commands with the Generic NETLINK mechanism. Returns zero on success and
59 * non-zero on failure.
60 *
61 */
62int __init netlbl_netlink_init(void)
63{
64 int ret_val;
65
66 ret_val = netlbl_mgmt_genl_init();
67 if (ret_val != 0)
68 return ret_val;
69
70 ret_val = netlbl_cipsov4_genl_init();
71 if (ret_val != 0)
72 return ret_val;
73
74 return netlbl_unlabel_genl_init();
75}
76
77/*
78 * NetLabel Audit Functions
79 */
80
81/**
82 * netlbl_audit_start_common - Start an audit message
83 * @type: audit message type
84 * @audit_info: NetLabel audit information
85 *
86 * Description:
87 * Start an audit message using the type specified in @type and fill the audit
88 * message with some fields common to all NetLabel audit messages. Returns
89 * a pointer to the audit buffer on success, NULL on failure.
90 *
91 */
92struct audit_buffer *netlbl_audit_start_common(int type,
93 struct netlbl_audit *audit_info)
94{
95 struct audit_buffer *audit_buf;
96 char *secctx;
97 u32 secctx_len;
98
99 if (audit_enabled == 0)
100 return NULL;
101
102 audit_buf = audit_log_start(current->audit_context, GFP_ATOMIC, type);
103 if (audit_buf == NULL)
104 return NULL;
105
106 audit_log_format(audit_buf, "netlabel: auid=%u ses=%u",
107 from_kuid(&init_user_ns, audit_info->loginuid),
108 audit_info->sessionid);
109
110 if (audit_info->secid != 0 &&
111 security_secid_to_secctx(audit_info->secid,
112 &secctx,
113 &secctx_len) == 0) {
114 audit_log_format(audit_buf, " subj=%s", secctx);
115 security_release_secctx(secctx, secctx_len);
116 }
117
118 return audit_buf;
119}