← Documents Documentation/security/SCTP.rst GitHub 원문 ↗

Linux 6.18.37 · Security

SCTP LSM 및 SELinux 지원

SCTP 전용 LSM hook의 호출 지점, association 수립 시퀀스, SELinux SID·policy·peer labeling과 CIPSO/CALIPSO 제약을 설명합니다.

Source pathDocumentation/security/SCTP.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

SCTP.rst:1-344

SCTP는 하나의 socket에서 여러 association과 여러 transport 주소를 다룰 수 있어 일반 socket 검사 외에 association 요청·주소 변경·socket clone·peer SID 확정을 위한 전용 LSM hook이 필요합니다.

SELinux는 첫 association의 peer label을 socket에 고정하고 이후 association의 label이 다를 때 `association` permission을 검사합니다. Multi-homing 환경에서는 주소별 NetLabel을 일관되게 구성하고, CIPSO는 IPv4·CALIPSO는 IPv6에만 적용된다는 점을 함께 확인해야 합니다.

보안 검사 지점
bind/connect 주소 permissionINIT·COOKIE ECHO association 검사COOKIE ACK peer SID 확정accept·peeloff socket SID 복제후속 association label 비교

주소 선택부터 association 확정과 새 socket 생성까지 label을 연속적으로 유지한다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

SCTP 전용 security hook

1-22

SCTP에 security module을 연결하기 위해 네 개의 전용 hook이 구현되어 있다. 원문은 ‘three’라고 표현하지만 목록에는 `security_sctp_assoc_request()`, `security_sctp_bind_connect()`, `security_sctp_sk_clone()`, `security_sctp_assoc_established()` 네 개가 제시된다. 이 번역은 실제 목록을 기준으로 네 hook을 모두 보존한다.

각 hook은 association 요청, bind/connect 주소 검증, 새 socket으로의 보안 상태 복제, association 수립 뒤 peer 보안 ID 저장을 담당한다. 일반 LSM 동작은 앞부분에서 설명하고, 뒤의 SCTP SELinux Support 절에서 SELinux가 SID와 label을 처리하는 구체적인 방식을 확장해 설명한다.

SCTP security hook
Hook역할
security_sctp_assoc_requestINIT·COOKIE ECHO association 요청 검사
security_sctp_bind_connectIPv4/IPv6 bind·connect 주소 검증
security_sctp_sk_cloneaccept·peeloff 새 socket 보안 상태 복제
security_sctp_assoc_establishedCOOKIE ACK의 peer secid 저장

association 생명 주기의 각 지점에서 LSM 검사를 수행한다.

.. SPDX-License-Identifier: GPL-2.0

====
SCTP
====

SCTP LSM Support
================

Security Hooks
--------------

For security module support, three SCTP specific hooks have been implemented::

    security_sctp_assoc_request()
    security_sctp_bind_connect()
    security_sctp_sk_clone()
    security_sctp_assoc_established()

The usage of these hooks are described below with the SELinux implementation
described in the `SCTP SELinux Support`_ chapter.

Association 요청과 bind/connect 주소 검사

23-67

`security_sctp_assoc_request()`는 association INIT packet의 `@asoc`과 `@chunk->skb`를 security module에 전달한다. `@asoc`은 SCTP association 구조체 pointer, `@skb`는 association packet의 skbuff pointer다. 성공하면 0, 실패하면 error를 반환한다.

`security_sctp_bind_connect()`는 `@optname`에 따라 bind 또는 connect service가 될 하나 이상의 IPv4/IPv6 주소를 security module에 넘겨 검증한다. 인자는 현재 `@sk`, 검증할 option 이름 `@optname`, 하나 이상의 `@address`, 전체 주소 길이 `@addrlen`이다. 길이는 각 주소에 `sizeof(struct sockaddr_in)` 또는 `sizeof(struct sockaddr_in6)`을 적용해 계산한다.

BIND 유형에서 `SCTP_SOCKOPT_BINDX_ADD`는 하나 이상의 주소를 받고, `SCTP_PRIMARY_ADDR`와 `SCTP_SET_PEER_PRIMARY_ADDR`는 단일 주소를 받는다. CONNECT 유형에서 `SCTP_SOCKOPT_CONNECTX`와 `SCTP_PARAM_ADD_IP`는 하나 이상의 주소, `SCTP_SENDMSG_CONNECT`와 `SCTP_PARAM_SET_PRIMARY`는 단일 주소를 받는다.

BIND 유형 검사
optnameaddress 내용
SCTP_SOCKOPT_BINDX_ADDIPv4/IPv6 하나 이상
SCTP_PRIMARY_ADDRIPv4 또는 IPv6 하나
SCTP_SET_PEER_PRIMARY_ADDRIPv4 또는 IPv6 하나

optname별 주소 개수 요구 사항이다.

CONNECT 유형 검사
optnameaddress 내용
SCTP_SOCKOPT_CONNECTXIPv4/IPv6 하나 이상
SCTP_PARAM_ADD_IPIPv4/IPv6 하나 이상
SCTP_SENDMSG_CONNECTIPv4 또는 IPv6 하나
SCTP_PARAM_SET_PRIMARYIPv4 또는 IPv6 하나

연결과 동적 주소 변경에 쓰이는 주소 개수 요구 사항이다.


security_sctp_assoc_request()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Passes the ``@asoc`` and ``@chunk->skb`` of the association INIT packet to the
security module. Returns 0 on success, error on failure.
::

    @asoc - pointer to sctp association structure.
    @skb - pointer to skbuff of association packet.


security_sctp_bind_connect()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Passes one or more ipv4/ipv6 addresses to the security module for validation
based on the ``@optname`` that will result in either a bind or connect
service as shown in the permission check tables below.
Returns 0 on success, error on failure.
::

    @sk      - Pointer to sock structure.
    @optname - Name of the option to validate.
    @address - One or more ipv4 / ipv6 addresses.
    @addrlen - The total length of address(s). This is calculated on each
               ipv4 or ipv6 address using sizeof(struct sockaddr_in) or
               sizeof(struct sockaddr_in6).

  ------------------------------------------------------------------
  |                     BIND Type Checks                           |
  |       @optname             |         @address contains         |
  |----------------------------|-----------------------------------|
  | SCTP_SOCKOPT_BINDX_ADD     | One or more ipv4 / ipv6 addresses |
  | SCTP_PRIMARY_ADDR          | Single ipv4 or ipv6 address       |
  | SCTP_SET_PEER_PRIMARY_ADDR | Single ipv4 or ipv6 address       |
  ------------------------------------------------------------------

  ------------------------------------------------------------------
  |                   CONNECT Type Checks                          |
  |       @optname             |         @address contains         |
  |----------------------------|-----------------------------------|
  | SCTP_SOCKOPT_CONNECTX      | One or more ipv4 / ipv6 addresses |
  | SCTP_PARAM_ADD_IP          | One or more ipv4 / ipv6 addresses |
  | SCTP_SENDMSG_CONNECT       | Single ipv4 or ipv6 address       |
  | SCTP_PARAM_SET_PRIMARY     | Single ipv4 or ipv6 address       |
  ------------------------------------------------------------------

optname 의미와 Dynamic Address Reconfiguration

68-109

`SCTP_SOCKOPT_BINDX_ADD`는 선택적으로 `bind(3)`을 호출한 뒤 추가 bind 주소를 association에 연결한다. `sctp_bindx(3)`는 socket에 bind 주소 집합을 추가한다. `SCTP_SOCKOPT_CONNECTX`는 multi-homed peer에 도달할 여러 주소를 할당하고, `sctp_connectx(3)`는 여러 목적지 주소로 SCTP 연결을 시작한다.

`SCTP_SENDMSG_CONNECT`는 새 association에서 `sendmsg(2)` 또는 `sctp_sendmsg(3)`가 생성하는 연결을 시작한다. `SCTP_PRIMARY_ADDR`는 local primary 주소를 설정하고, `SCTP_SET_PEER_PRIMARY_ADDR`는 peer에게 지정 주소를 association primary로 설정하도록 요청한다. `SCTP_PARAM_ADD_IP`와 `SCTP_PARAM_SET_PRIMARY`는 Dynamic Address Reconfiguration이 켜졌을 때 사용한다.

동적 주소 재구성을 지원하려면 양 endpoint에서 `/proc/sys/net/sctp/addip_enable`과 `/proc/sys/net/sctp/addip_noauth_enable`을 켜거나 적절한 `setsockopt(2)`를 사용해야 한다. 이후 `SCTP_SOCKOPT_BINDX_ADD`는 ASCONF chunk의 `SCTP_PARAM_ADD_IP`로, `SCTP_SET_PEER_PRIMARY_ADDR`는 `SCTP_PARAM_SET_PRIMARY`로 peer에 전달된다.

ASCONF 변환
optnameASCONF parameter
SCTP_SOCKOPT_BINDX_ADDSCTP_PARAM_ADD_IP
SCTP_SET_PEER_PRIMARY_ADDRSCTP_PARAM_SET_PRIMARY

local optname이 peer로 보내는 ASCONF parameter로 변환된다.

동적 주소 재구성
addip_enable·addip_noauth_enable 설정bindx 또는 peer primary 요청security_sctp_bind_connect 검사ASCONF parameter 생성peer가 주소 구성을 갱신

양 endpoint가 기능을 허용한 뒤 주소 변경을 ASCONF로 전달한다.

A summary of the ``@optname`` entries is as follows::

    SCTP_SOCKOPT_BINDX_ADD - Allows additional bind addresses to be
                             associated after (optionally) calling
                             bind(3).
                             sctp_bindx(3) adds a set of bind
                             addresses on a socket.

    SCTP_SOCKOPT_CONNECTX - Allows the allocation of multiple
                            addresses for reaching a peer
                            (multi-homed).
                            sctp_connectx(3) initiates a connection
                            on an SCTP socket using multiple
                            destination addresses.

    SCTP_SENDMSG_CONNECT  - Initiate a connection that is generated by a
                            sendmsg(2) or sctp_sendmsg(3) on a new association.

    SCTP_PRIMARY_ADDR     - Set local primary address.

    SCTP_SET_PEER_PRIMARY_ADDR - Request peer sets address as
                                 association primary.

    SCTP_PARAM_ADD_IP          - These are used when Dynamic Address
    SCTP_PARAM_SET_PRIMARY     - Reconfiguration is enabled as explained below.


To support Dynamic Address Reconfiguration the following parameters must be
enabled on both endpoints (or use the appropriate **setsockopt**\(2))::

    /proc/sys/net/sctp/addip_enable
    /proc/sys/net/sctp/addip_noauth_enable

then the following *_PARAM_*'s are sent to the peer in an
ASCONF chunk when the corresponding ``@optname``'s are present::

          @optname                      ASCONF Parameter
         ----------                    ------------------
    SCTP_SOCKOPT_BINDX_ADD     ->   SCTP_PARAM_ADD_IP
    SCTP_SET_PEER_PRIMARY_ADDR ->   SCTP_PARAM_SET_PRIMARY

Socket clone과 association 수립 hook

110-130

`security_sctp_sk_clone()`은 `accept(2)`가 TCP-style socket을 새로 만들거나 사용자 공간이 `sctp_peeloff(3)`를 호출해 association을 별도 socket으로 떼어낼 때 호출된다. 현재 association `@asoc`, 현재 socket `@sk`, 새 socket `@newsk`를 전달한다.

`security_sctp_assoc_established()`는 COOKIE ACK를 받았을 때 호출되며, client에서는 packet의 peer secid를 `@asoc->peer_secid`에 저장한다. 인자는 association 구조체 `@asoc`과 COOKIE ACK packet의 skbuff `@skb`다.

새 SCTP socket 생성
association 존재accept(2) 또는 sctp_peeloff(3)새 sock 구조 생성security_sctp_sk_clone 호출새 socket에 보안 상태 복제

association의 보안 상태를 accept 또는 peeloff 결과 socket에 연결한다.

security_sctp_sk_clone()
~~~~~~~~~~~~~~~~~~~~~~~~
Called whenever a new socket is created by **accept**\(2)
(i.e. a TCP style socket) or when a socket is 'peeled off' e.g userspace
calls **sctp_peeloff**\(3).
::

    @asoc - pointer to current sctp association structure.
    @sk - pointer to current sock structure.
    @newsk - pointer to new sock structure.


security_sctp_assoc_established()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Called when a COOKIE ACK is received, and the peer secid will be
saved into ``@asoc->peer_secid`` for client::

    @asoc - pointer to sctp association structure.
    @skb - pointer to skbuff of the COOKIE ACK packet.

Association 수립 시 hook 호출 순서

131-186

endpoint A에서 `connect(2)`, `sctp_connectx(3)`, `sendmsg(2)`, `sctp_sendmsg(3)` 중 하나가 association 설정을 시작하면 `sctp_sf_do_prm_asoc()`이 `security_sctp_bind_connect()`를 호출해 endpoint Z로 연결할 주소를 검사하고 INIT을 보낸다.

Z의 `sctp_sf_do_5_1B_init()`은 INIT에 응답하면서 임시 association을 요청받는다. 첫 association이면 `security_sctp_assoc_request()`로 peer label을 설정한다. 첫 association이 아니면 허용 여부를 검사해 허용 시 INIT ACK을 보내고, 거부 시 audit event를 남긴 뒤 packet을 조용히 폐기한다.

A가 COOKIE ECHO를 보내면 Z의 `sctp_sf_do_5_1D_ce()`가 cookie를 확인해 영구 association을 만들고 INIT 때와 같은 검사를 위해 다시 `security_sctp_assoc_request()`를 호출한 뒤 COOKIE ACK을 보낸다. A의 `sctp_sf_do_5_1E_ca`는 `security_sctp_assoc_established()`로 peer label을 설정한다. TCP-style 또는 peeled-off socket이면 `security_sctp_sk_clone()`이 새 socket의 상태를 복제하고 양 endpoint가 ESTABLISHED에 도달한다.

SCTP association 수립
A: bind_connect 검사 후 INITZ: assoc_request 검사 후 INIT ACKA: COOKIE ECHOZ: assoc_request 재검사·영구 association·COOKIE ACKA: assoc_established로 peer label 저장필요 시 sk_cloneA·Z: ESTABLISHED

원문의 양방향 ASCII 시퀀스를 hook 호출 순서로 구조화했다.

Security Hooks used for Association Establishment
-------------------------------------------------

The following diagram shows the use of ``security_sctp_bind_connect()``,
``security_sctp_assoc_request()``, ``security_sctp_assoc_established()`` when
establishing an association.
::

      SCTP endpoint "A"                                SCTP endpoint "Z"
      =================                                =================
    sctp_sf_do_prm_asoc()
 Association setup can be initiated
 by a connect(2), sctp_connectx(3),
 sendmsg(2) or sctp_sendmsg(3).
 These will result in a call to
 security_sctp_bind_connect() to
 initiate an association to
 SCTP peer endpoint "Z".
         INIT --------------------------------------------->
                                                   sctp_sf_do_5_1B_init()
                                                 Respond to an INIT chunk.
                                             SCTP peer endpoint "A" is asking
                                             for a temporary association.
                                             Call security_sctp_assoc_request()
                                             to set the peer label if first
                                             association.
                                             If not first association, check
                                             whether allowed, IF so send:
          <----------------------------------------------- INIT ACK
          |                                  ELSE audit event and silently
          |                                       discard the packet.
          |
    COOKIE ECHO ------------------------------------------>
                                                  sctp_sf_do_5_1D_ce()
                                             Respond to an COOKIE ECHO chunk.
                                             Confirm the cookie and create a
                                             permanent association.
                                             Call security_sctp_assoc_request() to
                                             do the same as for INIT chunk Response.
          <------------------------------------------- COOKIE ACK
          |                                               |
    sctp_sf_do_5_1E_ca                                    |
 Call security_sctp_assoc_established()                   |
 to set the peer label.                                   |
          |                                               |
          |                               If SCTP_SOCKET_TCP or peeled off
          |                               socket security_sctp_sk_clone() is
          |                               called to clone the new socket.
          |                                               |
      ESTABLISHED                                    ESTABLISHED
          |                                               |
    ------------------------------------------------------------------
    |                     Association Established                    |
    ------------------------------------------------------------------

SELinux association 요청 처리

187-227

SELinux 구현에서도 네 SCTP hook을 사용한다. `security_sctp_assoc_request()`는 INIT packet의 association과 skbuff를 받아 성공 시 0, 실패 시 error를 반환한다.

현재 `@asoc->base.sk`의 첫 association이면 `@skb`의 peer SID를 socket의 peer SID로 설정한다. 여러 association을 지원하는 하나의 `@asoc->base.sk`에는 peer SID 하나만 지정된다. 이후 association이면 기존 `@asoc->base.sk peer_sid`와 새 `@skb peer sid`를 비교해 허용 또는 거부를 결정한다.

SCTP `@asoc sid`는 `asoc->base.sk`의 socket SID를 기반으로 하되 MLS 부분은 `@skb peer sid`에서 가져온다. 이 SID는 새 socket을 생성하는 SCTP TCP-style socket과 peeled-off 연결에서 사용한다. CIPSO 또는 CALIPSO IP security option이 구성되어 있으면 해당 IP option도 socket에 설정한다.

SELinux SID 구성
첫 association의 packet peer SID 확인socket peer SID 설정 또는 기존 값 비교socket SID에서 asoc SID 기반 취득packet peer SID의 MLS 부분 결합CIPSO/CALIPSO option 적용

socket SID와 packet peer SID를 결합해 association과 후속 socket의 label을 만든다.

SCTP SELinux Support
====================

Security Hooks
--------------

The `SCTP LSM Support`_ chapter above describes the following SCTP security
hooks with the SELinux specifics expanded below::

    security_sctp_assoc_request()
    security_sctp_bind_connect()
    security_sctp_sk_clone()
    security_sctp_assoc_established()


security_sctp_assoc_request()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Passes the ``@asoc`` and ``@chunk->skb`` of the association INIT packet to the
security module. Returns 0 on success, error on failure.
::

    @asoc - pointer to sctp association structure.
    @skb - pointer to skbuff of association packet.

The security module performs the following operations:
     IF this is the first association on ``@asoc->base.sk``, then set the peer
     sid to that in ``@skb``. This will ensure there is only one peer sid
     assigned to ``@asoc->base.sk`` that may support multiple associations.

     ELSE validate the ``@asoc->base.sk peer_sid`` against the ``@skb peer sid``
     to determine whether the association should be allowed or denied.

     Set the sctp ``@asoc sid`` to socket's sid (from ``asoc->base.sk``) with
     MLS portion taken from ``@skb peer sid``. This will be used by SCTP
     TCP style sockets and peeled off connections as they cause a new socket
     to be generated.

     If IP security options are configured (CIPSO/CALIPSO), then the ip
     options are set on the socket.

SELinux bind, clone, established 처리

228-280

SELinux의 `security_sctp_bind_connect()`는 일반 LSM 절의 같은 BIND/CONNECT 표에 따라 `@optname`별 IPv4/IPv6 주소 권한을 검사한다. Dynamic Address Reconfiguration이 켜졌을 때 ASCONF chunk를 처리하는 방식도 앞 절의 설명을 따른다.

`security_sctp_sk_clone()`은 `accept(2)` 또는 `sctp_peeloff(3)`로 새 socket이 생길 때 association의 SID와 peer SID를 각각 새 socket의 SID와 peer SID로 설정한다. 현재 association, 기존 socket, 새 socket pointer가 전달된다.

`security_sctp_assoc_established()`는 COOKIE ACK 수신 시 연결의 peer SID를 `@skb`에 든 값으로 설정하며 association과 COOKIE ACK skbuff를 인자로 받는다.

SELinux hook의 SID 효과
Hook주요 결과
bind_connect주소별 bind/connect permission 검사
sk_cloneasoc SID·peer SID를 new socket에 복제
assoc_establishedCOOKIE ACK peer SID를 connection에 저장

검사 이후 어느 객체의 보안 식별자가 갱신되는지 보여 준다.

security_sctp_bind_connect()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Checks permissions required for ipv4/ipv6 addresses based on the ``@optname``
as follows::

  ------------------------------------------------------------------
  |                   BIND Permission Checks                       |
  |       @optname             |         @address contains         |
  |----------------------------|-----------------------------------|
  | SCTP_SOCKOPT_BINDX_ADD     | One or more ipv4 / ipv6 addresses |
  | SCTP_PRIMARY_ADDR          | Single ipv4 or ipv6 address       |
  | SCTP_SET_PEER_PRIMARY_ADDR | Single ipv4 or ipv6 address       |
  ------------------------------------------------------------------

  ------------------------------------------------------------------
  |                 CONNECT Permission Checks                      |
  |       @optname             |         @address contains         |
  |----------------------------|-----------------------------------|
  | SCTP_SOCKOPT_CONNECTX      | One or more ipv4 / ipv6 addresses |
  | SCTP_PARAM_ADD_IP          | One or more ipv4 / ipv6 addresses |
  | SCTP_SENDMSG_CONNECT       | Single ipv4 or ipv6 address       |
  | SCTP_PARAM_SET_PRIMARY     | Single ipv4 or ipv6 address       |
  ------------------------------------------------------------------


`SCTP LSM Support`_ gives a summary of the ``@optname``
entries and also describes ASCONF chunk processing when Dynamic Address
Reconfiguration is enabled.


security_sctp_sk_clone()
~~~~~~~~~~~~~~~~~~~~~~~~
Called whenever a new socket is created by **accept**\(2) (i.e. a TCP style
socket) or when a socket is 'peeled off' e.g userspace calls
**sctp_peeloff**\(3). ``security_sctp_sk_clone()`` will set the new
sockets sid and peer sid to that contained in the ``@asoc sid`` and
``@asoc peer sid`` respectively.
::

    @asoc - pointer to current sctp association structure.
    @sk - pointer to current sock structure.
    @newsk - pointer to new sock structure.


security_sctp_assoc_established()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Called when a COOKIE ACK is received where it sets the connection's peer sid
to that in ``@skb``::

    @asoc - pointer to sctp association structure.
    @skb - pointer to skbuff of the COOKIE ACK packet.

SELinux policy class와 permission

281-301

커널은 SCTP 지원을 위해 `class sctp_socket inherits socket { node_bind }` class를 제공한다. 이 class는 `policycap extended_socket_class;` policy capability가 활성화될 때 사용할 수 있다.

SELinux SCTP 지원은 특정 port type에 연결하기 위한 `name_connect` permission과 peer label 비교에 사용하는 `association` permission을 추가한다. 사용자 공간 도구가 갱신되어 있으면 `portcon sctp 1024-1036 system_u:object_r:sctp_ports_t:s0`처럼 SCTP port 범위에 context를 지정할 수 있다.

SCTP policy 요소
요소값/역할
classsctp_socket inherits socket { node_bind }
policy capabilityextended_socket_class
permissionname_connect, association
portconSCTP port 범위에 SELinux context 지정

socket class, capability, permission, port context를 함께 구성한다.

Policy Statements
-----------------
The following class and permissions to support SCTP are available within the
kernel::

    class sctp_socket inherits socket { node_bind }

whenever the following policy capability is enabled::

    policycap extended_socket_class;

SELinux SCTP support adds the ``name_connect`` permission for connecting
to a specific port type and the ``association`` permission that is explained
in the section below.

If userspace tools have been updated, SCTP will support the ``portcon``
statement as shown in the following example::

    portcon sctp 1024-1036 system_u:object_r:sctp_ports_t:s0

SCTP peer labeling 규칙과 주의사항

302-344

SCTP socket에는 peer label 하나만 지정된다. 첫 association을 수립할 때 socket peer label이 정해지고, 뒤의 association은 packet peer label을 socket peer label과 비교한다. 두 값이 다를 때만 `association` permission을 검사하며 socket peer SID와 수신 packet peer SID를 대조해 허용 또는 거부를 결정한다.

peer labeling이 꺼져 있으면 peer context는 항상 `SECINITSID_UNLABELED`, Reference Policy에서는 `unlabeled_t`다. SCTP는 하나의 socket에서 endpoint마다 여러 transport 주소를 지원하므로 policy와 NetLabel을 주소별로 다른 peer label로 구성할 수 있다. 그러나 socket label은 첫 association의 transport 주소로 결정되므로 모든 peer label을 일관되게 설정하는 것이 권장된다. 사용자 공간은 `getpeercon(3)`으로 socket peer context를 조회할 수 있다.

특정 interface에 지정한 NetLabel은 그 interface가 down되면 service가 entry를 제거한다. network 시작 script에서 `netlabelctl(8)`로 필요한 label을 다시 설정해야 하며 `netlabel-config(8)` helper를 참고할 수 있다. 관련 SCTP peer labeling 규칙은 원문에 연결된 netlabel 게시물 모음에서 다룬다.

CIPSO는 `socket(AF_INET, ...)` IPv4에만, CALIPSO는 `socket(AF_INET6, ...)` IPv6에만 지원된다. 잘못된 label 때문에 SCTP packet을 배달할 수 없을 때 CIPSO는 ICMP packet을 보내지만 CALIPSO는 ICMP 없이 조용히 폐기한다. 커널은 SCTP/IPsec을 지원하지만 RFC 3554의 사용자 공간 지원이 `racoon(8)`이나 `ipsec_pluto(8)`에 구현되지 않아 IPsec은 지원되지 않는 것으로 문서화되어 있다.

Peer labeling 주의사항
항목동작
Label 미사용SECINITSID_UNLABELED / unlabeled_t
Multi-homing첫 association 주소가 socket peer label 결정
Interface downNetLabel entry 제거, startup에서 재설정 필요
CIPSOIPv4 전용, invalid label이면 ICMP 전송
CALIPSOIPv6 전용, invalid label이면 조용히 폐기
IPsec커널 지원, 사용자 공간 RFC 3554 구현 없음

주소 계열과 labeling 구성에 따른 차이를 정리한다.

SCTP Peer Labeling
------------------
An SCTP socket will only have one peer label assigned to it. This will be
assigned during the establishment of the first association. Any further
associations on this socket will have their packet peer label compared to
the sockets peer label, and only if they are different will the
``association`` permission be validated. This is validated by checking the
socket peer sid against the received packets peer sid to determine whether
the association should be allowed or denied.

NOTES:
   1) If peer labeling is not enabled, then the peer context will always be
      ``SECINITSID_UNLABELED`` (``unlabeled_t`` in Reference Policy).

   2) As SCTP can support more than one transport address per endpoint
      (multi-homing) on a single socket, it is possible to configure policy
      and NetLabel to provide different peer labels for each of these. As the
      socket peer label is determined by the first associations transport
      address, it is recommended that all peer labels are consistent.

   3) **getpeercon**\(3) may be used by userspace to retrieve the sockets peer
      context.

   4) While not SCTP specific, be aware when using NetLabel that if a label
      is assigned to a specific interface, and that interface 'goes down',
      then the NetLabel service will remove the entry. Therefore ensure that
      the network startup scripts call **netlabelctl**\(8) to set the required
      label (see **netlabel-config**\(8) helper script for details).

   5) The NetLabel SCTP peer labeling rules apply as discussed in the following
      set of posts tagged "netlabel" at: https://www.paul-moore.com/blog/t.

   6) CIPSO is only supported for IPv4 addressing: ``socket(AF_INET, ...)``
      CALIPSO is only supported for IPv6 addressing: ``socket(AF_INET6, ...)``

      Note the following when testing CIPSO/CALIPSO:
         a) CIPSO will send an ICMP packet if an SCTP packet cannot be
            delivered because of an invalid label.
         b) CALIPSO does not send an ICMP packet, just silently discards it.

   7) IPSEC is not supported as RFC 3554 - sctp/ipsec support has not been
      implemented in userspace (**racoon**\(8) or **ipsec_pluto**\(8)),
      although the kernel supports SCTP/IPSEC.