aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c232
1 files changed, 170 insertions, 62 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 4a7374c12d9c..88f19536efad 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -291,6 +291,7 @@ static void sk_free_security(struct sock *sk)
291 struct sk_security_struct *ssec = sk->sk_security; 291 struct sk_security_struct *ssec = sk->sk_security;
292 292
293 sk->sk_security = NULL; 293 sk->sk_security = NULL;
294 selinux_netlbl_sk_security_free(ssec);
294 kfree(ssec); 295 kfree(ssec);
295} 296}
296 297
@@ -2121,7 +2122,6 @@ static inline void flush_unauthorized_files(struct files_struct *files)
2121 long j = -1; 2122 long j = -1;
2122 int drop_tty = 0; 2123 int drop_tty = 0;
2123 2124
2124 mutex_lock(&tty_mutex);
2125 tty = get_current_tty(); 2125 tty = get_current_tty();
2126 if (tty) { 2126 if (tty) {
2127 file_list_lock(); 2127 file_list_lock();
@@ -2139,8 +2139,8 @@ static inline void flush_unauthorized_files(struct files_struct *files)
2139 } 2139 }
2140 } 2140 }
2141 file_list_unlock(); 2141 file_list_unlock();
2142 tty_kref_put(tty);
2142 } 2143 }
2143 mutex_unlock(&tty_mutex);
2144 /* Reset controlling tty. */ 2144 /* Reset controlling tty. */
2145 if (drop_tty) 2145 if (drop_tty)
2146 no_tty(); 2146 no_tty();
@@ -3801,6 +3801,7 @@ out:
3801 3801
3802static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen) 3802static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
3803{ 3803{
3804 struct sock *sk = sock->sk;
3804 struct inode_security_struct *isec; 3805 struct inode_security_struct *isec;
3805 int err; 3806 int err;
3806 3807
@@ -3814,7 +3815,6 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3814 isec = SOCK_INODE(sock)->i_security; 3815 isec = SOCK_INODE(sock)->i_security;
3815 if (isec->sclass == SECCLASS_TCP_SOCKET || 3816 if (isec->sclass == SECCLASS_TCP_SOCKET ||
3816 isec->sclass == SECCLASS_DCCP_SOCKET) { 3817 isec->sclass == SECCLASS_DCCP_SOCKET) {
3817 struct sock *sk = sock->sk;
3818 struct avc_audit_data ad; 3818 struct avc_audit_data ad;
3819 struct sockaddr_in *addr4 = NULL; 3819 struct sockaddr_in *addr4 = NULL;
3820 struct sockaddr_in6 *addr6 = NULL; 3820 struct sockaddr_in6 *addr6 = NULL;
@@ -3848,6 +3848,8 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
3848 goto out; 3848 goto out;
3849 } 3849 }
3850 3850
3851 err = selinux_netlbl_socket_connect(sk, address);
3852
3851out: 3853out:
3852 return err; 3854 return err;
3853} 3855}
@@ -4077,20 +4079,28 @@ static int selinux_sock_rcv_skb_iptables_compat(struct sock *sk,
4077} 4079}
4078 4080
4079static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, 4081static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4080 struct avc_audit_data *ad, 4082 u16 family)
4081 u16 family, char *addrp)
4082{ 4083{
4083 int err; 4084 int err;
4084 struct sk_security_struct *sksec = sk->sk_security; 4085 struct sk_security_struct *sksec = sk->sk_security;
4085 u32 peer_sid; 4086 u32 peer_sid;
4086 u32 sk_sid = sksec->sid; 4087 u32 sk_sid = sksec->sid;
4088 struct avc_audit_data ad;
4089 char *addrp;
4090
4091 AVC_AUDIT_DATA_INIT(&ad, NET);
4092 ad.u.net.netif = skb->iif;
4093 ad.u.net.family = family;
4094 err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
4095 if (err)
4096 return err;
4087 4097
4088 if (selinux_compat_net) 4098 if (selinux_compat_net)
4089 err = selinux_sock_rcv_skb_iptables_compat(sk, skb, ad, 4099 err = selinux_sock_rcv_skb_iptables_compat(sk, skb, &ad,
4090 family, addrp); 4100 family, addrp);
4091 else 4101 else
4092 err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET, 4102 err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET,
4093 PACKET__RECV, ad); 4103 PACKET__RECV, &ad);
4094 if (err) 4104 if (err)
4095 return err; 4105 return err;
4096 4106
@@ -4099,12 +4109,14 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
4099 if (err) 4109 if (err)
4100 return err; 4110 return err;
4101 err = avc_has_perm(sk_sid, peer_sid, 4111 err = avc_has_perm(sk_sid, peer_sid,
4102 SECCLASS_PEER, PEER__RECV, ad); 4112 SECCLASS_PEER, PEER__RECV, &ad);
4113 if (err)
4114 selinux_netlbl_err(skb, err, 0);
4103 } else { 4115 } else {
4104 err = selinux_netlbl_sock_rcv_skb(sksec, skb, family, ad); 4116 err = selinux_netlbl_sock_rcv_skb(sksec, skb, family, &ad);
4105 if (err) 4117 if (err)
4106 return err; 4118 return err;
4107 err = selinux_xfrm_sock_rcv_skb(sksec->sid, skb, ad); 4119 err = selinux_xfrm_sock_rcv_skb(sksec->sid, skb, &ad);
4108 } 4120 }
4109 4121
4110 return err; 4122 return err;
@@ -4118,6 +4130,8 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4118 u32 sk_sid = sksec->sid; 4130 u32 sk_sid = sksec->sid;
4119 struct avc_audit_data ad; 4131 struct avc_audit_data ad;
4120 char *addrp; 4132 char *addrp;
4133 u8 secmark_active;
4134 u8 peerlbl_active;
4121 4135
4122 if (family != PF_INET && family != PF_INET6) 4136 if (family != PF_INET && family != PF_INET6)
4123 return 0; 4137 return 0;
@@ -4126,6 +4140,18 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4126 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP)) 4140 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
4127 family = PF_INET; 4141 family = PF_INET;
4128 4142
4143 /* If any sort of compatibility mode is enabled then handoff processing
4144 * to the selinux_sock_rcv_skb_compat() function to deal with the
4145 * special handling. We do this in an attempt to keep this function
4146 * as fast and as clean as possible. */
4147 if (selinux_compat_net || !selinux_policycap_netpeer)
4148 return selinux_sock_rcv_skb_compat(sk, skb, family);
4149
4150 secmark_active = selinux_secmark_enabled();
4151 peerlbl_active = netlbl_enabled() || selinux_xfrm_enabled();
4152 if (!secmark_active && !peerlbl_active)
4153 return 0;
4154
4129 AVC_AUDIT_DATA_INIT(&ad, NET); 4155 AVC_AUDIT_DATA_INIT(&ad, NET);
4130 ad.u.net.netif = skb->iif; 4156 ad.u.net.netif = skb->iif;
4131 ad.u.net.family = family; 4157 ad.u.net.family = family;
@@ -4133,15 +4159,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4133 if (err) 4159 if (err)
4134 return err; 4160 return err;
4135 4161
4136 /* If any sort of compatibility mode is enabled then handoff processing 4162 if (peerlbl_active) {
4137 * to the selinux_sock_rcv_skb_compat() function to deal with the
4138 * special handling. We do this in an attempt to keep this function
4139 * as fast and as clean as possible. */
4140 if (selinux_compat_net || !selinux_policycap_netpeer)
4141 return selinux_sock_rcv_skb_compat(sk, skb, &ad,
4142 family, addrp);
4143
4144 if (netlbl_enabled() || selinux_xfrm_enabled()) {
4145 u32 peer_sid; 4163 u32 peer_sid;
4146 4164
4147 err = selinux_skb_peerlbl_sid(skb, family, &peer_sid); 4165 err = selinux_skb_peerlbl_sid(skb, family, &peer_sid);
@@ -4149,13 +4167,17 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
4149 return err; 4167 return err;
4150 err = selinux_inet_sys_rcv_skb(skb->iif, addrp, family, 4168 err = selinux_inet_sys_rcv_skb(skb->iif, addrp, family,
4151 peer_sid, &ad); 4169 peer_sid, &ad);
4152 if (err) 4170 if (err) {
4171 selinux_netlbl_err(skb, err, 0);
4153 return err; 4172 return err;
4173 }
4154 err = avc_has_perm(sk_sid, peer_sid, SECCLASS_PEER, 4174 err = avc_has_perm(sk_sid, peer_sid, SECCLASS_PEER,
4155 PEER__RECV, &ad); 4175 PEER__RECV, &ad);
4176 if (err)
4177 selinux_netlbl_err(skb, err, 0);
4156 } 4178 }
4157 4179
4158 if (selinux_secmark_enabled()) { 4180 if (secmark_active) {
4159 err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET, 4181 err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET,
4160 PACKET__RECV, &ad); 4182 PACKET__RECV, &ad);
4161 if (err) 4183 if (err)
@@ -4214,10 +4236,12 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *
4214 u32 peer_secid = SECSID_NULL; 4236 u32 peer_secid = SECSID_NULL;
4215 u16 family; 4237 u16 family;
4216 4238
4217 if (sock) 4239 if (skb && skb->protocol == htons(ETH_P_IP))
4240 family = PF_INET;
4241 else if (skb && skb->protocol == htons(ETH_P_IPV6))
4242 family = PF_INET6;
4243 else if (sock)
4218 family = sock->sk->sk_family; 4244 family = sock->sk->sk_family;
4219 else if (skb && skb->sk)
4220 family = skb->sk->sk_family;
4221 else 4245 else
4222 goto out; 4246 goto out;
4223 4247
@@ -4275,8 +4299,6 @@ static void selinux_sock_graft(struct sock *sk, struct socket *parent)
4275 sk->sk_family == PF_UNIX) 4299 sk->sk_family == PF_UNIX)
4276 isec->sid = sksec->sid; 4300 isec->sid = sksec->sid;
4277 sksec->sclass = isec->sclass; 4301 sksec->sclass = isec->sclass;
4278
4279 selinux_netlbl_sock_graft(sk, parent);
4280} 4302}
4281 4303
4282static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb, 4304static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,
@@ -4284,10 +4306,15 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,
4284{ 4306{
4285 struct sk_security_struct *sksec = sk->sk_security; 4307 struct sk_security_struct *sksec = sk->sk_security;
4286 int err; 4308 int err;
4309 u16 family = sk->sk_family;
4287 u32 newsid; 4310 u32 newsid;
4288 u32 peersid; 4311 u32 peersid;
4289 4312
4290 err = selinux_skb_peerlbl_sid(skb, sk->sk_family, &peersid); 4313 /* handle mapped IPv4 packets arriving via IPv6 sockets */
4314 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
4315 family = PF_INET;
4316
4317 err = selinux_skb_peerlbl_sid(skb, family, &peersid);
4291 if (err) 4318 if (err)
4292 return err; 4319 return err;
4293 if (peersid == SECSID_NULL) { 4320 if (peersid == SECSID_NULL) {
@@ -4322,12 +4349,18 @@ static void selinux_inet_csk_clone(struct sock *newsk,
4322 selinux_netlbl_sk_security_reset(newsksec, req->rsk_ops->family); 4349 selinux_netlbl_sk_security_reset(newsksec, req->rsk_ops->family);
4323} 4350}
4324 4351
4325static void selinux_inet_conn_established(struct sock *sk, 4352static void selinux_inet_conn_established(struct sock *sk, struct sk_buff *skb)
4326 struct sk_buff *skb)
4327{ 4353{
4354 u16 family = sk->sk_family;
4328 struct sk_security_struct *sksec = sk->sk_security; 4355 struct sk_security_struct *sksec = sk->sk_security;
4329 4356
4330 selinux_skb_peerlbl_sid(skb, sk->sk_family, &sksec->peer_sid); 4357 /* handle mapped IPv4 packets arriving via IPv6 sockets */
4358 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
4359 family = PF_INET;
4360
4361 selinux_skb_peerlbl_sid(skb, family, &sksec->peer_sid);
4362
4363 selinux_netlbl_inet_conn_established(sk, family);
4331} 4364}
4332 4365
4333static void selinux_req_classify_flow(const struct request_sock *req, 4366static void selinux_req_classify_flow(const struct request_sock *req,
@@ -4377,39 +4410,54 @@ out:
4377static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex, 4410static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
4378 u16 family) 4411 u16 family)
4379{ 4412{
4413 int err;
4380 char *addrp; 4414 char *addrp;
4381 u32 peer_sid; 4415 u32 peer_sid;
4382 struct avc_audit_data ad; 4416 struct avc_audit_data ad;
4383 u8 secmark_active; 4417 u8 secmark_active;
4418 u8 netlbl_active;
4384 u8 peerlbl_active; 4419 u8 peerlbl_active;
4385 4420
4386 if (!selinux_policycap_netpeer) 4421 if (!selinux_policycap_netpeer)
4387 return NF_ACCEPT; 4422 return NF_ACCEPT;
4388 4423
4389 secmark_active = selinux_secmark_enabled(); 4424 secmark_active = selinux_secmark_enabled();
4390 peerlbl_active = netlbl_enabled() || selinux_xfrm_enabled(); 4425 netlbl_active = netlbl_enabled();
4426 peerlbl_active = netlbl_active || selinux_xfrm_enabled();
4391 if (!secmark_active && !peerlbl_active) 4427 if (!secmark_active && !peerlbl_active)
4392 return NF_ACCEPT; 4428 return NF_ACCEPT;
4393 4429
4430 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0)
4431 return NF_DROP;
4432
4394 AVC_AUDIT_DATA_INIT(&ad, NET); 4433 AVC_AUDIT_DATA_INIT(&ad, NET);
4395 ad.u.net.netif = ifindex; 4434 ad.u.net.netif = ifindex;
4396 ad.u.net.family = family; 4435 ad.u.net.family = family;
4397 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0) 4436 if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0)
4398 return NF_DROP; 4437 return NF_DROP;
4399 4438
4400 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0) 4439 if (peerlbl_active) {
4401 return NF_DROP; 4440 err = selinux_inet_sys_rcv_skb(ifindex, addrp, family,
4402 4441 peer_sid, &ad);
4403 if (peerlbl_active) 4442 if (err) {
4404 if (selinux_inet_sys_rcv_skb(ifindex, addrp, family, 4443 selinux_netlbl_err(skb, err, 1);
4405 peer_sid, &ad) != 0)
4406 return NF_DROP; 4444 return NF_DROP;
4445 }
4446 }
4407 4447
4408 if (secmark_active) 4448 if (secmark_active)
4409 if (avc_has_perm(peer_sid, skb->secmark, 4449 if (avc_has_perm(peer_sid, skb->secmark,
4410 SECCLASS_PACKET, PACKET__FORWARD_IN, &ad)) 4450 SECCLASS_PACKET, PACKET__FORWARD_IN, &ad))
4411 return NF_DROP; 4451 return NF_DROP;
4412 4452
4453 if (netlbl_active)
4454 /* we do this in the FORWARD path and not the POST_ROUTING
4455 * path because we want to make sure we apply the necessary
4456 * labeling before IPsec is applied so we can leverage AH
4457 * protection */
4458 if (selinux_netlbl_skbuff_setsid(skb, family, peer_sid) != 0)
4459 return NF_DROP;
4460
4413 return NF_ACCEPT; 4461 return NF_ACCEPT;
4414} 4462}
4415 4463
@@ -4433,6 +4481,37 @@ static unsigned int selinux_ipv6_forward(unsigned int hooknum,
4433} 4481}
4434#endif /* IPV6 */ 4482#endif /* IPV6 */
4435 4483
4484static unsigned int selinux_ip_output(struct sk_buff *skb,
4485 u16 family)
4486{
4487 u32 sid;
4488
4489 if (!netlbl_enabled())
4490 return NF_ACCEPT;
4491
4492 /* we do this in the LOCAL_OUT path and not the POST_ROUTING path
4493 * because we want to make sure we apply the necessary labeling
4494 * before IPsec is applied so we can leverage AH protection */
4495 if (skb->sk) {
4496 struct sk_security_struct *sksec = skb->sk->sk_security;
4497 sid = sksec->sid;
4498 } else
4499 sid = SECINITSID_KERNEL;
4500 if (selinux_netlbl_skbuff_setsid(skb, family, sid) != 0)
4501 return NF_DROP;
4502
4503 return NF_ACCEPT;
4504}
4505
4506static unsigned int selinux_ipv4_output(unsigned int hooknum,
4507 struct sk_buff *skb,
4508 const struct net_device *in,
4509 const struct net_device *out,
4510 int (*okfn)(struct sk_buff *))
4511{
4512 return selinux_ip_output(skb, PF_INET);
4513}
4514
4436static int selinux_ip_postroute_iptables_compat(struct sock *sk, 4515static int selinux_ip_postroute_iptables_compat(struct sock *sk,
4437 int ifindex, 4516 int ifindex,
4438 struct avc_audit_data *ad, 4517 struct avc_audit_data *ad,
@@ -4500,30 +4579,36 @@ static int selinux_ip_postroute_iptables_compat(struct sock *sk,
4500 4579
4501static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, 4580static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
4502 int ifindex, 4581 int ifindex,
4503 struct avc_audit_data *ad, 4582 u16 family)
4504 u16 family,
4505 char *addrp,
4506 u8 proto)
4507{ 4583{
4508 struct sock *sk = skb->sk; 4584 struct sock *sk = skb->sk;
4509 struct sk_security_struct *sksec; 4585 struct sk_security_struct *sksec;
4586 struct avc_audit_data ad;
4587 char *addrp;
4588 u8 proto;
4510 4589
4511 if (sk == NULL) 4590 if (sk == NULL)
4512 return NF_ACCEPT; 4591 return NF_ACCEPT;
4513 sksec = sk->sk_security; 4592 sksec = sk->sk_security;
4514 4593
4594 AVC_AUDIT_DATA_INIT(&ad, NET);
4595 ad.u.net.netif = ifindex;
4596 ad.u.net.family = family;
4597 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
4598 return NF_DROP;
4599
4515 if (selinux_compat_net) { 4600 if (selinux_compat_net) {
4516 if (selinux_ip_postroute_iptables_compat(skb->sk, ifindex, 4601 if (selinux_ip_postroute_iptables_compat(skb->sk, ifindex,
4517 ad, family, addrp)) 4602 &ad, family, addrp))
4518 return NF_DROP; 4603 return NF_DROP;
4519 } else { 4604 } else {
4520 if (avc_has_perm(sksec->sid, skb->secmark, 4605 if (avc_has_perm(sksec->sid, skb->secmark,
4521 SECCLASS_PACKET, PACKET__SEND, ad)) 4606 SECCLASS_PACKET, PACKET__SEND, &ad))
4522 return NF_DROP; 4607 return NF_DROP;
4523 } 4608 }
4524 4609
4525 if (selinux_policycap_netpeer) 4610 if (selinux_policycap_netpeer)
4526 if (selinux_xfrm_postroute_last(sksec->sid, skb, ad, proto)) 4611 if (selinux_xfrm_postroute_last(sksec->sid, skb, &ad, proto))
4527 return NF_DROP; 4612 return NF_DROP;
4528 4613
4529 return NF_ACCEPT; 4614 return NF_ACCEPT;
@@ -4537,23 +4622,15 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4537 struct sock *sk; 4622 struct sock *sk;
4538 struct avc_audit_data ad; 4623 struct avc_audit_data ad;
4539 char *addrp; 4624 char *addrp;
4540 u8 proto;
4541 u8 secmark_active; 4625 u8 secmark_active;
4542 u8 peerlbl_active; 4626 u8 peerlbl_active;
4543 4627
4544 AVC_AUDIT_DATA_INIT(&ad, NET);
4545 ad.u.net.netif = ifindex;
4546 ad.u.net.family = family;
4547 if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
4548 return NF_DROP;
4549
4550 /* If any sort of compatibility mode is enabled then handoff processing 4628 /* If any sort of compatibility mode is enabled then handoff processing
4551 * to the selinux_ip_postroute_compat() function to deal with the 4629 * to the selinux_ip_postroute_compat() function to deal with the
4552 * special handling. We do this in an attempt to keep this function 4630 * special handling. We do this in an attempt to keep this function
4553 * as fast and as clean as possible. */ 4631 * as fast and as clean as possible. */
4554 if (selinux_compat_net || !selinux_policycap_netpeer) 4632 if (selinux_compat_net || !selinux_policycap_netpeer)
4555 return selinux_ip_postroute_compat(skb, ifindex, &ad, 4633 return selinux_ip_postroute_compat(skb, ifindex, family);
4556 family, addrp, proto);
4557 4634
4558 /* If skb->dst->xfrm is non-NULL then the packet is undergoing an IPsec 4635 /* If skb->dst->xfrm is non-NULL then the packet is undergoing an IPsec
4559 * packet transformation so allow the packet to pass without any checks 4636 * packet transformation so allow the packet to pass without any checks
@@ -4569,21 +4646,45 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
4569 if (!secmark_active && !peerlbl_active) 4646 if (!secmark_active && !peerlbl_active)
4570 return NF_ACCEPT; 4647 return NF_ACCEPT;
4571 4648
4572 /* if the packet is locally generated (skb->sk != NULL) then use the 4649 /* if the packet is being forwarded then get the peer label from the
4573 * socket's label as the peer label, otherwise the packet is being 4650 * packet itself; otherwise check to see if it is from a local
4574 * forwarded through this system and we need to fetch the peer label 4651 * application or the kernel, if from an application get the peer label
4575 * directly from the packet */ 4652 * from the sending socket, otherwise use the kernel's sid */
4576 sk = skb->sk; 4653 sk = skb->sk;
4577 if (sk) { 4654 if (sk == NULL) {
4655 switch (family) {
4656 case PF_INET:
4657 if (IPCB(skb)->flags & IPSKB_FORWARDED)
4658 secmark_perm = PACKET__FORWARD_OUT;
4659 else
4660 secmark_perm = PACKET__SEND;
4661 break;
4662 case PF_INET6:
4663 if (IP6CB(skb)->flags & IP6SKB_FORWARDED)
4664 secmark_perm = PACKET__FORWARD_OUT;
4665 else
4666 secmark_perm = PACKET__SEND;
4667 break;
4668 default:
4669 return NF_DROP;
4670 }
4671 if (secmark_perm == PACKET__FORWARD_OUT) {
4672 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid))
4673 return NF_DROP;
4674 } else
4675 peer_sid = SECINITSID_KERNEL;
4676 } else {
4578 struct sk_security_struct *sksec = sk->sk_security; 4677 struct sk_security_struct *sksec = sk->sk_security;
4579 peer_sid = sksec->sid; 4678 peer_sid = sksec->sid;
4580 secmark_perm = PACKET__SEND; 4679 secmark_perm = PACKET__SEND;
4581 } else {
4582 if (selinux_skb_peerlbl_sid(skb, family, &peer_sid))
4583 return NF_DROP;
4584 secmark_perm = PACKET__FORWARD_OUT;
4585 } 4680 }
4586 4681
4682 AVC_AUDIT_DATA_INIT(&ad, NET);
4683 ad.u.net.netif = ifindex;
4684 ad.u.net.family = family;
4685 if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL))
4686 return NF_DROP;
4687
4587 if (secmark_active) 4688 if (secmark_active)
4588 if (avc_has_perm(peer_sid, skb->secmark, 4689 if (avc_has_perm(peer_sid, skb->secmark,
4589 SECCLASS_PACKET, secmark_perm, &ad)) 4690 SECCLASS_PACKET, secmark_perm, &ad))
@@ -5657,6 +5758,13 @@ static struct nf_hook_ops selinux_ipv4_ops[] = {
5657 .pf = PF_INET, 5758 .pf = PF_INET,
5658 .hooknum = NF_INET_FORWARD, 5759 .hooknum = NF_INET_FORWARD,
5659 .priority = NF_IP_PRI_SELINUX_FIRST, 5760 .priority = NF_IP_PRI_SELINUX_FIRST,
5761 },
5762 {
5763 .hook = selinux_ipv4_output,
5764 .owner = THIS_MODULE,
5765 .pf = PF_INET,
5766 .hooknum = NF_INET_LOCAL_OUT,
5767 .priority = NF_IP_PRI_SELINUX_FIRST,
5660 } 5768 }
5661}; 5769};
5662 5770