Skip to content

Commit c269497

Browse files
committed
Merge tag 'selinux-pr-20220321' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux updates from Paul Moore: "We've got a number of SELinux patches queued up, the highlights are: - Fixup the security_fs_context_parse_param() LSM hook so it executes all of the LSM hook implementations unless a serious error occurs. We also correct the SELinux hook implementation so that it returns zero on success. - In addition to a few SELinux mount option parsing fixes, we simplified the parsing by moving it earlier in the process. The logic was that it was unlikely an admin/user would use the new mount API and not have the policy loaded before passing the SELinux options. - Properly fixed the LSM/SELinux/SCTP hooks with the addition of the security_sctp_assoc_established() hook. This work was done in conjunction with the netdev folks and should complete the move of the SCTP labeling from the endpoints to the associations. - Fixed a variety of sparse warnings caused by changes in the "__rcu" markings of some core kernel structures. - Ensure we access the superblock's LSM security blob using the stacking-safe accessors. - Added the ability for the kernel to always allow FIOCLEX and FIONCLEX if the "ioctl_skip_cloexec" policy capability is specified. - Various constifications improvements, type casting improvements, additional return value checks, and dead code/parameter removal. - Documentation fixes" * tag 'selinux-pr-20220321' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: (23 commits) selinux: shorten the policy capability enum names docs: fix 'make htmldocs' warning in SCTP.rst selinux: allow FIOCLEX and FIONCLEX with policy capability selinux: use correct type for context length selinux: drop return statement at end of void functions security: implement sctp_assoc_established hook in selinux security: add sctp_assoc_established hook selinux: parse contexts for mount options early selinux: various sparse fixes selinux: try to use preparsed sid before calling parse_sid() selinux: Fix selinux_sb_mnt_opts_compat() LSM: general protection fault in legacy_parse_param selinux: fix a type cast problem in cred_init_security() selinux: drop unused macro selinux: simplify cred_init_security selinux: do not discard const qualifier in cast selinux: drop unused parameter of avtab_insert_node selinux: drop cast to same type selinux: enclose macro arguments in parenthesis selinux: declare name parameter of hash_eval const ...
2 parents 7f313ff + cdbec3e commit c269497

24 files changed

Lines changed: 255 additions & 231 deletions

Documentation/security/SCTP.rst

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ For security module support, three SCTP specific hooks have been implemented::
1515
security_sctp_assoc_request()
1616
security_sctp_bind_connect()
1717
security_sctp_sk_clone()
18-
19-
Also the following security hook has been utilised::
20-
21-
security_inet_conn_established()
18+
security_sctp_assoc_established()
2219

2320
The usage of these hooks are described below with the SELinux implementation
2421
described in the `SCTP SELinux Support`_ chapter.
@@ -122,19 +119,20 @@ calls **sctp_peeloff**\(3).
122119
@newsk - pointer to new sock structure.
123120

124121

125-
security_inet_conn_established()
126-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127-
Called when a COOKIE ACK is received::
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::
128126

129-
@sk - pointer to sock structure.
127+
@asoc - pointer to sctp association structure.
130128
@skb - pointer to skbuff of the COOKIE ACK packet.
131129

132130

133131
Security Hooks used for Association Establishment
134132
-------------------------------------------------
135133

136134
The following diagram shows the use of ``security_sctp_bind_connect()``,
137-
``security_sctp_assoc_request()``, ``security_inet_conn_established()`` when
135+
``security_sctp_assoc_request()``, ``security_sctp_assoc_established()`` when
138136
establishing an association.
139137
::
140138

@@ -172,7 +170,7 @@ establishing an association.
172170
<------------------------------------------- COOKIE ACK
173171
| |
174172
sctp_sf_do_5_1E_ca |
175-
Call security_inet_conn_established() |
173+
Call security_sctp_assoc_established() |
176174
to set the peer label. |
177175
| |
178176
| If SCTP_SOCKET_TCP or peeled off
@@ -198,7 +196,7 @@ hooks with the SELinux specifics expanded below::
198196
security_sctp_assoc_request()
199197
security_sctp_bind_connect()
200198
security_sctp_sk_clone()
201-
security_inet_conn_established()
199+
security_sctp_assoc_established()
202200

203201

204202
security_sctp_assoc_request()
@@ -271,12 +269,12 @@ sockets sid and peer sid to that contained in the ``@asoc sid`` and
271269
@newsk - pointer to new sock structure.
272270

273271

274-
security_inet_conn_established()
275-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
272+
security_sctp_assoc_established()
273+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
276274
Called when a COOKIE ACK is received where it sets the connection's peer sid
277275
to that in ``@skb``::
278276

279-
@sk - pointer to sock structure.
277+
@asoc - pointer to sctp association structure.
280278
@skb - pointer to skbuff of the COOKIE ACK packet.
281279

282280

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ LSM_HOOK(int, 0, sctp_bind_connect, struct sock *sk, int optname,
332332
struct sockaddr *address, int addrlen)
333333
LSM_HOOK(void, LSM_RET_VOID, sctp_sk_clone, struct sctp_association *asoc,
334334
struct sock *sk, struct sock *newsk)
335+
LSM_HOOK(int, 0, sctp_assoc_established, struct sctp_association *asoc,
336+
struct sk_buff *skb)
335337
#endif /* CONFIG_SECURITY_NETWORK */
336338

337339
#ifdef CONFIG_SECURITY_INFINIBAND

include/linux/lsm_hooks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,11 @@
10461046
* @asoc pointer to current sctp association structure.
10471047
* @sk pointer to current sock structure.
10481048
* @newsk pointer to new sock structure.
1049+
* @sctp_assoc_established:
1050+
* Passes the @asoc and @chunk->skb of the association COOKIE_ACK packet
1051+
* to the security module.
1052+
* @asoc pointer to sctp association structure.
1053+
* @skb pointer to skbuff of association packet.
10491054
*
10501055
* Security hooks for Infiniband
10511056
*

include/linux/security.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,8 @@ int security_sctp_bind_connect(struct sock *sk, int optname,
14221422
struct sockaddr *address, int addrlen);
14231423
void security_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk,
14241424
struct sock *newsk);
1425+
int security_sctp_assoc_established(struct sctp_association *asoc,
1426+
struct sk_buff *skb);
14251427

14261428
#else /* CONFIG_SECURITY_NETWORK */
14271429
static inline int security_unix_stream_connect(struct sock *sock,
@@ -1641,6 +1643,12 @@ static inline void security_sctp_sk_clone(struct sctp_association *asoc,
16411643
struct sock *newsk)
16421644
{
16431645
}
1646+
1647+
static inline int security_sctp_assoc_established(struct sctp_association *asoc,
1648+
struct sk_buff *skb)
1649+
{
1650+
return 0;
1651+
}
16441652
#endif /* CONFIG_SECURITY_NETWORK */
16451653

16461654
#ifdef CONFIG_SECURITY_INFINIBAND

net/sctp/sm_statefuns.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,11 @@ enum sctp_disposition sctp_sf_do_5_1E_ca(struct net *net,
930930
if (!sctp_vtag_verify(chunk, asoc))
931931
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
932932

933+
/* Set peer label for connection. */
934+
if (security_sctp_assoc_established((struct sctp_association *)asoc,
935+
chunk->skb))
936+
return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
937+
933938
/* Verify that the chunk length for the COOKIE-ACK is OK.
934939
* If we don't do this, any bundled chunks may be junked.
935940
*/
@@ -945,9 +950,6 @@ enum sctp_disposition sctp_sf_do_5_1E_ca(struct net *net,
945950
*/
946951
sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
947952

948-
/* Set peer label for connection. */
949-
security_inet_conn_established(ep->base.sk, chunk->skb);
950-
951953
/* RFC 2960 5.1 Normal Establishment of an Association
952954
*
953955
* E) Upon reception of the COOKIE ACK, endpoint "A" will move

security/security.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,22 @@ int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc)
884884
return call_int_hook(fs_context_dup, 0, fc, src_fc);
885885
}
886886

887-
int security_fs_context_parse_param(struct fs_context *fc, struct fs_parameter *param)
887+
int security_fs_context_parse_param(struct fs_context *fc,
888+
struct fs_parameter *param)
888889
{
889-
return call_int_hook(fs_context_parse_param, -ENOPARAM, fc, param);
890+
struct security_hook_list *hp;
891+
int trc;
892+
int rc = -ENOPARAM;
893+
894+
hlist_for_each_entry(hp, &security_hook_heads.fs_context_parse_param,
895+
list) {
896+
trc = hp->hook.fs_context_parse_param(fc, param);
897+
if (trc == 0)
898+
rc = 0;
899+
else if (trc != -ENOPARAM)
900+
return trc;
901+
}
902+
return rc;
890903
}
891904

892905
int security_sb_alloc(struct super_block *sb)
@@ -2391,6 +2404,13 @@ void security_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk,
23912404
}
23922405
EXPORT_SYMBOL(security_sctp_sk_clone);
23932406

2407+
int security_sctp_assoc_established(struct sctp_association *asoc,
2408+
struct sk_buff *skb)
2409+
{
2410+
return call_int_hook(sctp_assoc_established, 0, asoc, skb);
2411+
}
2412+
EXPORT_SYMBOL(security_sctp_assoc_established);
2413+
23942414
#endif /* CONFIG_SECURITY_NETWORK */
23952415

23962416
#ifdef CONFIG_SECURITY_INFINIBAND

0 commit comments

Comments
 (0)