diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-13 13:00:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-13 13:00:44 -0400 |
commit | 8d71ff0bef9cf4e70108a9a2762f2361e607abde (patch) | |
tree | a79487fceb6ec18e956373a3019416a43b269f1d /security/selinux/hooks.c | |
parent | 244dc4e54b73567fae7f8fd9ba56584be9375442 (diff) | |
parent | 92562927826fceb2f8e69c89e28161b8c1e0b125 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6: (24 commits)
integrity: special fs magic
As pointed out by Jonathan Corbet, the timer must be deleted before
ERROR: code indent should use tabs where possible
The tpm_dev_release function is only called for platform devices, not pnp
Protect tpm_chip_list when transversing it.
Renames num_open to is_open, as only one process can open the file at a time.
Remove the BKL calls from the TPM driver, which were added in the overall
netlabel: Add configuration support for local labeling
cipso: Add support for native local labeling and fixup mapping names
netlabel: Changes to the NetLabel security attributes to allow LSMs to pass full contexts
selinux: Cache NetLabel secattrs in the socket's security struct
selinux: Set socket NetLabel based on connection endpoint
netlabel: Add functionality to set the security attributes of a packet
netlabel: Add network address selectors to the NetLabel/LSM domain mapping
netlabel: Add a generic way to create ordered linked lists of network addrs
netlabel: Replace protocol/NetLabel linking with refrerence counts
smack: Fix missing calls to netlbl_skbuff_err()
selinux: Fix missing calls to netlbl_skbuff_err()
selinux: Fix a problem in security_netlbl_sid_to_secattr()
selinux: Better local/forward check in selinux_ip_postroute()
...
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r-- | security/selinux/hooks.c | 229 |
1 files changed, 169 insertions, 60 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index 48881394fbd4..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 | ||
@@ -3800,6 +3801,7 @@ out: | |||
3800 | 3801 | ||
3801 | static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen) | 3802 | static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen) |
3802 | { | 3803 | { |
3804 | struct sock *sk = sock->sk; | ||
3803 | struct inode_security_struct *isec; | 3805 | struct inode_security_struct *isec; |
3804 | int err; | 3806 | int err; |
3805 | 3807 | ||
@@ -3813,7 +3815,6 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, | |||
3813 | isec = SOCK_INODE(sock)->i_security; | 3815 | isec = SOCK_INODE(sock)->i_security; |
3814 | if (isec->sclass == SECCLASS_TCP_SOCKET || | 3816 | if (isec->sclass == SECCLASS_TCP_SOCKET || |
3815 | isec->sclass == SECCLASS_DCCP_SOCKET) { | 3817 | isec->sclass == SECCLASS_DCCP_SOCKET) { |
3816 | struct sock *sk = sock->sk; | ||
3817 | struct avc_audit_data ad; | 3818 | struct avc_audit_data ad; |
3818 | struct sockaddr_in *addr4 = NULL; | 3819 | struct sockaddr_in *addr4 = NULL; |
3819 | struct sockaddr_in6 *addr6 = NULL; | 3820 | struct sockaddr_in6 *addr6 = NULL; |
@@ -3847,6 +3848,8 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, | |||
3847 | goto out; | 3848 | goto out; |
3848 | } | 3849 | } |
3849 | 3850 | ||
3851 | err = selinux_netlbl_socket_connect(sk, address); | ||
3852 | |||
3850 | out: | 3853 | out: |
3851 | return err; | 3854 | return err; |
3852 | } | 3855 | } |
@@ -4076,20 +4079,28 @@ static int selinux_sock_rcv_skb_iptables_compat(struct sock *sk, | |||
4076 | } | 4079 | } |
4077 | 4080 | ||
4078 | static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, | 4081 | static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, |
4079 | struct avc_audit_data *ad, | 4082 | u16 family) |
4080 | u16 family, char *addrp) | ||
4081 | { | 4083 | { |
4082 | int err; | 4084 | int err; |
4083 | struct sk_security_struct *sksec = sk->sk_security; | 4085 | struct sk_security_struct *sksec = sk->sk_security; |
4084 | u32 peer_sid; | 4086 | u32 peer_sid; |
4085 | 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; | ||
4086 | 4097 | ||
4087 | if (selinux_compat_net) | 4098 | if (selinux_compat_net) |
4088 | err = selinux_sock_rcv_skb_iptables_compat(sk, skb, ad, | 4099 | err = selinux_sock_rcv_skb_iptables_compat(sk, skb, &ad, |
4089 | family, addrp); | 4100 | family, addrp); |
4090 | else | 4101 | else |
4091 | err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET, | 4102 | err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET, |
4092 | PACKET__RECV, ad); | 4103 | PACKET__RECV, &ad); |
4093 | if (err) | 4104 | if (err) |
4094 | return err; | 4105 | return err; |
4095 | 4106 | ||
@@ -4098,12 +4109,14 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb, | |||
4098 | if (err) | 4109 | if (err) |
4099 | return err; | 4110 | return err; |
4100 | err = avc_has_perm(sk_sid, peer_sid, | 4111 | err = avc_has_perm(sk_sid, peer_sid, |
4101 | SECCLASS_PEER, PEER__RECV, ad); | 4112 | SECCLASS_PEER, PEER__RECV, &ad); |
4113 | if (err) | ||
4114 | selinux_netlbl_err(skb, err, 0); | ||
4102 | } else { | 4115 | } else { |
4103 | err = selinux_netlbl_sock_rcv_skb(sksec, skb, family, ad); | 4116 | err = selinux_netlbl_sock_rcv_skb(sksec, skb, family, &ad); |
4104 | if (err) | 4117 | if (err) |
4105 | return err; | 4118 | return err; |
4106 | err = selinux_xfrm_sock_rcv_skb(sksec->sid, skb, ad); | 4119 | err = selinux_xfrm_sock_rcv_skb(sksec->sid, skb, &ad); |
4107 | } | 4120 | } |
4108 | 4121 | ||
4109 | return err; | 4122 | return err; |
@@ -4117,6 +4130,8 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) | |||
4117 | u32 sk_sid = sksec->sid; | 4130 | u32 sk_sid = sksec->sid; |
4118 | struct avc_audit_data ad; | 4131 | struct avc_audit_data ad; |
4119 | char *addrp; | 4132 | char *addrp; |
4133 | u8 secmark_active; | ||
4134 | u8 peerlbl_active; | ||
4120 | 4135 | ||
4121 | if (family != PF_INET && family != PF_INET6) | 4136 | if (family != PF_INET && family != PF_INET6) |
4122 | return 0; | 4137 | return 0; |
@@ -4125,6 +4140,18 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) | |||
4125 | if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP)) | 4140 | if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP)) |
4126 | family = PF_INET; | 4141 | family = PF_INET; |
4127 | 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 | |||
4128 | AVC_AUDIT_DATA_INIT(&ad, NET); | 4155 | AVC_AUDIT_DATA_INIT(&ad, NET); |
4129 | ad.u.net.netif = skb->iif; | 4156 | ad.u.net.netif = skb->iif; |
4130 | ad.u.net.family = family; | 4157 | ad.u.net.family = family; |
@@ -4132,15 +4159,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) | |||
4132 | if (err) | 4159 | if (err) |
4133 | return err; | 4160 | return err; |
4134 | 4161 | ||
4135 | /* If any sort of compatibility mode is enabled then handoff processing | 4162 | if (peerlbl_active) { |
4136 | * to the selinux_sock_rcv_skb_compat() function to deal with the | ||
4137 | * special handling. We do this in an attempt to keep this function | ||
4138 | * as fast and as clean as possible. */ | ||
4139 | if (selinux_compat_net || !selinux_policycap_netpeer) | ||
4140 | return selinux_sock_rcv_skb_compat(sk, skb, &ad, | ||
4141 | family, addrp); | ||
4142 | |||
4143 | if (netlbl_enabled() || selinux_xfrm_enabled()) { | ||
4144 | u32 peer_sid; | 4163 | u32 peer_sid; |
4145 | 4164 | ||
4146 | err = selinux_skb_peerlbl_sid(skb, family, &peer_sid); | 4165 | err = selinux_skb_peerlbl_sid(skb, family, &peer_sid); |
@@ -4148,13 +4167,17 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb) | |||
4148 | return err; | 4167 | return err; |
4149 | err = selinux_inet_sys_rcv_skb(skb->iif, addrp, family, | 4168 | err = selinux_inet_sys_rcv_skb(skb->iif, addrp, family, |
4150 | peer_sid, &ad); | 4169 | peer_sid, &ad); |
4151 | if (err) | 4170 | if (err) { |
4171 | selinux_netlbl_err(skb, err, 0); | ||
4152 | return err; | 4172 | return err; |
4173 | } | ||
4153 | err = avc_has_perm(sk_sid, peer_sid, SECCLASS_PEER, | 4174 | err = avc_has_perm(sk_sid, peer_sid, SECCLASS_PEER, |
4154 | PEER__RECV, &ad); | 4175 | PEER__RECV, &ad); |
4176 | if (err) | ||
4177 | selinux_netlbl_err(skb, err, 0); | ||
4155 | } | 4178 | } |
4156 | 4179 | ||
4157 | if (selinux_secmark_enabled()) { | 4180 | if (secmark_active) { |
4158 | err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET, | 4181 | err = avc_has_perm(sk_sid, skb->secmark, SECCLASS_PACKET, |
4159 | PACKET__RECV, &ad); | 4182 | PACKET__RECV, &ad); |
4160 | if (err) | 4183 | if (err) |
@@ -4213,10 +4236,12 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff * | |||
4213 | u32 peer_secid = SECSID_NULL; | 4236 | u32 peer_secid = SECSID_NULL; |
4214 | u16 family; | 4237 | u16 family; |
4215 | 4238 | ||
4216 | 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) | ||
4217 | family = sock->sk->sk_family; | 4244 | family = sock->sk->sk_family; |
4218 | else if (skb && skb->sk) | ||
4219 | family = skb->sk->sk_family; | ||
4220 | else | 4245 | else |
4221 | goto out; | 4246 | goto out; |
4222 | 4247 | ||
@@ -4274,8 +4299,6 @@ static void selinux_sock_graft(struct sock *sk, struct socket *parent) | |||
4274 | sk->sk_family == PF_UNIX) | 4299 | sk->sk_family == PF_UNIX) |
4275 | isec->sid = sksec->sid; | 4300 | isec->sid = sksec->sid; |
4276 | sksec->sclass = isec->sclass; | 4301 | sksec->sclass = isec->sclass; |
4277 | |||
4278 | selinux_netlbl_sock_graft(sk, parent); | ||
4279 | } | 4302 | } |
4280 | 4303 | ||
4281 | static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb, | 4304 | static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb, |
@@ -4283,10 +4306,15 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb, | |||
4283 | { | 4306 | { |
4284 | struct sk_security_struct *sksec = sk->sk_security; | 4307 | struct sk_security_struct *sksec = sk->sk_security; |
4285 | int err; | 4308 | int err; |
4309 | u16 family = sk->sk_family; | ||
4286 | u32 newsid; | 4310 | u32 newsid; |
4287 | u32 peersid; | 4311 | u32 peersid; |
4288 | 4312 | ||
4289 | 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); | ||
4290 | if (err) | 4318 | if (err) |
4291 | return err; | 4319 | return err; |
4292 | if (peersid == SECSID_NULL) { | 4320 | if (peersid == SECSID_NULL) { |
@@ -4321,12 +4349,18 @@ static void selinux_inet_csk_clone(struct sock *newsk, | |||
4321 | selinux_netlbl_sk_security_reset(newsksec, req->rsk_ops->family); | 4349 | selinux_netlbl_sk_security_reset(newsksec, req->rsk_ops->family); |
4322 | } | 4350 | } |
4323 | 4351 | ||
4324 | static void selinux_inet_conn_established(struct sock *sk, | 4352 | static void selinux_inet_conn_established(struct sock *sk, struct sk_buff *skb) |
4325 | struct sk_buff *skb) | ||
4326 | { | 4353 | { |
4354 | u16 family = sk->sk_family; | ||
4327 | struct sk_security_struct *sksec = sk->sk_security; | 4355 | struct sk_security_struct *sksec = sk->sk_security; |
4328 | 4356 | ||
4329 | 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); | ||
4330 | } | 4364 | } |
4331 | 4365 | ||
4332 | static void selinux_req_classify_flow(const struct request_sock *req, | 4366 | static void selinux_req_classify_flow(const struct request_sock *req, |
@@ -4376,39 +4410,54 @@ out: | |||
4376 | static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex, | 4410 | static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex, |
4377 | u16 family) | 4411 | u16 family) |
4378 | { | 4412 | { |
4413 | int err; | ||
4379 | char *addrp; | 4414 | char *addrp; |
4380 | u32 peer_sid; | 4415 | u32 peer_sid; |
4381 | struct avc_audit_data ad; | 4416 | struct avc_audit_data ad; |
4382 | u8 secmark_active; | 4417 | u8 secmark_active; |
4418 | u8 netlbl_active; | ||
4383 | u8 peerlbl_active; | 4419 | u8 peerlbl_active; |
4384 | 4420 | ||
4385 | if (!selinux_policycap_netpeer) | 4421 | if (!selinux_policycap_netpeer) |
4386 | return NF_ACCEPT; | 4422 | return NF_ACCEPT; |
4387 | 4423 | ||
4388 | secmark_active = selinux_secmark_enabled(); | 4424 | secmark_active = selinux_secmark_enabled(); |
4389 | peerlbl_active = netlbl_enabled() || selinux_xfrm_enabled(); | 4425 | netlbl_active = netlbl_enabled(); |
4426 | peerlbl_active = netlbl_active || selinux_xfrm_enabled(); | ||
4390 | if (!secmark_active && !peerlbl_active) | 4427 | if (!secmark_active && !peerlbl_active) |
4391 | return NF_ACCEPT; | 4428 | return NF_ACCEPT; |
4392 | 4429 | ||
4430 | if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0) | ||
4431 | return NF_DROP; | ||
4432 | |||
4393 | AVC_AUDIT_DATA_INIT(&ad, NET); | 4433 | AVC_AUDIT_DATA_INIT(&ad, NET); |
4394 | ad.u.net.netif = ifindex; | 4434 | ad.u.net.netif = ifindex; |
4395 | ad.u.net.family = family; | 4435 | ad.u.net.family = family; |
4396 | if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0) | 4436 | if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0) |
4397 | return NF_DROP; | 4437 | return NF_DROP; |
4398 | 4438 | ||
4399 | if (selinux_skb_peerlbl_sid(skb, family, &peer_sid) != 0) | 4439 | if (peerlbl_active) { |
4400 | return NF_DROP; | 4440 | err = selinux_inet_sys_rcv_skb(ifindex, addrp, family, |
4401 | 4441 | peer_sid, &ad); | |
4402 | if (peerlbl_active) | 4442 | if (err) { |
4403 | if (selinux_inet_sys_rcv_skb(ifindex, addrp, family, | 4443 | selinux_netlbl_err(skb, err, 1); |
4404 | peer_sid, &ad) != 0) | ||
4405 | return NF_DROP; | 4444 | return NF_DROP; |
4445 | } | ||
4446 | } | ||
4406 | 4447 | ||
4407 | if (secmark_active) | 4448 | if (secmark_active) |
4408 | if (avc_has_perm(peer_sid, skb->secmark, | 4449 | if (avc_has_perm(peer_sid, skb->secmark, |
4409 | SECCLASS_PACKET, PACKET__FORWARD_IN, &ad)) | 4450 | SECCLASS_PACKET, PACKET__FORWARD_IN, &ad)) |
4410 | return NF_DROP; | 4451 | return NF_DROP; |
4411 | 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 | |||
4412 | return NF_ACCEPT; | 4461 | return NF_ACCEPT; |
4413 | } | 4462 | } |
4414 | 4463 | ||
@@ -4432,6 +4481,37 @@ static unsigned int selinux_ipv6_forward(unsigned int hooknum, | |||
4432 | } | 4481 | } |
4433 | #endif /* IPV6 */ | 4482 | #endif /* IPV6 */ |
4434 | 4483 | ||
4484 | static 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 | |||
4506 | static 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 | |||
4435 | static int selinux_ip_postroute_iptables_compat(struct sock *sk, | 4515 | static int selinux_ip_postroute_iptables_compat(struct sock *sk, |
4436 | int ifindex, | 4516 | int ifindex, |
4437 | struct avc_audit_data *ad, | 4517 | struct avc_audit_data *ad, |
@@ -4499,30 +4579,36 @@ static int selinux_ip_postroute_iptables_compat(struct sock *sk, | |||
4499 | 4579 | ||
4500 | static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, | 4580 | static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb, |
4501 | int ifindex, | 4581 | int ifindex, |
4502 | struct avc_audit_data *ad, | 4582 | u16 family) |
4503 | u16 family, | ||
4504 | char *addrp, | ||
4505 | u8 proto) | ||
4506 | { | 4583 | { |
4507 | struct sock *sk = skb->sk; | 4584 | struct sock *sk = skb->sk; |
4508 | struct sk_security_struct *sksec; | 4585 | struct sk_security_struct *sksec; |
4586 | struct avc_audit_data ad; | ||
4587 | char *addrp; | ||
4588 | u8 proto; | ||
4509 | 4589 | ||
4510 | if (sk == NULL) | 4590 | if (sk == NULL) |
4511 | return NF_ACCEPT; | 4591 | return NF_ACCEPT; |
4512 | sksec = sk->sk_security; | 4592 | sksec = sk->sk_security; |
4513 | 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 | |||
4514 | if (selinux_compat_net) { | 4600 | if (selinux_compat_net) { |
4515 | if (selinux_ip_postroute_iptables_compat(skb->sk, ifindex, | 4601 | if (selinux_ip_postroute_iptables_compat(skb->sk, ifindex, |
4516 | ad, family, addrp)) | 4602 | &ad, family, addrp)) |
4517 | return NF_DROP; | 4603 | return NF_DROP; |
4518 | } else { | 4604 | } else { |
4519 | if (avc_has_perm(sksec->sid, skb->secmark, | 4605 | if (avc_has_perm(sksec->sid, skb->secmark, |
4520 | SECCLASS_PACKET, PACKET__SEND, ad)) | 4606 | SECCLASS_PACKET, PACKET__SEND, &ad)) |
4521 | return NF_DROP; | 4607 | return NF_DROP; |
4522 | } | 4608 | } |
4523 | 4609 | ||
4524 | if (selinux_policycap_netpeer) | 4610 | if (selinux_policycap_netpeer) |
4525 | if (selinux_xfrm_postroute_last(sksec->sid, skb, ad, proto)) | 4611 | if (selinux_xfrm_postroute_last(sksec->sid, skb, &ad, proto)) |
4526 | return NF_DROP; | 4612 | return NF_DROP; |
4527 | 4613 | ||
4528 | return NF_ACCEPT; | 4614 | return NF_ACCEPT; |
@@ -4536,23 +4622,15 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex, | |||
4536 | struct sock *sk; | 4622 | struct sock *sk; |
4537 | struct avc_audit_data ad; | 4623 | struct avc_audit_data ad; |
4538 | char *addrp; | 4624 | char *addrp; |
4539 | u8 proto; | ||
4540 | u8 secmark_active; | 4625 | u8 secmark_active; |
4541 | u8 peerlbl_active; | 4626 | u8 peerlbl_active; |
4542 | 4627 | ||
4543 | AVC_AUDIT_DATA_INIT(&ad, NET); | ||
4544 | ad.u.net.netif = ifindex; | ||
4545 | ad.u.net.family = family; | ||
4546 | if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto)) | ||
4547 | return NF_DROP; | ||
4548 | |||
4549 | /* If any sort of compatibility mode is enabled then handoff processing | 4628 | /* If any sort of compatibility mode is enabled then handoff processing |
4550 | * to the selinux_ip_postroute_compat() function to deal with the | 4629 | * to the selinux_ip_postroute_compat() function to deal with the |
4551 | * 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 |
4552 | * as fast and as clean as possible. */ | 4631 | * as fast and as clean as possible. */ |
4553 | if (selinux_compat_net || !selinux_policycap_netpeer) | 4632 | if (selinux_compat_net || !selinux_policycap_netpeer) |
4554 | return selinux_ip_postroute_compat(skb, ifindex, &ad, | 4633 | return selinux_ip_postroute_compat(skb, ifindex, family); |
4555 | family, addrp, proto); | ||
4556 | 4634 | ||
4557 | /* 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 |
4558 | * packet transformation so allow the packet to pass without any checks | 4636 | * packet transformation so allow the packet to pass without any checks |
@@ -4568,21 +4646,45 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex, | |||
4568 | if (!secmark_active && !peerlbl_active) | 4646 | if (!secmark_active && !peerlbl_active) |
4569 | return NF_ACCEPT; | 4647 | return NF_ACCEPT; |
4570 | 4648 | ||
4571 | /* 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 |
4572 | * 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 |
4573 | * 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 |
4574 | * directly from the packet */ | 4652 | * from the sending socket, otherwise use the kernel's sid */ |
4575 | sk = skb->sk; | 4653 | sk = skb->sk; |
4576 | 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 { | ||
4577 | struct sk_security_struct *sksec = sk->sk_security; | 4677 | struct sk_security_struct *sksec = sk->sk_security; |
4578 | peer_sid = sksec->sid; | 4678 | peer_sid = sksec->sid; |
4579 | secmark_perm = PACKET__SEND; | 4679 | secmark_perm = PACKET__SEND; |
4580 | } else { | ||
4581 | if (selinux_skb_peerlbl_sid(skb, family, &peer_sid)) | ||
4582 | return NF_DROP; | ||
4583 | secmark_perm = PACKET__FORWARD_OUT; | ||
4584 | } | 4680 | } |
4585 | 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 | |||
4586 | if (secmark_active) | 4688 | if (secmark_active) |
4587 | if (avc_has_perm(peer_sid, skb->secmark, | 4689 | if (avc_has_perm(peer_sid, skb->secmark, |
4588 | SECCLASS_PACKET, secmark_perm, &ad)) | 4690 | SECCLASS_PACKET, secmark_perm, &ad)) |
@@ -5656,6 +5758,13 @@ static struct nf_hook_ops selinux_ipv4_ops[] = { | |||
5656 | .pf = PF_INET, | 5758 | .pf = PF_INET, |
5657 | .hooknum = NF_INET_FORWARD, | 5759 | .hooknum = NF_INET_FORWARD, |
5658 | .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, | ||
5659 | } | 5768 | } |
5660 | }; | 5769 | }; |
5661 | 5770 | ||