aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
authorAlexey Kodanev <alexey.kodanev@oracle.com>2018-05-11 13:15:12 -0400
committerPaul Moore <paul@paul-moore.com>2018-05-14 15:19:25 -0400
commit88b7d370bb4b1280717ebdacd6748456f9ba484f (patch)
treeb39eaeabeabb993ffcfffe9fb6f566a32ad4975a /security/selinux/hooks.c
parent0f8db8cc73df60b3de9a5eebd8f117b56eff5b03 (diff)
selinux: fix address family in bind() and connect() to match address/port
Since sctp_bindx() and sctp_connectx() can have multiple addresses, sk_family can differ from sa_family. Therefore, selinux_socket_bind() and selinux_socket_connect_helper(), which process sockaddr structure (address and port), should use the address family from that structure too, and not from the socket one. The initialization of the data for the audit record is moved above, in selinux_socket_bind(), so that there is no duplicate changes and code. Fixes: d452930fd3b9 ("selinux: Add SCTP support") Suggested-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Alexey Kodanev <alexey.kodanev@oracle.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 16df6cca9a1b..f5f2d6a582f0 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -4622,6 +4622,11 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
4622 goto err_af; 4622 goto err_af;
4623 } 4623 }
4624 4624
4625 ad.type = LSM_AUDIT_DATA_NET;
4626 ad.u.net = &net;
4627 ad.u.net->sport = htons(snum);
4628 ad.u.net->family = family_sa;
4629
4625 if (snum) { 4630 if (snum) {
4626 int low, high; 4631 int low, high;
4627 4632
@@ -4633,10 +4638,6 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
4633 snum, &sid); 4638 snum, &sid);
4634 if (err) 4639 if (err)
4635 goto out; 4640 goto out;
4636 ad.type = LSM_AUDIT_DATA_NET;
4637 ad.u.net = &net;
4638 ad.u.net->sport = htons(snum);
4639 ad.u.net->family = family;
4640 err = avc_has_perm(&selinux_state, 4641 err = avc_has_perm(&selinux_state,
4641 sksec->sid, sid, 4642 sksec->sid, sid,
4642 sksec->sclass, 4643 sksec->sclass,
@@ -4668,15 +4669,10 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
4668 break; 4669 break;
4669 } 4670 }
4670 4671
4671 err = sel_netnode_sid(addrp, family, &sid); 4672 err = sel_netnode_sid(addrp, family_sa, &sid);
4672 if (err) 4673 if (err)
4673 goto out; 4674 goto out;
4674 4675
4675 ad.type = LSM_AUDIT_DATA_NET;
4676 ad.u.net = &net;
4677 ad.u.net->sport = htons(snum);
4678 ad.u.net->family = family;
4679
4680 if (family_sa == AF_INET) 4676 if (family_sa == AF_INET)
4681 ad.u.net->v4info.saddr = addr4->sin_addr.s_addr; 4677 ad.u.net->v4info.saddr = addr4->sin_addr.s_addr;
4682 else 4678 else
@@ -4772,7 +4768,7 @@ static int selinux_socket_connect_helper(struct socket *sock,
4772 ad.type = LSM_AUDIT_DATA_NET; 4768 ad.type = LSM_AUDIT_DATA_NET;
4773 ad.u.net = &net; 4769 ad.u.net = &net;
4774 ad.u.net->dport = htons(snum); 4770 ad.u.net->dport = htons(snum);
4775 ad.u.net->family = sk->sk_family; 4771 ad.u.net->family = address->sa_family;
4776 err = avc_has_perm(&selinux_state, 4772 err = avc_has_perm(&selinux_state,
4777 sksec->sid, sid, sksec->sclass, perm, &ad); 4773 sksec->sid, sid, sksec->sclass, perm, &ad);
4778 if (err) 4774 if (err)