xref: /linux/net/netlabel/netlabel_user.c (revision cb72d38211eacda2dd90b09540542b6582da614e)
1d15c345fSPaul Moore /*
2d15c345fSPaul Moore  * NetLabel NETLINK Interface
3d15c345fSPaul Moore  *
4d15c345fSPaul Moore  * This file defines the NETLINK interface for the NetLabel system.  The
5d15c345fSPaul Moore  * NetLabel system manages static and dynamic label mappings for network
6d15c345fSPaul Moore  * protocols such as CIPSO and RIPSO.
7d15c345fSPaul Moore  *
882c21bfaSPaul Moore  * Author: Paul Moore <paul@paul-moore.com>
9d15c345fSPaul Moore  *
10d15c345fSPaul Moore  */
11d15c345fSPaul Moore 
12d15c345fSPaul Moore /*
13d15c345fSPaul Moore  * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
14d15c345fSPaul Moore  *
15d15c345fSPaul Moore  * This program is free software;  you can redistribute it and/or modify
16d15c345fSPaul Moore  * it under the terms of the GNU General Public License as published by
17d15c345fSPaul Moore  * the Free Software Foundation; either version 2 of the License, or
18d15c345fSPaul Moore  * (at your option) any later version.
19d15c345fSPaul Moore  *
20d15c345fSPaul Moore  * This program is distributed in the hope that it will be useful,
21d15c345fSPaul Moore  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
22d15c345fSPaul Moore  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
23d15c345fSPaul Moore  * the GNU General Public License for more details.
24d15c345fSPaul Moore  *
25d15c345fSPaul Moore  * You should have received a copy of the GNU General Public License
26d484ff15SJeff Kirsher  * along with this program;  if not, see <http://www.gnu.org/licenses/>.
27d15c345fSPaul Moore  *
28d15c345fSPaul Moore  */
29d15c345fSPaul Moore 
30d15c345fSPaul Moore #include <linux/init.h>
31d15c345fSPaul Moore #include <linux/types.h>
32d15c345fSPaul Moore #include <linux/list.h>
33d15c345fSPaul Moore #include <linux/socket.h>
3432f50cdeSPaul Moore #include <linux/audit.h>
3532f50cdeSPaul Moore #include <linux/tty.h>
3632f50cdeSPaul Moore #include <linux/security.h>
375a0e3ad6STejun Heo #include <linux/gfp.h>
38d15c345fSPaul Moore #include <net/sock.h>
39d15c345fSPaul Moore #include <net/netlink.h>
40d15c345fSPaul Moore #include <net/genetlink.h>
41d15c345fSPaul Moore #include <net/netlabel.h>
42d15c345fSPaul Moore #include <asm/bug.h>
43d15c345fSPaul Moore 
44d15c345fSPaul Moore #include "netlabel_mgmt.h"
45d15c345fSPaul Moore #include "netlabel_unlabeled.h"
46d15c345fSPaul Moore #include "netlabel_cipso_v4.h"
47*cb72d382SHuw Davies #include "netlabel_calipso.h"
48d15c345fSPaul Moore #include "netlabel_user.h"
49d15c345fSPaul Moore 
50d15c345fSPaul Moore /*
51d15c345fSPaul Moore  * NetLabel NETLINK Setup Functions
52d15c345fSPaul Moore  */
53d15c345fSPaul Moore 
54d15c345fSPaul Moore /**
55d15c345fSPaul Moore  * netlbl_netlink_init - Initialize the NETLINK communication channel
56d15c345fSPaul Moore  *
57d15c345fSPaul Moore  * Description:
58d15c345fSPaul Moore  * Call out to the NetLabel components so they can register their families and
59d15c345fSPaul Moore  * commands with the Generic NETLINK mechanism.  Returns zero on success and
60d15c345fSPaul Moore  * non-zero on failure.
61d15c345fSPaul Moore  *
62d15c345fSPaul Moore  */
6305705e4eSPavel Emelyanov int __init netlbl_netlink_init(void)
64d15c345fSPaul Moore {
65d15c345fSPaul Moore 	int ret_val;
66d15c345fSPaul Moore 
67d15c345fSPaul Moore 	ret_val = netlbl_mgmt_genl_init();
68d15c345fSPaul Moore 	if (ret_val != 0)
69d15c345fSPaul Moore 		return ret_val;
70d15c345fSPaul Moore 
71d15c345fSPaul Moore 	ret_val = netlbl_cipsov4_genl_init();
72d15c345fSPaul Moore 	if (ret_val != 0)
73d15c345fSPaul Moore 		return ret_val;
74d15c345fSPaul Moore 
75*cb72d382SHuw Davies 	ret_val = netlbl_calipso_genl_init();
76*cb72d382SHuw Davies 	if (ret_val != 0)
77*cb72d382SHuw Davies 		return ret_val;
78*cb72d382SHuw Davies 
7916b99a4fSFabian Frederick 	return netlbl_unlabel_genl_init();
80d15c345fSPaul Moore }
8132f50cdeSPaul Moore 
8232f50cdeSPaul Moore /*
8332f50cdeSPaul Moore  * NetLabel Audit Functions
8432f50cdeSPaul Moore  */
8532f50cdeSPaul Moore 
8632f50cdeSPaul Moore /**
8732f50cdeSPaul Moore  * netlbl_audit_start_common - Start an audit message
8832f50cdeSPaul Moore  * @type: audit message type
8995d4e6beSPaul Moore  * @audit_info: NetLabel audit information
9032f50cdeSPaul Moore  *
9132f50cdeSPaul Moore  * Description:
9232f50cdeSPaul Moore  * Start an audit message using the type specified in @type and fill the audit
9332f50cdeSPaul Moore  * message with some fields common to all NetLabel audit messages.  Returns
9432f50cdeSPaul Moore  * a pointer to the audit buffer on success, NULL on failure.
9532f50cdeSPaul Moore  *
9632f50cdeSPaul Moore  */
9795d4e6beSPaul Moore struct audit_buffer *netlbl_audit_start_common(int type,
9895d4e6beSPaul Moore 					       struct netlbl_audit *audit_info)
9932f50cdeSPaul Moore {
10032f50cdeSPaul Moore 	struct audit_buffer *audit_buf;
10132f50cdeSPaul Moore 	char *secctx;
10232f50cdeSPaul Moore 	u32 secctx_len;
10332f50cdeSPaul Moore 
104de64688fSPaul Moore 	if (audit_enabled == 0)
105de64688fSPaul Moore 		return NULL;
106de64688fSPaul Moore 
10794de7febSPavel Emelyanov 	audit_buf = audit_log_start(current->audit_context, GFP_ATOMIC, type);
10832f50cdeSPaul Moore 	if (audit_buf == NULL)
10932f50cdeSPaul Moore 		return NULL;
11032f50cdeSPaul Moore 
1112532386fSEric Paris 	audit_log_format(audit_buf, "netlabel: auid=%u ses=%u",
112e1760bd5SEric W. Biederman 			 from_kuid(&init_user_ns, audit_info->loginuid),
1132532386fSEric Paris 			 audit_info->sessionid);
11432f50cdeSPaul Moore 
11595d4e6beSPaul Moore 	if (audit_info->secid != 0 &&
11695d4e6beSPaul Moore 	    security_secid_to_secctx(audit_info->secid,
11795d4e6beSPaul Moore 				     &secctx,
118e6e0871cSPaul Moore 				     &secctx_len) == 0) {
11932f50cdeSPaul Moore 		audit_log_format(audit_buf, " subj=%s", secctx);
120e6e0871cSPaul Moore 		security_release_secctx(secctx, secctx_len);
121e6e0871cSPaul Moore 	}
12232f50cdeSPaul Moore 
12332f50cdeSPaul Moore 	return audit_buf;
12432f50cdeSPaul Moore }
125