Thomas Gleixner | 1ccea77 | 2019-05-19 15:51:43 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 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 | * |
Paul Moore | 82c21bf | 2011-08-01 11:10:33 +0000 | [diff] [blame] | 9 | * Author: Paul Moore <paul@paul-moore.com> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/list.h> |
| 19 | #include <linux/socket.h> |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 20 | #include <linux/audit.h> |
| 21 | #include <linux/tty.h> |
| 22 | #include <linux/security.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/gfp.h> |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 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" |
Huw Davies | cb72d38 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 33 | #include "netlabel_calipso.h" |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 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 | */ |
Pavel Emelyanov | 05705e4 | 2008-02-17 22:33:57 -0800 | [diff] [blame] | 49 | int __init netlbl_netlink_init(void) |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 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 | |
Huw Davies | cb72d38 | 2016-06-27 15:02:46 -0400 | [diff] [blame] | 61 | ret_val = netlbl_calipso_genl_init(); |
| 62 | if (ret_val != 0) |
| 63 | return ret_val; |
| 64 | |
Fabian Frederick | 16b99a4 | 2014-10-08 20:37:01 +0200 | [diff] [blame] | 65 | return netlbl_unlabel_genl_init(); |
Paul Moore | d15c345 | 2006-08-03 16:48:37 -0700 | [diff] [blame] | 66 | } |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * NetLabel Audit Functions |
| 70 | */ |
| 71 | |
| 72 | /** |
| 73 | * netlbl_audit_start_common - Start an audit message |
| 74 | * @type: audit message type |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 75 | * @audit_info: NetLabel audit information |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 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 | */ |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 83 | struct audit_buffer *netlbl_audit_start_common(int type, |
| 84 | struct netlbl_audit *audit_info) |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 85 | { |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 86 | struct audit_buffer *audit_buf; |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 87 | char *secctx; |
| 88 | u32 secctx_len; |
| 89 | |
Richard Guy Briggs | f785959 | 2018-06-05 19:20:39 -0400 | [diff] [blame] | 90 | if (audit_enabled == AUDIT_OFF) |
Paul Moore | de64688 | 2006-11-17 17:38:55 -0500 | [diff] [blame] | 91 | return NULL; |
| 92 | |
Richard Guy Briggs | cdfb6b3 | 2018-05-12 21:58:20 -0400 | [diff] [blame] | 93 | audit_buf = audit_log_start(audit_context(), GFP_ATOMIC, type); |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 94 | if (audit_buf == NULL) |
| 95 | return NULL; |
| 96 | |
Eric Paris | 2532386 | 2008-04-18 10:09:25 -0400 | [diff] [blame] | 97 | audit_log_format(audit_buf, "netlabel: auid=%u ses=%u", |
Eric W. Biederman | e1760bd | 2012-09-10 22:39:43 -0700 | [diff] [blame] | 98 | from_kuid(&init_user_ns, audit_info->loginuid), |
Eric Paris | 2532386 | 2008-04-18 10:09:25 -0400 | [diff] [blame] | 99 | audit_info->sessionid); |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 100 | |
Paul Moore | 95d4e6b | 2006-09-29 17:05:05 -0700 | [diff] [blame] | 101 | if (audit_info->secid != 0 && |
| 102 | security_secid_to_secctx(audit_info->secid, |
| 103 | &secctx, |
Paul Moore | e6e0871 | 2007-08-01 11:12:59 -0400 | [diff] [blame] | 104 | &secctx_len) == 0) { |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 105 | audit_log_format(audit_buf, " subj=%s", secctx); |
Paul Moore | e6e0871 | 2007-08-01 11:12:59 -0400 | [diff] [blame] | 106 | security_release_secctx(secctx, secctx_len); |
| 107 | } |
Paul Moore | 32f50cd | 2006-09-28 14:51:47 -0700 | [diff] [blame] | 108 | |
| 109 | return audit_buf; |
| 110 | } |