Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 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.moore@hp.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, write to the Free Software |
| 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/list.h> |
| 34 | #include <linux/socket.h> |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 35 | #include <linux/audit.h> |
| 36 | #include <linux/tty.h> |
| 37 | #include <linux/security.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/gfp.h> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 39 | #include <net/sock.h> |
| 40 | #include <net/netlink.h> |
| 41 | #include <net/genetlink.h> |
| 42 | #include <net/netlabel.h> |
| 43 | #include <asm/bug.h> |
| 44 | |
| 45 | #include "netlabel_mgmt.h" |
| 46 | #include "netlabel_unlabeled.h" |
| 47 | #include "netlabel_cipso_v4.h" |
| 48 | #include "netlabel_user.h" |
| 49 | |
| 50 | /* |
| 51 | * NetLabel NETLINK Setup Functions |
| 52 | */ |
| 53 | |
| 54 | /** |
| 55 | * netlbl_netlink_init - Initialize the NETLINK communication channel |
| 56 | * |
| 57 | * Description: |
| 58 | * Call out to the NetLabel components so they can register their families and |
| 59 | * commands with the Generic NETLINK mechanism. Returns zero on success and |
| 60 | * non-zero on failure. |
| 61 | * |
| 62 | */ |
Pavel Emelyanov | 05705e4 | 2008-02-17 22:33:57 -0800 | [diff] [blame] | 63 | int __init netlbl_netlink_init(void) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 64 | { |
| 65 | int ret_val; |
| 66 | |
| 67 | ret_val = netlbl_mgmt_genl_init(); |
| 68 | if (ret_val != 0) |
| 69 | return ret_val; |
| 70 | |
| 71 | ret_val = netlbl_cipsov4_genl_init(); |
| 72 | if (ret_val != 0) |
| 73 | return ret_val; |
| 74 | |
| 75 | ret_val = netlbl_unlabel_genl_init(); |
| 76 | if (ret_val != 0) |
| 77 | return ret_val; |
| 78 | |
| 79 | return 0; |
| 80 | } |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * NetLabel Audit Functions |
| 84 | */ |
| 85 | |
| 86 | /** |
| 87 | * netlbl_audit_start_common - Start an audit message |
| 88 | * @type: audit message type |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 89 | * @audit_info: NetLabel audit information |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 90 | * |
| 91 | * Description: |
| 92 | * Start an audit message using the type specified in @type and fill the audit |
| 93 | * message with some fields common to all NetLabel audit messages. Returns |
| 94 | * a pointer to the audit buffer on success, NULL on failure. |
| 95 | * |
| 96 | */ |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 97 | struct audit_buffer *netlbl_audit_start_common(int type, |
| 98 | struct netlbl_audit *audit_info) |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 99 | { |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 100 | struct audit_buffer *audit_buf; |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 101 | char *secctx; |
| 102 | u32 secctx_len; |
| 103 | |
Paul Moore | de64688 | 2006-11-17 17:38:55 -0500 | [diff] [blame] | 104 | if (audit_enabled == 0) |
| 105 | return NULL; |
| 106 | |
Pavel Emelyanov | 94de7fe | 2008-02-12 22:35:37 -0800 | [diff] [blame] | 107 | audit_buf = audit_log_start(current->audit_context, GFP_ATOMIC, type); |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 108 | if (audit_buf == NULL) |
| 109 | return NULL; |
| 110 | |
Eric Paris | 2532386 | 2008-04-18 10:09:25 -0400 | [diff] [blame] | 111 | audit_log_format(audit_buf, "netlabel: auid=%u ses=%u", |
| 112 | audit_info->loginuid, |
| 113 | audit_info->sessionid); |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 114 | |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 115 | if (audit_info->secid != 0 && |
| 116 | security_secid_to_secctx(audit_info->secid, |
| 117 | &secctx, |
Paul Moore | e6e0871 | 2007-08-01 11:12:59 -0400 | [diff] [blame] | 118 | &secctx_len) == 0) { |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 119 | audit_log_format(audit_buf, " subj=%s", secctx); |
Paul Moore | e6e0871 | 2007-08-01 11:12:59 -0400 | [diff] [blame] | 120 | security_release_secctx(secctx, secctx_len); |
| 121 | } |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 122 | |
| 123 | return audit_buf; |
| 124 | } |