calipso: Allow request sockets to be relabelled by the lsm.
Subsystems (5)
RFC PATCH 13/17 calipso: Allow request sockets to be relabelled by the lsm.
Request sockets need to have a label that takes into account the incoming connection as well as their parent's label. This is used for the outgoing SYN-ACK and for their child full-socket.
Signed-off-by Huw Davies <[email protected]>
--- include/net/netlabel.h | 6 ++++ net/ipv6/calipso.c | 78 +++++++++++++++++++++++++++++++++++++++++ net/ipv6/exthdrs.c | 16 ++++++--- net/netlabel/netlabel_calipso.c | 40 +++++++++++++++++++++ net/netlabel/netlabel_calipso.h | 4 +++ net/netlabel/netlabel_kapi.c | 39 ++++++++++++++++----- security/selinux/netlabel.c | 2 +- 7 files changed, 171 insertions(+), 14 deletions(-)
include/net/netlabel.h +6 -0
@@ -229,6 +229,8 @@ struct netlbl_lsm_secattr {* @sock_getattr: retrieve the socket's attr * @sock_setattr: set the socket's attr * @sock_delattr: remove the socket's attr +* @req_setattr: set the req socket's attr +* @req_delattr: remove the req socket's attr * * Description: * This structure is filled out by the CALIPSO engine and passed
@@ -252,6 +254,10 @@ struct netlbl_calipso_ops {const struct calipso_doi *doi_def, const struct netlbl_lsm_secattr *secattr);void (*sock_delattr)(struct sock *sk); +int (*req_setattr)(struct request_sock *req, +const struct calipso_doi *doi_def, +const struct netlbl_lsm_secattr *secattr); +void (*req_delattr)(struct request_sock *req); };/*
net/ipv6/calipso.c +78 -0
90 lines not on this page · raw message
net/ipv6/exthdrs.c +11 -5
@@ -793,7 +793,7 @@ static int ipv6_renew_option(void *ohdr,* specified option type is not copied into the new set of options. * * The new set of options is allocated from the socket option memory -* buffer of @sk. +* buffer of @sk. If @sk is NULL, then kmalloc() is used instead. */ static struct ipv6_txoptions * __ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,
@@ -828,7 +828,10 @@ __ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,return NULL ; tot_len +=sizeof (*opt2); - opt2 =sock_kmalloc (sk, tot_len,GFP_ATOMIC ); +if (sk) + opt2 =sock_kmalloc (sk, tot_len,GFP_ATOMIC ); +else + opt2 =kmalloc (tot_len,GFP_ATOMIC );if (!opt2)return ERR_PTR (-ENOBUFS );
@@ -872,7 +875,10 @@ __ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,return opt2; out: -sock_kfree_s (sk, opt2, opt2->tot_len); +if (sk) +sock_kfree_s (sk, opt2, opt2->tot_len); +else +kfree (opt2);return ERR_PTR (err); }
@@ -895,7 +901,7 @@ out:* copied into the new set of options. * * The new set of options is allocated from the socket option memory -* buffer of @sk. +* buffer of @sk. If @sk is NULL, then kmalloc() is used instead. */ struct ipv6_txoptions * ipv6_renew_options_kern(struct sock *sk, struct ipv6_txoptions *opt,
@@ -925,7 +931,7 @@ ipv6_renew_options_kern(struct sock *sk, struct ipv6_txoptions *opt,* copied into the new set of options. * * The new set of options is allocated from the socket option memory -* buffer of @sk. +* buffer of @sk. If @sk is NULL, then kmalloc() is used instead. */ struct ipv6_txoptions * ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,
net/netlabel/netlabel_calipso.c +40 -0
@@ -581,3 +581,43 @@ void calipso_sock_delattr(struct sock *sk)if (ops) ops->sock_delattr (sk); } + +/** +* calipso_req_setattr - Add a CALIPSO option to a connection request socket +* @req: the connection request socket +* @doi_def: the CALIPSO DOI to use +* @secattr: the specific security attributes of the socket +* +* Description: +* Set the CALIPSO option on the given socket using the DOI definition and +* security attributes passed to the function. Returns zero on success and +* negative values on failure. +* +*/ +int calipso_req_setattr (struct request_sock *req, +const struct calipso_doi *doi_def, +const struct netlbl_lsm_secattr *secattr) +{ +int ret_val = -ENOMSG ; +const struct netlbl_calipso_ops *ops =netlbl_calipso_ops_get (); + +if (ops) + ret_val = ops->req_setattr (req, doi_def, secattr); +return ret_val; +} + +/** +* calipso_req_delattr - Delete the CALIPSO option from a request socket +* @reg: the request socket +* +* Description: +* Removes the CALIPSO option from a request socket, if present. +* +*/ +void calipso_req_delattr (struct request_sock *req) +{ +const struct netlbl_calipso_ops *ops =netlbl_calipso_ops_get (); + +if (ops) + ops->req_delattr (req); +}
net/netlabel/netlabel_calipso.h +4 -0
@@ -135,5 +135,9 @@ int calipso_sock_setattr(struct sock *sk,const struct calipso_doi *doi_def, const struct netlbl_lsm_secattr *secattr);void calipso_sock_delattr (struct sock *sk); +int calipso_req_setattr (struct request_sock *req, +const struct calipso_doi *doi_def, +const struct netlbl_lsm_secattr *secattr); +void calipso_req_delattr (struct request_sock *req);#endif
net/netlabel/netlabel_kapi.c +31 -8
@@ -1054,12 +1054,13 @@ int netlbl_req_setattr(struct request_sock *req, {int ret_val;struct netlbl_dommap_def *entry; +struct inet_request_sock *ireq =inet_rsk (req);rcu_read_lock ();switch (req->rsk_ops->family) {case AF_INET : entry =netlbl_domhsh_getentry_af4 (secattr->domain, -inet_rsk (req)->ir_rmt_addr); + ireq->ir_rmt_addr);if (entry ==NULL ) { ret_val = -ENOENT ; goto req_setattr_return;
@@ -1070,9 +1071,7 @@ int netlbl_req_setattr(struct request_sock *req, entry->cipso, secattr);break ;case NETLBL_NLTYPE_UNLABELED : -/* just delete the protocols we support for right now -* but we could remove other protocols if needed */ -cipso_v4_req_delattr (req); +netlbl_req_delattr (req); ret_val =0 ;break ;default :
@@ -1081,9 +1080,24 @@ int netlbl_req_setattr(struct request_sock *req,break ;#if IS_ENABLED (CONFIG_IPV6 )case AF_INET6 : -/* since we don't support any IPv6 labeling protocols right -* now we can optimize everything away until we do */ - ret_val =0 ; + entry =netlbl_domhsh_getentry_af6 (secattr->domain, + &ireq->ir_v6_rmt_addr); +if (entry ==NULL ) { + ret_val = -ENOENT ; + goto req_setattr_return; + } +switch (entry->type) { +case NETLBL_NLTYPE_CALIPSO : + ret_val =calipso_req_setattr (req, + entry->calipso, secattr); +break ; +case NETLBL_NLTYPE_UNLABELED : +netlbl_req_delattr (req); + ret_val =0 ; +break ; +default : + ret_val = -ENOENT ; + }break ;#endif /* IPv6 */ default :
@@ -1105,7 +1119,16 @@ req_setattr_return:*/ void netlbl_req_delattr (struct request_sock *req) { -cipso_v4_req_delattr (req); +switch (req->rsk_ops->family) { +case AF_INET : +cipso_v4_req_delattr (req); +break ; +#if IS_ENABLED (CONFIG_IPV6 ) +case AF_INET6 : +calipso_req_delattr (req); +break ; +#endif /* IPv6 */ + } }/**
security/selinux/netlabel.c +1 -1
@@ -284,7 +284,7 @@ int selinux_netlbl_inet_conn_request(struct request_sock *req, u16 family)int rc;struct netlbl_lsm_secattr secattr; -if (family !=PF_INET ) +if (family !=PF_INET && family !=PF_INET6 )return 0 ;netlbl_secattr_init (&secattr);
Signature · 7 lines
1.8.0 _______________________________________________ Selinux mailing list [email protected] To unsubscribe, send email to [email protected] To get help, send an email containing "help" to [email protected]
net/ipv6/exthdrs.c __ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt, · line 836
Quoted 8 lines · Huw Davies
net/ipv6/exthdrs.c +4
-1tot_len +=sizeof (*opt2); - opt2 =sock_kmalloc (sk, tot_len,GFP_ATOMIC ); +if (sk) + opt2 =sock_kmalloc (sk, tot_len,GFP_ATOMIC ); +else + opt2 =kmalloc (tot_len,GFP_ATOMIC );if (!opt2)return ERR_PTR (-ENOBUFS );
This change looks dangerous to me in terms of control of memory depletion from a remote host. Could you use sk_to_full_sk and account options towards the listener socket?