SCTP.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ====
  3. SCTP
  4. ====
  5. SCTP LSM Support
  6. ================
  7. Security Hooks
  8. --------------
  9. For security module support, three SCTP specific hooks have been implemented::
  10. security_sctp_assoc_request()
  11. security_sctp_bind_connect()
  12. security_sctp_sk_clone()
  13. security_sctp_assoc_established()
  14. The usage of these hooks are described below with the SELinux implementation
  15. described in the `SCTP SELinux Support`_ chapter.
  16. security_sctp_assoc_request()
  17. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. Passes the ``@asoc`` and ``@chunk->skb`` of the association INIT packet to the
  19. security module. Returns 0 on success, error on failure.
  20. ::
  21. @asoc - pointer to sctp association structure.
  22. @skb - pointer to skbuff of association packet.
  23. security_sctp_bind_connect()
  24. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. Passes one or more ipv4/ipv6 addresses to the security module for validation
  26. based on the ``@optname`` that will result in either a bind or connect
  27. service as shown in the permission check tables below.
  28. Returns 0 on success, error on failure.
  29. ::
  30. @sk - Pointer to sock structure.
  31. @optname - Name of the option to validate.
  32. @address - One or more ipv4 / ipv6 addresses.
  33. @addrlen - The total length of address(s). This is calculated on each
  34. ipv4 or ipv6 address using sizeof(struct sockaddr_in) or
  35. sizeof(struct sockaddr_in6).
  36. ------------------------------------------------------------------
  37. | BIND Type Checks |
  38. | @optname | @address contains |
  39. |----------------------------|-----------------------------------|
  40. | SCTP_SOCKOPT_BINDX_ADD | One or more ipv4 / ipv6 addresses |
  41. | SCTP_PRIMARY_ADDR | Single ipv4 or ipv6 address |
  42. | SCTP_SET_PEER_PRIMARY_ADDR | Single ipv4 or ipv6 address |
  43. ------------------------------------------------------------------
  44. ------------------------------------------------------------------
  45. | CONNECT Type Checks |
  46. | @optname | @address contains |
  47. |----------------------------|-----------------------------------|
  48. | SCTP_SOCKOPT_CONNECTX | One or more ipv4 / ipv6 addresses |
  49. | SCTP_PARAM_ADD_IP | One or more ipv4 / ipv6 addresses |
  50. | SCTP_SENDMSG_CONNECT | Single ipv4 or ipv6 address |
  51. | SCTP_PARAM_SET_PRIMARY | Single ipv4 or ipv6 address |
  52. ------------------------------------------------------------------
  53. A summary of the ``@optname`` entries is as follows::
  54. SCTP_SOCKOPT_BINDX_ADD - Allows additional bind addresses to be
  55. associated after (optionally) calling
  56. bind(3).
  57. sctp_bindx(3) adds a set of bind
  58. addresses on a socket.
  59. SCTP_SOCKOPT_CONNECTX - Allows the allocation of multiple
  60. addresses for reaching a peer
  61. (multi-homed).
  62. sctp_connectx(3) initiates a connection
  63. on an SCTP socket using multiple
  64. destination addresses.
  65. SCTP_SENDMSG_CONNECT - Initiate a connection that is generated by a
  66. sendmsg(2) or sctp_sendmsg(3) on a new asociation.
  67. SCTP_PRIMARY_ADDR - Set local primary address.
  68. SCTP_SET_PEER_PRIMARY_ADDR - Request peer sets address as
  69. association primary.
  70. SCTP_PARAM_ADD_IP - These are used when Dynamic Address
  71. SCTP_PARAM_SET_PRIMARY - Reconfiguration is enabled as explained below.
  72. To support Dynamic Address Reconfiguration the following parameters must be
  73. enabled on both endpoints (or use the appropriate **setsockopt**\(2))::
  74. /proc/sys/net/sctp/addip_enable
  75. /proc/sys/net/sctp/addip_noauth_enable
  76. then the following *_PARAM_*'s are sent to the peer in an
  77. ASCONF chunk when the corresponding ``@optname``'s are present::
  78. @optname ASCONF Parameter
  79. ---------- ------------------
  80. SCTP_SOCKOPT_BINDX_ADD -> SCTP_PARAM_ADD_IP
  81. SCTP_SET_PEER_PRIMARY_ADDR -> SCTP_PARAM_SET_PRIMARY
  82. security_sctp_sk_clone()
  83. ~~~~~~~~~~~~~~~~~~~~~~~~
  84. Called whenever a new socket is created by **accept**\(2)
  85. (i.e. a TCP style socket) or when a socket is 'peeled off' e.g userspace
  86. calls **sctp_peeloff**\(3).
  87. ::
  88. @asoc - pointer to current sctp association structure.
  89. @sk - pointer to current sock structure.
  90. @newsk - pointer to new sock structure.
  91. security_sctp_assoc_established()
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. Called when a COOKIE ACK is received, and the peer secid will be
  94. saved into ``@asoc->peer_secid`` for client::
  95. @asoc - pointer to sctp association structure.
  96. @skb - pointer to skbuff of the COOKIE ACK packet.
  97. Security Hooks used for Association Establishment
  98. -------------------------------------------------
  99. The following diagram shows the use of ``security_sctp_bind_connect()``,
  100. ``security_sctp_assoc_request()``, ``security_sctp_assoc_established()`` when
  101. establishing an association.
  102. ::
  103. SCTP endpoint "A" SCTP endpoint "Z"
  104. ================= =================
  105. sctp_sf_do_prm_asoc()
  106. Association setup can be initiated
  107. by a connect(2), sctp_connectx(3),
  108. sendmsg(2) or sctp_sendmsg(3).
  109. These will result in a call to
  110. security_sctp_bind_connect() to
  111. initiate an association to
  112. SCTP peer endpoint "Z".
  113. INIT --------------------------------------------->
  114. sctp_sf_do_5_1B_init()
  115. Respond to an INIT chunk.
  116. SCTP peer endpoint "A" is asking
  117. for a temporary association.
  118. Call security_sctp_assoc_request()
  119. to set the peer label if first
  120. association.
  121. If not first association, check
  122. whether allowed, IF so send:
  123. <----------------------------------------------- INIT ACK
  124. | ELSE audit event and silently
  125. | discard the packet.
  126. |
  127. COOKIE ECHO ------------------------------------------>
  128. sctp_sf_do_5_1D_ce()
  129. Respond to an COOKIE ECHO chunk.
  130. Confirm the cookie and create a
  131. permanent association.
  132. Call security_sctp_assoc_request() to
  133. do the same as for INIT chunk Response.
  134. <------------------------------------------- COOKIE ACK
  135. | |
  136. sctp_sf_do_5_1E_ca |
  137. Call security_sctp_assoc_established() |
  138. to set the peer label. |
  139. | |
  140. | If SCTP_SOCKET_TCP or peeled off
  141. | socket security_sctp_sk_clone() is
  142. | called to clone the new socket.
  143. | |
  144. ESTABLISHED ESTABLISHED
  145. | |
  146. ------------------------------------------------------------------
  147. | Association Established |
  148. ------------------------------------------------------------------
  149. SCTP SELinux Support
  150. ====================
  151. Security Hooks
  152. --------------
  153. The `SCTP LSM Support`_ chapter above describes the following SCTP security
  154. hooks with the SELinux specifics expanded below::
  155. security_sctp_assoc_request()
  156. security_sctp_bind_connect()
  157. security_sctp_sk_clone()
  158. security_sctp_assoc_established()
  159. security_sctp_assoc_request()
  160. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161. Passes the ``@asoc`` and ``@chunk->skb`` of the association INIT packet to the
  162. security module. Returns 0 on success, error on failure.
  163. ::
  164. @asoc - pointer to sctp association structure.
  165. @skb - pointer to skbuff of association packet.
  166. The security module performs the following operations:
  167. IF this is the first association on ``@asoc->base.sk``, then set the peer
  168. sid to that in ``@skb``. This will ensure there is only one peer sid
  169. assigned to ``@asoc->base.sk`` that may support multiple associations.
  170. ELSE validate the ``@asoc->base.sk peer_sid`` against the ``@skb peer sid``
  171. to determine whether the association should be allowed or denied.
  172. Set the sctp ``@asoc sid`` to socket's sid (from ``asoc->base.sk``) with
  173. MLS portion taken from ``@skb peer sid``. This will be used by SCTP
  174. TCP style sockets and peeled off connections as they cause a new socket
  175. to be generated.
  176. If IP security options are configured (CIPSO/CALIPSO), then the ip
  177. options are set on the socket.
  178. security_sctp_bind_connect()
  179. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  180. Checks permissions required for ipv4/ipv6 addresses based on the ``@optname``
  181. as follows::
  182. ------------------------------------------------------------------
  183. | BIND Permission Checks |
  184. | @optname | @address contains |
  185. |----------------------------|-----------------------------------|
  186. | SCTP_SOCKOPT_BINDX_ADD | One or more ipv4 / ipv6 addresses |
  187. | SCTP_PRIMARY_ADDR | Single ipv4 or ipv6 address |
  188. | SCTP_SET_PEER_PRIMARY_ADDR | Single ipv4 or ipv6 address |
  189. ------------------------------------------------------------------
  190. ------------------------------------------------------------------
  191. | CONNECT Permission Checks |
  192. | @optname | @address contains |
  193. |----------------------------|-----------------------------------|
  194. | SCTP_SOCKOPT_CONNECTX | One or more ipv4 / ipv6 addresses |
  195. | SCTP_PARAM_ADD_IP | One or more ipv4 / ipv6 addresses |
  196. | SCTP_SENDMSG_CONNECT | Single ipv4 or ipv6 address |
  197. | SCTP_PARAM_SET_PRIMARY | Single ipv4 or ipv6 address |
  198. ------------------------------------------------------------------
  199. `SCTP LSM Support`_ gives a summary of the ``@optname``
  200. entries and also describes ASCONF chunk processing when Dynamic Address
  201. Reconfiguration is enabled.
  202. security_sctp_sk_clone()
  203. ~~~~~~~~~~~~~~~~~~~~~~~~
  204. Called whenever a new socket is created by **accept**\(2) (i.e. a TCP style
  205. socket) or when a socket is 'peeled off' e.g userspace calls
  206. **sctp_peeloff**\(3). ``security_sctp_sk_clone()`` will set the new
  207. sockets sid and peer sid to that contained in the ``@asoc sid`` and
  208. ``@asoc peer sid`` respectively.
  209. ::
  210. @asoc - pointer to current sctp association structure.
  211. @sk - pointer to current sock structure.
  212. @newsk - pointer to new sock structure.
  213. security_sctp_assoc_established()
  214. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  215. Called when a COOKIE ACK is received where it sets the connection's peer sid
  216. to that in ``@skb``::
  217. @asoc - pointer to sctp association structure.
  218. @skb - pointer to skbuff of the COOKIE ACK packet.
  219. Policy Statements
  220. -----------------
  221. The following class and permissions to support SCTP are available within the
  222. kernel::
  223. class sctp_socket inherits socket { node_bind }
  224. whenever the following policy capability is enabled::
  225. policycap extended_socket_class;
  226. SELinux SCTP support adds the ``name_connect`` permission for connecting
  227. to a specific port type and the ``association`` permission that is explained
  228. in the section below.
  229. If userspace tools have been updated, SCTP will support the ``portcon``
  230. statement as shown in the following example::
  231. portcon sctp 1024-1036 system_u:object_r:sctp_ports_t:s0
  232. SCTP Peer Labeling
  233. ------------------
  234. An SCTP socket will only have one peer label assigned to it. This will be
  235. assigned during the establishment of the first association. Any further
  236. associations on this socket will have their packet peer label compared to
  237. the sockets peer label, and only if they are different will the
  238. ``association`` permission be validated. This is validated by checking the
  239. socket peer sid against the received packets peer sid to determine whether
  240. the association should be allowed or denied.
  241. NOTES:
  242. 1) If peer labeling is not enabled, then the peer context will always be
  243. ``SECINITSID_UNLABELED`` (``unlabeled_t`` in Reference Policy).
  244. 2) As SCTP can support more than one transport address per endpoint
  245. (multi-homing) on a single socket, it is possible to configure policy
  246. and NetLabel to provide different peer labels for each of these. As the
  247. socket peer label is determined by the first associations transport
  248. address, it is recommended that all peer labels are consistent.
  249. 3) **getpeercon**\(3) may be used by userspace to retrieve the sockets peer
  250. context.
  251. 4) While not SCTP specific, be aware when using NetLabel that if a label
  252. is assigned to a specific interface, and that interface 'goes down',
  253. then the NetLabel service will remove the entry. Therefore ensure that
  254. the network startup scripts call **netlabelctl**\(8) to set the required
  255. label (see **netlabel-config**\(8) helper script for details).
  256. 5) The NetLabel SCTP peer labeling rules apply as discussed in the following
  257. set of posts tagged "netlabel" at: https://www.paul-moore.com/blog/t.
  258. 6) CIPSO is only supported for IPv4 addressing: ``socket(AF_INET, ...)``
  259. CALIPSO is only supported for IPv6 addressing: ``socket(AF_INET6, ...)``
  260. Note the following when testing CIPSO/CALIPSO:
  261. a) CIPSO will send an ICMP packet if an SCTP packet cannot be
  262. delivered because of an invalid label.
  263. b) CALIPSO does not send an ICMP packet, just silently discards it.
  264. 7) IPSEC is not supported as RFC 3554 - sctp/ipsec support has not been
  265. implemented in userspace (**racoon**\(8) or **ipsec_pluto**\(8)),
  266. although the kernel supports SCTP/IPSEC.