요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. 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.
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 |
------------------------------------------------------------------
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
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.
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 |
------------------------------------------------------------------
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.
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.
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
------------------
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.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
SCTP 전용 security hook
1-22SCTP에 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을 처리하는 구체적인 방식을 확장해 설명한다.
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`는 단일 주소를 받는다.
optname별 주소 개수 요구 사항이다.
연결과 동적 주소 변경에 쓰이는 주소 개수 요구 사항이다.
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에 전달된다.
local optname이 peer로 보내는 ASCONF parameter로 변환된다.
양 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`다.
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-186endpoint 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에 도달한다.
원문의 양방향 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-227SELinux 구현에서도 네 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에 설정한다.
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-280SELinux의 `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를 인자로 받는다.
검사 이후 어느 객체의 보안 식별자가 갱신되는지 보여 준다.
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를 지정할 수 있다.
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-344SCTP 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은 지원되지 않는 것으로 문서화되어 있다.
주소 계열과 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.
요약·해설
SCTP.rst:1-344SCTP는 하나의 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에만 적용된다는 점을 함께 확인해야 합니다.
주소 선택부터 association 확정과 새 socket 생성까지 label을 연속적으로 유지한다.