Skip to content

Commit e7310c9

Browse files
lxindavem330
authored andcommitted
security: implement sctp_assoc_established hook in selinux
Different from selinux_inet_conn_established(), it also gives the secid to asoc->peer_secid in selinux_sctp_assoc_established(), as one UDP-type socket may have more than one asocs. Note that peer_secid in asoc will save the peer secid for this asoc connection, and peer_sid in sksec will just keep the peer secid for the latest connection. So the right use should be do peeloff for UDP-type socket if there will be multiple asocs in one socket, so that the peeloff socket has the right label for its asoc. v1->v2: - call selinux_inet_conn_established() to reduce some code duplication in selinux_sctp_assoc_established(), as Ondrej suggested. - when doing peeloff, it calls sock_create() where it actually gets secid for socket from socket_sockcreate_sid(). So reuse SECSID_WILD to ensure the peeloff socket keeps using that secid after calling selinux_sctp_sk_clone() for client side. Fixes: 72e89f5 ("security: Add support for SCTP security hooks") Reported-by: Prashanth Prahlad <pprahlad@redhat.com> Reviewed-by: Richard Haines <richard_c_haines@btinternet.com> Tested-by: Richard Haines <richard_c_haines@btinternet.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7c2ef02 commit e7310c9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

security/selinux/hooks.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5502,7 +5502,8 @@ static void selinux_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk
55025502
if (!selinux_policycap_extsockclass())
55035503
return selinux_sk_clone_security(sk, newsk);
55045504

5505-
newsksec->sid = asoc->secid;
5505+
if (asoc->secid != SECSID_WILD)
5506+
newsksec->sid = asoc->secid;
55065507
newsksec->peer_sid = asoc->peer_secid;
55075508
newsksec->sclass = sksec->sclass;
55085509
selinux_netlbl_sctp_sk_clone(sk, newsk);
@@ -5558,6 +5559,16 @@ static void selinux_inet_conn_established(struct sock *sk, struct sk_buff *skb)
55585559
selinux_skb_peerlbl_sid(skb, family, &sksec->peer_sid);
55595560
}
55605561

5562+
static void selinux_sctp_assoc_established(struct sctp_association *asoc,
5563+
struct sk_buff *skb)
5564+
{
5565+
struct sk_security_struct *sksec = asoc->base.sk->sk_security;
5566+
5567+
selinux_inet_conn_established(asoc->base.sk, skb);
5568+
asoc->peer_secid = sksec->peer_sid;
5569+
asoc->secid = SECSID_WILD;
5570+
}
5571+
55615572
static int selinux_secmark_relabel_packet(u32 sid)
55625573
{
55635574
const struct task_security_struct *__tsec;
@@ -7228,6 +7239,7 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {
72287239
LSM_HOOK_INIT(sctp_assoc_request, selinux_sctp_assoc_request),
72297240
LSM_HOOK_INIT(sctp_sk_clone, selinux_sctp_sk_clone),
72307241
LSM_HOOK_INIT(sctp_bind_connect, selinux_sctp_bind_connect),
7242+
LSM_HOOK_INIT(sctp_assoc_established, selinux_sctp_assoc_established),
72317243
LSM_HOOK_INIT(inet_conn_request, selinux_inet_conn_request),
72327244
LSM_HOOK_INIT(inet_csk_clone, selinux_inet_csk_clone),
72337245
LSM_HOOK_INIT(inet_conn_established, selinux_inet_conn_established),

0 commit comments

Comments
 (0)