aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlabel/netlabel_kapi.c
diff options
context:
space:
mode:
authorHuw Davies <huw@codeweavers.com>2016-06-27 15:02:51 -0400
committerPaul Moore <paul@paul-moore.com>2016-06-27 15:02:51 -0400
commitceba1832b1b2da0149c51de62a847c00bca1677a (patch)
tree5f03426f96c98a387cc1087865fe99b32410561c /net/netlabel/netlabel_kapi.c
parent3faa8f982f958961fda68b8d63e682fe77a032d4 (diff)
calipso: Set the calipso socket label to match the secattr.
CALIPSO is a hop-by-hop IPv6 option. A lot of this patch is based on the equivalent CISPO code. The main difference is due to manipulating the options in the hop-by-hop header. Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'net/netlabel/netlabel_kapi.c')
-rw-r--r--net/netlabel/netlabel_kapi.c58
1 files changed, 50 insertions, 8 deletions
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index 54f13a33b52c..00bab51c291e 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -37,12 +37,14 @@
37#include <net/ipv6.h> 37#include <net/ipv6.h>
38#include <net/netlabel.h> 38#include <net/netlabel.h>
39#include <net/cipso_ipv4.h> 39#include <net/cipso_ipv4.h>
40#include <net/calipso.h>
40#include <asm/bug.h> 41#include <asm/bug.h>
41#include <linux/atomic.h> 42#include <linux/atomic.h>
42 43
43#include "netlabel_domainhash.h" 44#include "netlabel_domainhash.h"
44#include "netlabel_unlabeled.h" 45#include "netlabel_unlabeled.h"
45#include "netlabel_cipso_v4.h" 46#include "netlabel_cipso_v4.h"
47#include "netlabel_calipso.h"
46#include "netlabel_user.h" 48#include "netlabel_user.h"
47#include "netlabel_mgmt.h" 49#include "netlabel_mgmt.h"
48#include "netlabel_addrlist.h" 50#include "netlabel_addrlist.h"
@@ -521,6 +523,7 @@ int netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap, u32 offset)
521 523
522 return -ENOENT; 524 return -ENOENT;
523} 525}
526EXPORT_SYMBOL(netlbl_catmap_walk);
524 527
525/** 528/**
526 * netlbl_catmap_walkrng - Find the end of a string of set bits 529 * netlbl_catmap_walkrng - Find the end of a string of set bits
@@ -656,6 +659,7 @@ int netlbl_catmap_setbit(struct netlbl_lsm_catmap **catmap,
656 659
657 return 0; 660 return 0;
658} 661}
662EXPORT_SYMBOL(netlbl_catmap_setbit);
659 663
660/** 664/**
661 * netlbl_catmap_setrng - Set a range of bits in a LSM secattr catmap 665 * netlbl_catmap_setrng - Set a range of bits in a LSM secattr catmap
@@ -870,9 +874,21 @@ int netlbl_sock_setattr(struct sock *sk,
870 break; 874 break;
871#if IS_ENABLED(CONFIG_IPV6) 875#if IS_ENABLED(CONFIG_IPV6)
872 case AF_INET6: 876 case AF_INET6:
873 /* since we don't support any IPv6 labeling protocols right 877 switch (dom_entry->def.type) {
874 * now we can optimize everything away until we do */ 878 case NETLBL_NLTYPE_ADDRSELECT:
875 ret_val = 0; 879 ret_val = -EDESTADDRREQ;
880 break;
881 case NETLBL_NLTYPE_CALIPSO:
882 ret_val = calipso_sock_setattr(sk,
883 dom_entry->def.calipso,
884 secattr);
885 break;
886 case NETLBL_NLTYPE_UNLABELED:
887 ret_val = 0;
888 break;
889 default:
890 ret_val = -ENOENT;
891 }
876 break; 892 break;
877#endif /* IPv6 */ 893#endif /* IPv6 */
878 default: 894 default:
@@ -899,6 +915,11 @@ void netlbl_sock_delattr(struct sock *sk)
899 case AF_INET: 915 case AF_INET:
900 cipso_v4_sock_delattr(sk); 916 cipso_v4_sock_delattr(sk);
901 break; 917 break;
918#if IS_ENABLED(CONFIG_IPV6)
919 case AF_INET6:
920 calipso_sock_delattr(sk);
921 break;
922#endif /* IPv6 */
902 } 923 }
903} 924}
904 925
@@ -925,7 +946,7 @@ int netlbl_sock_getattr(struct sock *sk,
925 break; 946 break;
926#if IS_ENABLED(CONFIG_IPV6) 947#if IS_ENABLED(CONFIG_IPV6)
927 case AF_INET6: 948 case AF_INET6:
928 ret_val = -ENOMSG; 949 ret_val = calipso_sock_getattr(sk, secattr);
929 break; 950 break;
930#endif /* IPv6 */ 951#endif /* IPv6 */
931 default: 952 default:
@@ -953,6 +974,9 @@ int netlbl_conn_setattr(struct sock *sk,
953{ 974{
954 int ret_val; 975 int ret_val;
955 struct sockaddr_in *addr4; 976 struct sockaddr_in *addr4;
977#if IS_ENABLED(CONFIG_IPV6)
978 struct sockaddr_in6 *addr6;
979#endif
956 struct netlbl_dommap_def *entry; 980 struct netlbl_dommap_def *entry;
957 981
958 rcu_read_lock(); 982 rcu_read_lock();
@@ -973,7 +997,7 @@ int netlbl_conn_setattr(struct sock *sk,
973 case NETLBL_NLTYPE_UNLABELED: 997 case NETLBL_NLTYPE_UNLABELED:
974 /* just delete the protocols we support for right now 998 /* just delete the protocols we support for right now
975 * but we could remove other protocols if needed */ 999 * but we could remove other protocols if needed */
976 cipso_v4_sock_delattr(sk); 1000 netlbl_sock_delattr(sk);
977 ret_val = 0; 1001 ret_val = 0;
978 break; 1002 break;
979 default: 1003 default:
@@ -982,9 +1006,27 @@ int netlbl_conn_setattr(struct sock *sk,
982 break; 1006 break;
983#if IS_ENABLED(CONFIG_IPV6) 1007#if IS_ENABLED(CONFIG_IPV6)
984 case AF_INET6: 1008 case AF_INET6:
985 /* since we don't support any IPv6 labeling protocols right 1009 addr6 = (struct sockaddr_in6 *)addr;
986 * now we can optimize everything away until we do */ 1010 entry = netlbl_domhsh_getentry_af6(secattr->domain,
987 ret_val = 0; 1011 &addr6->sin6_addr);
1012 if (entry == NULL) {
1013 ret_val = -ENOENT;
1014 goto conn_setattr_return;
1015 }
1016 switch (entry->type) {
1017 case NETLBL_NLTYPE_CALIPSO:
1018 ret_val = calipso_sock_setattr(sk,
1019 entry->calipso, secattr);
1020 break;
1021 case NETLBL_NLTYPE_UNLABELED:
1022 /* just delete the protocols we support for right now
1023 * but we could remove other protocols if needed */
1024 netlbl_sock_delattr(sk);
1025 ret_val = 0;
1026 break;
1027 default:
1028 ret_val = -ENOENT;
1029 }
988 break; 1030 break;
989#endif /* IPv6 */ 1031#endif /* IPv6 */
990 default: 1032 default: