PageRenderTime 23ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/security/selinux/include/objsec.h

http://github.com/torvalds/linux
C Header | 192 lines | 148 code | 26 blank | 18 comment | 1 complexity | 0d30dd1e94baec0dbeca02aeb90098e6 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * NSA Security-Enhanced Linux (SELinux) security module
  4. *
  5. * This file contains the SELinux security data structures for kernel objects.
  6. *
  7. * Author(s): Stephen Smalley, <sds@tycho.nsa.gov>
  8. * Chris Vance, <cvance@nai.com>
  9. * Wayne Salamon, <wsalamon@nai.com>
  10. * James Morris <jmorris@redhat.com>
  11. *
  12. * Copyright (C) 2001,2002 Networks Associates Technology, Inc.
  13. * Copyright (C) 2003 Red Hat, Inc., James Morris <jmorris@redhat.com>
  14. * Copyright (C) 2016 Mellanox Technologies
  15. */
  16. #ifndef _SELINUX_OBJSEC_H_
  17. #define _SELINUX_OBJSEC_H_
  18. #include <linux/list.h>
  19. #include <linux/sched.h>
  20. #include <linux/fs.h>
  21. #include <linux/binfmts.h>
  22. #include <linux/in.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/lsm_hooks.h>
  25. #include <linux/msg.h>
  26. #include <net/net_namespace.h>
  27. #include "flask.h"
  28. #include "avc.h"
  29. struct task_security_struct {
  30. u32 osid; /* SID prior to last execve */
  31. u32 sid; /* current SID */
  32. u32 exec_sid; /* exec SID */
  33. u32 create_sid; /* fscreate SID */
  34. u32 keycreate_sid; /* keycreate SID */
  35. u32 sockcreate_sid; /* fscreate SID */
  36. } __randomize_layout;
  37. enum label_initialized {
  38. LABEL_INVALID, /* invalid or not initialized */
  39. LABEL_INITIALIZED, /* initialized */
  40. LABEL_PENDING
  41. };
  42. struct inode_security_struct {
  43. struct inode *inode; /* back pointer to inode object */
  44. struct list_head list; /* list of inode_security_struct */
  45. u32 task_sid; /* SID of creating task */
  46. u32 sid; /* SID of this object */
  47. u16 sclass; /* security class of this object */
  48. unsigned char initialized; /* initialization flag */
  49. spinlock_t lock;
  50. };
  51. struct file_security_struct {
  52. u32 sid; /* SID of open file description */
  53. u32 fown_sid; /* SID of file owner (for SIGIO) */
  54. u32 isid; /* SID of inode at the time of file open */
  55. u32 pseqno; /* Policy seqno at the time of file open */
  56. };
  57. struct superblock_security_struct {
  58. struct super_block *sb; /* back pointer to sb object */
  59. u32 sid; /* SID of file system superblock */
  60. u32 def_sid; /* default SID for labeling */
  61. u32 mntpoint_sid; /* SECURITY_FS_USE_MNTPOINT context for files */
  62. unsigned short behavior; /* labeling behavior */
  63. unsigned short flags; /* which mount options were specified */
  64. struct mutex lock;
  65. struct list_head isec_head;
  66. spinlock_t isec_lock;
  67. };
  68. struct msg_security_struct {
  69. u32 sid; /* SID of message */
  70. };
  71. struct ipc_security_struct {
  72. u16 sclass; /* security class of this object */
  73. u32 sid; /* SID of IPC resource */
  74. };
  75. struct netif_security_struct {
  76. struct net *ns; /* network namespace */
  77. int ifindex; /* device index */
  78. u32 sid; /* SID for this interface */
  79. };
  80. struct netnode_security_struct {
  81. union {
  82. __be32 ipv4; /* IPv4 node address */
  83. struct in6_addr ipv6; /* IPv6 node address */
  84. } addr;
  85. u32 sid; /* SID for this node */
  86. u16 family; /* address family */
  87. };
  88. struct netport_security_struct {
  89. u32 sid; /* SID for this node */
  90. u16 port; /* port number */
  91. u8 protocol; /* transport protocol */
  92. };
  93. struct sk_security_struct {
  94. #ifdef CONFIG_NETLABEL
  95. enum { /* NetLabel state */
  96. NLBL_UNSET = 0,
  97. NLBL_REQUIRE,
  98. NLBL_LABELED,
  99. NLBL_REQSKB,
  100. NLBL_CONNLABELED,
  101. } nlbl_state;
  102. struct netlbl_lsm_secattr *nlbl_secattr; /* NetLabel sec attributes */
  103. #endif
  104. u32 sid; /* SID of this object */
  105. u32 peer_sid; /* SID of peer */
  106. u16 sclass; /* sock security class */
  107. enum { /* SCTP association state */
  108. SCTP_ASSOC_UNSET = 0,
  109. SCTP_ASSOC_SET,
  110. } sctp_assoc_state;
  111. };
  112. struct tun_security_struct {
  113. u32 sid; /* SID for the tun device sockets */
  114. };
  115. struct key_security_struct {
  116. u32 sid; /* SID of key */
  117. };
  118. struct ib_security_struct {
  119. u32 sid; /* SID of the queue pair or MAD agent */
  120. };
  121. struct pkey_security_struct {
  122. u64 subnet_prefix; /* Port subnet prefix */
  123. u16 pkey; /* PKey number */
  124. u32 sid; /* SID of pkey */
  125. };
  126. struct bpf_security_struct {
  127. u32 sid; /* SID of bpf obj creator */
  128. };
  129. struct perf_event_security_struct {
  130. u32 sid; /* SID of perf_event obj creator */
  131. };
  132. extern struct lsm_blob_sizes selinux_blob_sizes;
  133. static inline struct task_security_struct *selinux_cred(const struct cred *cred)
  134. {
  135. return cred->security + selinux_blob_sizes.lbs_cred;
  136. }
  137. static inline struct file_security_struct *selinux_file(const struct file *file)
  138. {
  139. return file->f_security + selinux_blob_sizes.lbs_file;
  140. }
  141. static inline struct inode_security_struct *selinux_inode(
  142. const struct inode *inode)
  143. {
  144. if (unlikely(!inode->i_security))
  145. return NULL;
  146. return inode->i_security + selinux_blob_sizes.lbs_inode;
  147. }
  148. static inline struct msg_security_struct *selinux_msg_msg(
  149. const struct msg_msg *msg_msg)
  150. {
  151. return msg_msg->security + selinux_blob_sizes.lbs_msg_msg;
  152. }
  153. static inline struct ipc_security_struct *selinux_ipc(
  154. const struct kern_ipc_perm *ipc)
  155. {
  156. return ipc->security + selinux_blob_sizes.lbs_ipc;
  157. }
  158. /*
  159. * get the subjective security ID of the current task
  160. */
  161. static inline u32 current_sid(void)
  162. {
  163. const struct task_security_struct *tsec = selinux_cred(current_cred());
  164. return tsec->sid;
  165. }
  166. #endif /* _SELINUX_OBJSEC_H_ */