netlabel_user.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  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. *
  9. * Author: Paul Moore <paul@paul-moore.com>
  10. */
  11. /*
  12. * (c) Copyright Hewlett-Packard Development Company, L.P., 2006
  13. */
  14. #include <linux/init.h>
  15. #include <linux/types.h>
  16. #include <linux/list.h>
  17. #include <linux/socket.h>
  18. #include <linux/audit.h>
  19. #include <linux/tty.h>
  20. #include <linux/security.h>
  21. #include <linux/gfp.h>
  22. #include <net/sock.h>
  23. #include <net/netlink.h>
  24. #include <net/genetlink.h>
  25. #include <net/netlabel.h>
  26. #include <asm/bug.h>
  27. #include "netlabel_mgmt.h"
  28. #include "netlabel_unlabeled.h"
  29. #include "netlabel_cipso_v4.h"
  30. #include "netlabel_calipso.h"
  31. #include "netlabel_user.h"
  32. /*
  33. * NetLabel NETLINK Setup Functions
  34. */
  35. /**
  36. * netlbl_netlink_init - Initialize the NETLINK communication channel
  37. *
  38. * Description:
  39. * Call out to the NetLabel components so they can register their families and
  40. * commands with the Generic NETLINK mechanism. Returns zero on success and
  41. * non-zero on failure.
  42. *
  43. */
  44. int __init netlbl_netlink_init(void)
  45. {
  46. int ret_val;
  47. ret_val = netlbl_mgmt_genl_init();
  48. if (ret_val != 0)
  49. return ret_val;
  50. ret_val = netlbl_cipsov4_genl_init();
  51. if (ret_val != 0)
  52. return ret_val;
  53. ret_val = netlbl_calipso_genl_init();
  54. if (ret_val != 0)
  55. return ret_val;
  56. return netlbl_unlabel_genl_init();
  57. }
  58. /*
  59. * NetLabel Audit Functions
  60. */
  61. /**
  62. * netlbl_audit_start_common - Start an audit message
  63. * @type: audit message type
  64. * @audit_info: NetLabel audit information
  65. *
  66. * Description:
  67. * Start an audit message using the type specified in @type and fill the audit
  68. * message with some fields common to all NetLabel audit messages. Returns
  69. * a pointer to the audit buffer on success, NULL on failure.
  70. *
  71. */
  72. struct audit_buffer *netlbl_audit_start_common(int type,
  73. struct netlbl_audit *audit_info)
  74. {
  75. struct audit_buffer *audit_buf;
  76. char *secctx;
  77. u32 secctx_len;
  78. if (audit_enabled == AUDIT_OFF)
  79. return NULL;
  80. audit_buf = audit_log_start(audit_context(), GFP_ATOMIC, type);
  81. if (audit_buf == NULL)
  82. return NULL;
  83. audit_log_format(audit_buf, "netlabel: auid=%u ses=%u",
  84. from_kuid(&init_user_ns, audit_info->loginuid),
  85. audit_info->sessionid);
  86. if (audit_info->secid != 0 &&
  87. security_secid_to_secctx(audit_info->secid,
  88. &secctx,
  89. &secctx_len) == 0) {
  90. audit_log_format(audit_buf, " subj=%s", secctx);
  91. security_release_secctx(secctx, secctx_len);
  92. }
  93. return audit_buf;
  94. }