2 * NetLabel NETLINK Interface
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.
8 * Author: Paul Moore <paul.moore@hp.com>
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
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.
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.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <linux/init.h>
32 #include <linux/types.h>
33 #include <linux/list.h>
34 #include <linux/socket.h>
35 #include <linux/audit.h>
36 #include <linux/tty.h>
37 #include <linux/security.h>
39 #include <net/netlink.h>
40 #include <net/genetlink.h>
41 #include <net/netlabel.h>
44 #include "netlabel_mgmt.h"
45 #include "netlabel_unlabeled.h"
46 #include "netlabel_cipso_v4.h"
47 #include "netlabel_user.h"
50 * NetLabel NETLINK Setup Functions
54 * netlbl_netlink_init - Initialize the NETLINK communication channel
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.
62 int netlbl_netlink_init(void)
66 ret_val = netlbl_mgmt_genl_init();
70 ret_val = netlbl_cipsov4_genl_init();
74 ret_val = netlbl_unlabel_genl_init();
82 * NetLabel Audit Functions
86 * netlbl_audit_start_common - Start an audit message
87 * @type: audit message type
88 * @secid: LSM context ID
91 * Start an audit message using the type specified in @type and fill the audit
92 * message with some fields common to all NetLabel audit messages. Returns
93 * a pointer to the audit buffer on success, NULL on failure.
96 struct audit_buffer *netlbl_audit_start_common(int type, u32 secid)
98 struct audit_context *audit_ctx = current->audit_context;
99 struct audit_buffer *audit_buf;
100 uid_t audit_loginuid;
101 const char *audit_tty;
102 char audit_comm[sizeof(current->comm)];
103 struct vm_area_struct *vma;
107 audit_buf = audit_log_start(audit_ctx, GFP_ATOMIC, type);
108 if (audit_buf == NULL)
111 audit_loginuid = audit_get_loginuid(audit_ctx);
112 if (current->signal &&
113 current->signal->tty &&
114 current->signal->tty->name)
115 audit_tty = current->signal->tty->name;
117 audit_tty = "(none)";
118 get_task_comm(audit_comm, current);
120 audit_log_format(audit_buf,
121 "netlabel: auid=%u uid=%u tty=%s pid=%d",
126 audit_log_format(audit_buf, " comm=");
127 audit_log_untrustedstring(audit_buf, audit_comm);
129 down_read(¤t->mm->mmap_sem);
130 vma = current->mm->mmap;
132 if ((vma->vm_flags & VM_EXECUTABLE) &&
134 audit_log_d_path(audit_buf,
136 vma->vm_file->f_dentry,
137 vma->vm_file->f_vfsmnt);
142 up_read(¤t->mm->mmap_sem);
146 security_secid_to_secctx(secid, &secctx, &secctx_len) == 0)
147 audit_log_format(audit_buf, " subj=%s", secctx);
153 * netlbl_audit_nomsg - Send an audit message without additional text
154 * @type: audit message type
155 * @secid: LSM context ID
158 * Send an audit message with only the common NetLabel audit fields.
161 void netlbl_audit_nomsg(int type, u32 secid)
163 struct audit_buffer *audit_buf;
165 audit_buf = netlbl_audit_start_common(type, secid);
166 audit_log_end(audit_buf);