netlabel_user.c 3.2 KB

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