Skip to content

Commit 9eda2d2

Browse files
committed
Merge tag 'selinux-pr-20180403' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull SELinux updates from Paul Moore: "A bigger than usual pull request for SELinux, 13 patches (lucky!) along with a scary looking diffstat. Although if you look a bit closer, excluding the usual minor tweaks/fixes, there are really only two significant changes in this pull request: the addition of proper SELinux access controls for SCTP and the encapsulation of a lot of internal SELinux state. The SCTP changes are the result of a multi-month effort (maybe even a year or longer?) between the SELinux folks and the SCTP folks to add proper SELinux controls. A special thanks go to Richard for seeing this through and keeping the effort moving forward. The state encapsulation work is a bit of janitorial work that came out of some early work on SELinux namespacing. The question of namespacing is still an open one, but I believe there is some real value in the encapsulation work so we've split that out and are now sending that up to you" * tag 'selinux-pr-20180403' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: wrap AVC state selinux: wrap selinuxfs state selinux: fix handling of uninitialized selinux state in get_bools/classes selinux: Update SELinux SCTP documentation selinux: Fix ltp test connect-syscall failure selinux: rename the {is,set}_enforcing() functions selinux: wrap global selinux state selinux: fix typo in selinux_netlbl_sctp_sk_clone declaration selinux: Add SCTP support sctp: Add LSM hooks sctp: Add ip option support security: Add support for SCTP security hooks netlabel: If PF_INET6, check sk_buff ip header version
2 parents 6ad11bd + 6b6bc62 commit 9eda2d2

43 files changed

Lines changed: 2936 additions & 1252 deletions

Some content is hidden

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

‎include/linux/lsm_hooks.h‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,33 @@
906906
* associated with the TUN device's security structure.
907907
* @security pointer to the TUN devices's security structure.
908908
*
909+
* Security hooks for SCTP
910+
*
911+
* @sctp_assoc_request:
912+
* Passes the @ep and @chunk->skb of the association INIT packet to
913+
* the security module.
914+
* @ep pointer to sctp endpoint structure.
915+
* @skb pointer to skbuff of association packet.
916+
* Return 0 on success, error on failure.
917+
* @sctp_bind_connect:
918+
* Validiate permissions required for each address associated with sock
919+
* @sk. Depending on @optname, the addresses will be treated as either
920+
* for a connect or bind service. The @addrlen is calculated on each
921+
* ipv4 and ipv6 address using sizeof(struct sockaddr_in) or
922+
* sizeof(struct sockaddr_in6).
923+
* @sk pointer to sock structure.
924+
* @optname name of the option to validate.
925+
* @address list containing one or more ipv4/ipv6 addresses.
926+
* @addrlen total length of address(s).
927+
* Return 0 on success, error on failure.
928+
* @sctp_sk_clone:
929+
* Called whenever a new socket is created by accept(2) (i.e. a TCP
930+
* style socket) or when a socket is 'peeled off' e.g userspace
931+
* calls sctp_peeloff(3).
932+
* @ep pointer to current sctp endpoint structure.
933+
* @sk pointer to current sock structure.
934+
* @sk pointer to new sock structure.
935+
*
909936
* Security hooks for Infiniband
910937
*
911938
* @ib_pkey_access:
@@ -1665,6 +1692,12 @@ union security_list_options {
16651692
int (*tun_dev_attach_queue)(void *security);
16661693
int (*tun_dev_attach)(struct sock *sk, void *security);
16671694
int (*tun_dev_open)(void *security);
1695+
int (*sctp_assoc_request)(struct sctp_endpoint *ep,
1696+
struct sk_buff *skb);
1697+
int (*sctp_bind_connect)(struct sock *sk, int optname,
1698+
struct sockaddr *address, int addrlen);
1699+
void (*sctp_sk_clone)(struct sctp_endpoint *ep, struct sock *sk,
1700+
struct sock *newsk);
16681701
#endif /* CONFIG_SECURITY_NETWORK */
16691702

16701703
#ifdef CONFIG_SECURITY_INFINIBAND
@@ -1914,6 +1947,9 @@ struct security_hook_heads {
19141947
struct list_head tun_dev_attach_queue;
19151948
struct list_head tun_dev_attach;
19161949
struct list_head tun_dev_open;
1950+
struct list_head sctp_assoc_request;
1951+
struct list_head sctp_bind_connect;
1952+
struct list_head sctp_sk_clone;
19171953
#endif /* CONFIG_SECURITY_NETWORK */
19181954
#ifdef CONFIG_SECURITY_INFINIBAND
19191955
struct list_head ib_pkey_access;

0 commit comments

Comments
 (0)