selinux: support distinctions among all network address families
PATCH v2 1/1 selinux: support distinctions among all network address families
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to AF_ALG sockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishing AF_ALG sockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g. AF_NETBEUI, AF_SECURITY, AF_ASH, AF_ECONET, AF_SNA, AF_WANPIPE.
Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for ptrace_child is reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.
Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition for rawip_socket for SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)
security/selinux/hooks.c +73 -0
@@ -1268,6 +1268,8 @@ static inline int default_protocol_dgram(int protocol)static inline u16 socket_type_to_security_class (int family,int type,int protocol) { +int extsockclass = selinux_policycap_extsockclass; +switch (family) {case PF_UNIX :switch (type) {
@@ -1282,13 +1284,18 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoccase PF_INET6 :switch (type) {case SOCK_STREAM : +case SOCK_SEQPACKET :if (default_protocol_stream (protocol))return SECCLASS_TCP_SOCKET ; +else if (extsockclass && protocol ==IPPROTO_SCTP ) +return SECCLASS_SCTP_SOCKET ;else return SECCLASS_RAWIP_SOCKET ;case SOCK_DGRAM :if (default_protocol_dgram (protocol))return SECCLASS_UDP_SOCKET ; +else if (extsockclass && protocol ==IPPROTO_ICMP ) +return SECCLASS_ICMP_SOCKET ;else return SECCLASS_RAWIP_SOCKET ;case SOCK_DCCP :
@@ -1342,6 +1349,72 @@ static inline u16 socket_type_to_security_class(int family, int type, int protocreturn SECCLASS_APPLETALK_SOCKET ; } +if (extsockclass) { +switch (family) { +case PF_AX25 : +return SECCLASS_AX25_SOCKET ; +case PF_IPX : +return SECCLASS_IPX_SOCKET ; +case PF_NETROM : +return SECCLASS_NETROM_SOCKET ; +case PF_BRIDGE : +return SECCLASS_BRIDGE_SOCKET ; +case PF_ATMPVC : +return SECCLASS_ATMPVC_SOCKET ; +case PF_X25 : +return SECCLASS_X25_SOCKET ; +case PF_ROSE : +return SECCLASS_ROSE_SOCKET ; +case PF_DECnet: +return SECCLASS_DECNET_SOCKET ; +case PF_ATMSVC : +return SECCLASS_ATMSVC_SOCKET ; +case PF_RDS : +return SECCLASS_RDS_SOCKET ; +case PF_IRDA : +return SECCLASS_IRDA_SOCKET ; +case PF_PPPOX : +return SECCLASS_PPPOX_SOCKET ; +case PF_LLC : +return SECCLASS_LLC_SOCKET ; +case PF_IB : +return SECCLASS_IB_SOCKET ; +case PF_MPLS : +return SECCLASS_MPLS_SOCKET ; +case PF_CAN : +return SECCLASS_CAN_SOCKET ; +case PF_TIPC : +return SECCLASS_TIPC_SOCKET ; +case PF_BLUETOOTH : +return SECCLASS_BLUETOOTH_SOCKET ; +case PF_IUCV : +return SECCLASS_IUCV_SOCKET ; +case PF_RXRPC : +return SECCLASS_RXRPC_SOCKET ; +case PF_ISDN : +return SECCLASS_ISDN_SOCKET ; +case PF_PHONET : +return SECCLASS_PHONET_SOCKET ; +case PF_IEEE802154 : +return SECCLASS_IEEE802154_SOCKET ; +case PF_CAIF : +return SECCLASS_CAIF_SOCKET ; +case PF_ALG : +return SECCLASS_ALG_SOCKET ; +case PF_NFC : +return SECCLASS_NFC_SOCKET ; +case PF_VSOCK : +return SECCLASS_VSOCK_SOCKET ; +case PF_KCM : +return SECCLASS_KCM_SOCKET ; +case PF_QIPCRTR : +return SECCLASS_QIPCRTR_SOCKET ; +#if PF_MAX >43 +#error New address family defined, please update this function. +#endif + } + } +return SECCLASS_SOCKET ; }
security/selinux/include/classmap.h +68 -0
73 lines not on this page · raw message
security/selinux/include/security.h +2 -1
@@ -69,7 +69,7 @@ extern int selinux_enabled;enum {POLICYDB_CAPABILITY_NETPEER ,POLICYDB_CAPABILITY_OPENPERM , -POLICYDB_CAPABILITY_REDHAT1 , +POLICYDB_CAPABILITY_EXTSOCKCLASS ,POLICYDB_CAPABILITY_ALWAYSNETWORK , __POLICYDB_CAPABILITY_MAX };
@@ -77,6 +77,7 @@ enum {extern int selinux_policycap_netpeer;extern int selinux_policycap_openperm; +extern int selinux_policycap_extsockclass;extern int selinux_policycap_alwaysnetwork;/*
security/selinux/selinuxfs.c +1 -1
@@ -45,7 +45,7 @@static char *policycap_names[] = {"network_peer_controls" ,"open_perms" , -"redhat1" , +"extended_socket_class" ,"always_check_network" };
security/selinux/ss/services.c +3 -0
@@ -72,6 +72,7 @@int selinux_policycap_netpeer;int selinux_policycap_openperm; +int selinux_policycap_extsockclass;int selinux_policycap_alwaysnetwork;static DEFINE_RWLOCK (policy_rwlock);
@@ -1988,6 +1989,8 @@ static void security_load_policycaps(void) POLICYDB_CAPABILITY_NETPEER); selinux_policycap_openperm =ebitmap_get_bit (&policydb.policycaps,POLICYDB_CAPABILITY_OPENPERM ); + selinux_policycap_extsockclass =ebitmap_get_bit (&policydb.policycaps, +POLICYDB_CAPABILITY_EXTSOCKCLASS ); selinux_policycap_alwaysnetwork =ebitmap_get_bit (&policydb.policycaps,POLICYDB_CAPABILITY_ALWAYSNETWORK ); }
Signature · 1 line
2.7.4
Paul Moore
maintainerQuoted 34 lines · Stephen Smalley
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to
AF_ALGsockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishingAF_ALGsockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g.AF_NETBEUI,AF_SECURITY,AF_ASH,AF_ECONET,AF_SNA,AF_WANPIPE.Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for
ptrace_childis reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
Signed-off-by Stephen Smalley <[email protected]>---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition forrawip_socketfor SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.
Quoted 6 lines
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)
You mentioned IGMP previously, if we have a class for ICMP, it seems reasonable to have one for IGMP, don't you think? Although this does spiral a bit if we consider all the IPPROTO* protocols.
Quoted 241 lines
security/selinux/hooks.c +73
-0@@ -1268,6 +1268,8 @@ static inline int default_protocol_dgram(int protocol)static inline u16 socket_type_to_security_class (int family,int type,int protocol) { +int extsockclass = selinux_policycap_extsockclass; +switch (family) {case PF_UNIX :switch (type) {@@ -1282,13 +1284,18 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoccase PF_INET6 :switch (type) {case SOCK_STREAM : +case SOCK_SEQPACKET :if (default_protocol_stream (protocol))return SECCLASS_TCP_SOCKET ; +else if (extsockclass && protocol ==IPPROTO_SCTP ) +return SECCLASS_SCTP_SOCKET ;else return SECCLASS_RAWIP_SOCKET ;case SOCK_DGRAM :if (default_protocol_dgram (protocol))return SECCLASS_UDP_SOCKET ; +else if (extsockclass && protocol ==IPPROTO_ICMP ) +return SECCLASS_ICMP_SOCKET ;else return SECCLASS_RAWIP_SOCKET ;case SOCK_DCCP :@@ -1342,6 +1349,72 @@ static inline u16 socket_type_to_security_class(int family, int type, int protocreturn SECCLASS_APPLETALK_SOCKET ; } +if (extsockclass) { +switch (family) { +case PF_AX25 : +return SECCLASS_AX25_SOCKET ; +case PF_IPX : +return SECCLASS_IPX_SOCKET ; +case PF_NETROM : +return SECCLASS_NETROM_SOCKET ; +case PF_BRIDGE : +return SECCLASS_BRIDGE_SOCKET ; +case PF_ATMPVC : +return SECCLASS_ATMPVC_SOCKET ; +case PF_X25 : +return SECCLASS_X25_SOCKET ; +case PF_ROSE : +return SECCLASS_ROSE_SOCKET ; +case PF_DECnet: +return SECCLASS_DECNET_SOCKET ; +case PF_ATMSVC : +return SECCLASS_ATMSVC_SOCKET ; +case PF_RDS : +return SECCLASS_RDS_SOCKET ; +case PF_IRDA : +return SECCLASS_IRDA_SOCKET ; +case PF_PPPOX : +return SECCLASS_PPPOX_SOCKET ; +case PF_LLC : +return SECCLASS_LLC_SOCKET ; +case PF_IB : +return SECCLASS_IB_SOCKET ; +case PF_MPLS : +return SECCLASS_MPLS_SOCKET ; +case PF_CAN : +return SECCLASS_CAN_SOCKET ; +case PF_TIPC : +return SECCLASS_TIPC_SOCKET ; +case PF_BLUETOOTH : +return SECCLASS_BLUETOOTH_SOCKET ; +case PF_IUCV : +return SECCLASS_IUCV_SOCKET ; +case PF_RXRPC : +return SECCLASS_RXRPC_SOCKET ; +case PF_ISDN : +return SECCLASS_ISDN_SOCKET ; +case PF_PHONET : +return SECCLASS_PHONET_SOCKET ; +case PF_IEEE802154 : +return SECCLASS_IEEE802154_SOCKET ; +case PF_CAIF : +return SECCLASS_CAIF_SOCKET ; +case PF_ALG : +return SECCLASS_ALG_SOCKET ; +case PF_NFC : +return SECCLASS_NFC_SOCKET ; +case PF_VSOCK : +return SECCLASS_VSOCK_SOCKET ; +case PF_KCM : +return SECCLASS_KCM_SOCKET ; +case PF_QIPCRTR : +return SECCLASS_QIPCRTR_SOCKET ; +#if PF_MAX >43 +#error New address family defined, please update this function. +#endif + } + } +return SECCLASS_SOCKET ; }security/selinux/include/classmap.h +68
-0@@ -169,5 +169,73 @@ struct security_class_mapping secclass_map[] = { { COMMON_CAP_PERMS, NULL } }, {"cap2_userns" , { COMMON_CAP2_PERMS, NULL } }, + {"sctp_socket" , + { COMMON_SOCK_PERMS, + "node_bind", NULL } }, + {"icmp_socket" , + { COMMON_SOCK_PERMS, + "node_bind", NULL } }, + { "ax25_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "ipx_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "netrom_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "bridge_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "atmpvc_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "x25_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "rose_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "decnet_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "atmsvc_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "rds_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "irda_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "pppox_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "llc_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "ib_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "mpls_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "can_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "tipc_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "bluetooth_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "iucv_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "rxrpc_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "isdn_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "phonet_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "ieee802154_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "caif_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "alg_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "nfc_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "vsock_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "kcm_socket", + { COMMON_SOCK_PERMS, NULL } }, + { "qipcrtr_socket", + { COMMON_SOCK_PERMS, NULL } }, { NULL } }; + +#if PF_MAX >43 +#error New address family defined, please update secclass_map. +#endif security/selinux/include/security.h +2
-1@@ -69,7 +69,7 @@ extern int selinux_enabled;enum {POLICYDB_CAPABILITY_NETPEER ,POLICYDB_CAPABILITY_OPENPERM , -POLICYDB_CAPABILITY_REDHAT1 , +POLICYDB_CAPABILITY_EXTSOCKCLASS ,POLICYDB_CAPABILITY_ALWAYSNETWORK , __POLICYDB_CAPABILITY_MAX };@@ -77,6 +77,7 @@ enum {extern int selinux_policycap_netpeer;extern int selinux_policycap_openperm; +extern int selinux_policycap_extsockclass;extern int selinux_policycap_alwaysnetwork;/* security/selinux/selinuxfs.c +1
-1@@ -45,7 +45,7 @@static char *policycap_names[] = {"network_peer_controls" ,"open_perms" , -"redhat1" , +"extended_socket_class" ,"always_check_network" };security/selinux/ss/services.c +3
-1@@ -72,6 +72,7 @@int selinux_policycap_netpeer;int selinux_policycap_openperm; +int selinux_policycap_extsockclass;int selinux_policycap_alwaysnetwork;static DEFINE_RWLOCK (policy_rwlock);@@ -1988,6 +1989,8 @@ static void security_load_policycaps(void) POLICYDB_CAPABILITY_NETPEER); selinux_policycap_openperm =ebitmap_get_bit (&policydb.policycaps,POLICYDB_CAPABILITY_OPENPERM ); + selinux_policycap_extsockclass =ebitmap_get_bit (&policydb.policycaps, +POLICYDB_CAPABILITY_EXTSOCKCLASS ); selinux_policycap_alwaysnetwork =ebitmap_get_bit (&policydb.policycaps,POLICYDB_CAPABILITY_ALWAYSNETWORK ); } --2.7.4
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 42 lines · Paul Moore
Quoted 34 lines · Stephen Smalley
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to
AF_ALGsockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishingAF_ALGsockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g.AF_NETBEUI,AF_SECURITY,AF_ASH,AF_ECONET,AF_SNA,AF_WANPIPE.Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for
ptrace_childis reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
Signed-off-by Stephen Smalley <[email protected]>---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition forrawip_socketfor SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.Quoted 6 lines
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)
Quoted 3 lines
You mentioned IGMP previously, if we have a class for ICMP, it seems reasonable to have one for IGMP, don't you think? Although this does spiral a bit if we consider all the IPPROTO* protocols.
I thought about it, but the kernel does not provide IGMP sockets per se, unlike ICMP or SCTP sockets (i.e. ipv4/af_inet.c:inetsw_array[] defines an entry for SOCK_DGRAM, IPPROTO_ICMP and sctp/protocol.c defines and registers inet_protosw entries for SOCK_STREAM, IPPROTO_SCTP and SOCK_SEQPACKET, IPPROTO_SCTP; there is no equivalent for IGMP unless I missed it). So IGMP sockets are just raw IP sockets with a particular protocol value; they have no stream, seqpacket, or dgram semantics, and it is unclear it is worthwhile to distinguish them in policy.
Paul Moore
maintainerQuoted 47 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 34 lines · Stephen Smalley
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to
AF_ALGsockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishingAF_ALGsockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g.AF_NETBEUI,AF_SECURITY,AF_ASH,AF_ECONET,AF_SNA,AF_WANPIPE.Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for
ptrace_childis reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
Signed-off-by Stephen Smalley <[email protected]>---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition forrawip_socketfor SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.Quoted 6 lines
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)Quoted 3 lines
You mentioned IGMP previously, if we have a class for ICMP, it seems reasonable to have one for IGMP, don't you think? Although this does spiral a bit if we consider all the IPPROTO* protocols.
Quoted 8 lines
I thought about it, but the kernel does not provide IGMP sockets per se, unlike ICMP or SCTP sockets (i.e. ipv4/af_inet.c:inetsw_array[] defines an entry for
SOCK_DGRAM,IPPROTO_ICMPandsctp/protocol.cdefines and registersinet_protoswentries forSOCK_STREAM,IPPROTO_SCTPandSOCK_SEQPACKET,IPPROTO_SCTP; there is no equivalent for IGMP unless I missed it). So IGMP sockets are just raw IP sockets with a particular protocol value; they have no stream, seqpacket, or dgram semantics, and it is unclear it is worthwhile to distinguish them in policy.
Yes, sorry about that, it looks like you're right. I thought there might be some sort of IGMP routing daemon or something that would need to create an IGMP socket, but it looks like you just configure the kernel's multicast routing table and the kernel takes care of the IGMP packets.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 57 lines · Paul Moore
Quoted 47 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 34 lines · Stephen Smalley
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to
AF_ALGsockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishingAF_ALGsockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g.AF_NETBEUI,AF_SECURITY,AF_ASH,AF_ECONET,AF_SNA,AF_WANPIPE.Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for
ptrace_childis reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
Signed-off-by Stephen Smalley <[email protected]>---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition forrawip_socketfor SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.Quoted 6 lines
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)Quoted 3 lines
You mentioned IGMP previously, if we have a class for ICMP, it seems reasonable to have one for IGMP, don't you think? Although this does spiral a bit if we consider all the IPPROTO* protocols.
Quoted 8 lines
I thought about it, but the kernel does not provide IGMP sockets per se, unlike ICMP or SCTP sockets (i.e. ipv4/af_inet.c:inetsw_array[] defines an entry for
SOCK_DGRAM,IPPROTO_ICMPandsctp/protocol.cdefines and registersinet_protoswentries forSOCK_STREAM,IPPROTO_SCTPandSOCK_SEQPACKET,IPPROTO_SCTP; there is no equivalent for IGMP unless I missed it). So IGMP sockets are just raw IP sockets with a particular protocol value; they have no stream, seqpacket, or dgram semantics, and it is unclear it is worthwhile to distinguish them in policy.
Quoted 5 lines
Yes, sorry about that, it looks like you're right. I thought there might be some sort of IGMP routing daemon or something that would need to create an IGMP socket, but it looks like you just configure the kernel's multicast routing table and the kernel takes care of the IGMP packets.
Well, I think you can create an IGMP socket ala socket(PF_INET, SOCK_RAW, IPPROTO_IGMP). And we could map that to a IGMP socket class if we really wanted to do so. But that would be the first time we ever mapped a (PF_INET, SOCK_RAW, proto) to something other than SECCLASS_RAWIP_SOCKET. And at that point we'd probably want to map every individual protocol value. Not sure we need/want to go there.
Paul Moore
maintainerQuoted 64 lines · Stephen Smalley
Quoted 57 lines · Paul Moore
Quoted 47 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 34 lines · Stephen Smalley
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to
AF_ALGsockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishingAF_ALGsockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g.AF_NETBEUI,AF_SECURITY,AF_ASH,AF_ECONET,AF_SNA,AF_WANPIPE.Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for
ptrace_childis reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
Signed-off-by Stephen Smalley <[email protected]>---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition forrawip_socketfor SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.Quoted 6 lines
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)Quoted 3 lines
You mentioned IGMP previously, if we have a class for ICMP, it seems reasonable to have one for IGMP, don't you think? Although this does spiral a bit if we consider all the IPPROTO* protocols.
Quoted 8 lines
I thought about it, but the kernel does not provide IGMP sockets per se, unlike ICMP or SCTP sockets (i.e. ipv4/af_inet.c:inetsw_array[] defines an entry for
SOCK_DGRAM,IPPROTO_ICMPandsctp/protocol.cdefines and registersinet_protoswentries forSOCK_STREAM,IPPROTO_SCTPandSOCK_SEQPACKET,IPPROTO_SCTP; there is no equivalent for IGMP unless I missed it). So IGMP sockets are just raw IP sockets with a particular protocol value; they have no stream, seqpacket, or dgram semantics, and it is unclear it is worthwhile to distinguish them in policy.Quoted 5 lines
Yes, sorry about that, it looks like you're right. I thought there might be some sort of IGMP routing daemon or something that would need to create an IGMP socket, but it looks like you just configure the kernel's multicast routing table and the kernel takes care of the IGMP packets.
Quoted 6 lines
Well, I think you can create an IGMP socket ala
socket(PF_INET, SOCK_RAW, IPPROTO_IGMP). And we could map that to a IGMP socket class if we really wanted to do so. But that would be the first time we ever mapped a (PF_INET,SOCK_RAW, proto) to something other thanSECCLASS_RAWIP_SOCKET. And at that point we'd probably want to map every individual protocol value. Not sure we need/want to go there.
Yes, creating classes for each IPPROTO value is not something I think we want to do, although I have no problem doing it for key protocols as necessary.
I just merged this into selinux#next, the pull request for v4.10 was already sent up to James so this will go in during the v4.11 merge window (I think this can wait, it might give us time to get some of the policy ready).
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 72 lines · Paul Moore
Quoted 64 lines · Stephen Smalley
Quoted 57 lines · Paul Moore
Quoted 47 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 34 lines · Stephen Smalley
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to
AF_ALGsockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishingAF_ALGsockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g.AF_NETBEUI,AF_SECURITY,AF_ASH,AF_ECONET,AF_SNA,AF_WANPIPE.Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for
ptrace_childis reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
Signed-off-by Stephen Smalley <[email protected]>---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition forrawip_socketfor SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.Quoted 6 lines
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)Quoted 3 lines
You mentioned IGMP previously, if we have a class for ICMP, it seems reasonable to have one for IGMP, don't you think? Although this does spiral a bit if we consider all the IPPROTO* protocols.
Quoted 8 lines
I thought about it, but the kernel does not provide IGMP sockets per se, unlike ICMP or SCTP sockets (i.e. ipv4/af_inet.c:inetsw_array[] defines an entry for
SOCK_DGRAM,IPPROTO_ICMPandsctp/protocol.cdefines and registersinet_protoswentries forSOCK_STREAM,IPPROTO_SCTPandSOCK_SEQPACKET,IPPROTO_SCTP; there is no equivalent for IGMP unless I missed it). So IGMP sockets are just raw IP sockets with a particular protocol value; they have no stream, seqpacket, or dgram semantics, and it is unclear it is worthwhile to distinguish them in policy.Quoted 5 lines
Yes, sorry about that, it looks like you're right. I thought there might be some sort of IGMP routing daemon or something that would need to create an IGMP socket, but it looks like you just configure the kernel's multicast routing table and the kernel takes care of the IGMP packets.
Quoted 6 lines
Well, I think you can create an IGMP socket ala
socket(PF_INET, SOCK_RAW, IPPROTO_IGMP). And we could map that to a IGMP socket class if we really wanted to do so. But that would be the first time we ever mapped a (PF_INET,SOCK_RAW, proto) to something other thanSECCLASS_RAWIP_SOCKET. And at that point we'd probably want to map every individual protocol value. Not sure we need/want to go there.
Quoted 8 lines
Yes, creating classes for each IPPROTO value is not something I think we want to do, although I have no problem doing it for key protocols as necessary.
I just merged this into selinux#next, the pull request for v4.10 was already sent up to James so this will go in during the v4.11 merge window (I think this can wait, it might give us time to get some of the policy ready).
Yes, sounds good. I just pushed the patch for libsepol that allows one to specify the new policy capability in policy, and attached is a patch for Fedora's policy that you can add to its .spec file and rebuild if you want to try it out (but you first have to build and install the updated selinux userspace that defines it). May submit a modified form for upstream refpolicy that just comments out the policy capability so that we don't break building refpolicy on the currently released libsepol.
policy/flask/access_vectors +115 -0
@@ -950,3 +950,118 @@ class cap2_userns inherits cap2 + +# +# Define the access vector interpretation for the new socket classes +# enabled by the extended_socket_class policy capability. +# + +# +# The next two classes were previously mapped to rawip_socket and therefore +# have the same definition as rawip_socket (until further permissions +# are defined). +# +class sctp_socket +inherits socket +{ + node_bind +} + +class icmp_socket +inherits socket +{ + node_bind +} + +# +# The remaining network socket classes were previously +# mapped to the socket class and therefore have the +# same definition as socket. +# + +class ax25_socket +inherits socket + +class ipx_socket +inherits socket + +class netrom_socket +inherits socket + +class bridge_socket +inherits socket + +class atmpvc_socket +inherits socket + +class x25_socket +inherits socket + +class rose_socket +inherits socket + +class decnet_socket +inherits socket + +class atmsvc_socket +inherits socket + +class rds_socket +inherits socket + +class irda_socket +inherits socket + +class pppox_socket +inherits socket + +class llc_socket +inherits socket + +class ib_socket +inherits socket + +class mpls_socket +inherits socket + +class can_socket +inherits socket + +class tipc_socket +inherits socket + +class bluetooth_socket +inherits socket + +class iucv_socket +inherits socket + +class rxrpc_socket +inherits socket + +class isdn_socket +inherits socket + +class phonet_socket +inherits socket + +class ieee802154_socket +inherits socket + +class caif_socket +inherits socket + +class alg_socket +inherits socket + +class nfc_socket +inherits socket + +class vsock_socket +inherits socket + +class kcm_socket +inherits socket + +class qipcrtr_socket +inherits socket
policy/flask/security_classes +35 -0
@@ -154,4 +154,39 @@ class cap_userns class cap2_userns +# New socket classes introduced by extended_socket_class policy capability. +# These two were previously mapped to rawip_socket. +class sctp_socket +class icmp_socket +# These were previously mapped to socket. +class ax25_socket +class ipx_socket +class netrom_socket +class bridge_socket +class atmpvc_socket +class x25_socket +class rose_socket +class decnet_socket +class atmsvc_socket +class rds_socket +class irda_socket +class pppox_socket +class llc_socket +class ib_socket +class mpls_socket +class can_socket +class tipc_socket +class bluetooth_socket +class iucv_socket +class rxrpc_socket +class isdn_socket +class phonet_socket +class ieee802154_socket +class caif_socket +class alg_socket +class nfc_socket +class vsock_socket +class kcm_socket +class qipcrtr_socket + # FLASK
policy/policy_capabilities +41 -0
44 lines not on this page · raw message
policy/support/obj_perm_sets.spt +1 -1
@@ -28,7 +28,7 @@ # # All socket classes. # -define(`socket_class_set', `{ tcp_socket udp_socket rawip_socket netlink_socket packet_socket unix_stream_socket unix_dgram_socket appletalk_socket netlink_route_socket netlink_firewall_socket netlink_tcpdiag_socket netlink_nflog_socket netlink_xfrm_socket netlink_selinux_socket netlink_audit_socket netlink_ip6fw_socket netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket netlink_rdma_socket netlink_crypto_socket }') +define(`socket_class_set', `{ tcp_socket udp_socket rawip_socket netlink_socket packet_socket unix_stream_socket unix_dgram_socket appletalk_socket netlink_route_socket netlink_firewall_socket netlink_tcpdiag_socket netlink_nflog_socket netlink_xfrm_socket netlink_selinux_socket netlink_audit_socket netlink_ip6fw_socket netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket netlink_rdma_socket netlink_crypto_socket sctp_socket icmp_socket ax25_socket ipx_socket netrom_socket bridge_socket atmpvc_socket x25_socket rose_socket decnet_socket atmsvc_socket rds_socket irda_socket pppox_socket llc_socket ib_socket mpls_socket can_socket tipc_socket bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket alg_socket nfc_socket vsock_socket kcm_socket qipcrtr_socket}') # # Datagram socket classes.
Quoted 72 lines · Paul Moore
Quoted 64 lines · Stephen Smalley
Quoted 57 lines · Paul Moore
Quoted 47 lines · Stephen Smalley
Quoted 42 lines · Paul Moore
Quoted 34 lines · Stephen Smalley
Extend SELinux to support distinctions among all network address families implemented by the kernel by defining new socket security classes and mapping to them. Otherwise, many sockets are mapped to the generic socket class and are indistinguishable in policy. This has come up previously with regard to selectively allowing access to bluetooth sockets, and more recently with regard to selectively allowing access to
AF_ALGsockets. Guido Trentalancia submitted a patch that took a similar approach to add only support for distinguishingAF_ALGsockets, but this generalizes his approach to handle all address families implemented by the kernel. Socket security classes are also added for ICMP and SCTP sockets. Socket security classes were not defined for AF_* values that are reserved but unimplemented in the kernel, e.g.AF_NETBEUI,AF_SECURITY,AF_ASH,AF_ECONET,AF_SNA,AF_WANPIPE.Backward compatibility is provided by only enabling the finer-grained socket classes if a new policy capability is set in the policy; older policies will behave as before. The legacy redhat1 policy capability that was only ever used in testing within Fedora for
ptrace_childis reclaimed for this purpose; as far as I can tell, this policy capability is not enabled in any supported distro policy.Add a pair of conditional compilation guards to detect when new AF_* values are added so that we can update SELinux accordingly rather than having to belatedly update it long after new address families are introduced.
Signed-off-by Stephen Smalley <[email protected]>---
v2 reworks the style based on comments from Guido Trentalancia and adds security classes for SCTP and ICMP sockets. The security class support for SCTP sockets was based on Richard Haines' SCTP patch set. For now, we only duplicate the class definition forrawip_socketfor SCTP and ICMP sockets since that is how they were previously mapped. The SCTP definition can be further fleshed out by the SCTP patch set itself.Quoted 6 lines
security/selinux/hooks.c | 73 +++++++++++++++++++++++++++++++++++++ security/selinux/include/classmap.h | 68 ++++++++++++++++++++++++++++++++++ security/selinux/include/security.h | 3 +- security/selinux/selinuxfs.c | 2 +- security/selinux/ss/services.c | 3 ++ 5 files changed, 147 insertions(+), 2 deletions(-)Quoted 3 lines
You mentioned IGMP previously, if we have a class for ICMP, it seems reasonable to have one for IGMP, don't you think? Although this does spiral a bit if we consider all the IPPROTO* protocols.
Quoted 8 lines
I thought about it, but the kernel does not provide IGMP sockets per se, unlike ICMP or SCTP sockets (i.e. ipv4/af_inet.c:inetsw_array[] defines an entry for
SOCK_DGRAM,IPPROTO_ICMPandsctp/protocol.cdefines and registersinet_protoswentries forSOCK_STREAM,IPPROTO_SCTPandSOCK_SEQPACKET,IPPROTO_SCTP; there is no equivalent for IGMP unless I missed it). So IGMP sockets are just raw IP sockets with a particular protocol value; they have no stream, seqpacket, or dgram semantics, and it is unclear it is worthwhile to distinguish them in policy.Quoted 5 lines
Yes, sorry about that, it looks like you're right. I thought there might be some sort of IGMP routing daemon or something that would need to create an IGMP socket, but it looks like you just configure the kernel's multicast routing table and the kernel takes care of the IGMP packets.
Quoted 6 lines
Well, I think you can create an IGMP socket ala
socket(PF_INET, SOCK_RAW, IPPROTO_IGMP). And we could map that to a IGMP socket class if we really wanted to do so. But that would be the first time we ever mapped a (PF_INET,SOCK_RAW, proto) to something other thanSECCLASS_RAWIP_SOCKET. And at that point we'd probably want to map every individual protocol value. Not sure we need/want to go there.
Quoted 8 lines
Yes, creating classes for each IPPROTO value is not something I think we want to do, although I have no problem doing it for key protocols as necessary.
I just merged this into selinux#next, the pull request for v4.10 was already sent up to James so this will go in during the v4.11 merge window (I think this can wait, it might give us time to get some of the policy ready).
Wanted to clarify one point and also mention a bug/deficiency of this patch that I just realized:
- Clarification: At present, the patch will map PF_INET, SOCK_DGRAM, IPPROTO_ICMP to icmp_socket, but will continue to map PF_INET, SOCK_RAW, IPPROTO_ICMP to rawip_socket. That's intentional, since the SOCK_DGRAM IPPROTO_ICMP sockets were introduced to provide a more restricted form of ICMP sockets that could be exposed to unprivileged users (based on a sysctl), so distinguishing those in policy makes sense. But it could be surprising.
- Bug/deficiency: I hadn't noticed that there is a separate IPPROTO_ICMPV6, so I'll need to modify this patch or post a follow-on that ensure that we map SOCK_DGRAM,IPPROTO_ICMPV6 to icmp_socket too.
Paul Moore
maintainerQuoted 10 lines · Stephen Smalley
Wanted to clarify one point and also mention a bug/deficiency of this patch that I just realized:
- Clarification: At present, the patch will map
PF_INET,SOCK_DGRAM,IPPROTO_ICMPtoicmp_socket, but will continue to mapPF_INET,SOCK_RAW,IPPROTO_ICMPtorawip_socket. That's intentional, since theSOCK_DGRAMIPPROTO_ICMPsockets were introduced to provide a more restricted form of ICMP sockets that could be exposed to unprivileged users (based on a sysctl), so distinguishing those in policy makes sense. But it could be surprising.
Yes, I have no problem with this behavior.
Quoted 3 lines
- Bug/deficiency: I hadn't noticed that there is a separate
IPPROTO_ICMPV6, so I'll need to modify this patch or post a follow-on that ensure that we map SOCK_DGRAM,IPPROTO_ICMPV6 toicmp_sockettoo.
Merged your follow-up patch.
Signature · 2 lines
paul moore www.paul-moore.com
Hello.
Quoted 1 line · Stephen Smalley
On 12/06/2016 07:13 PM, Paul Moore wrote:
[...]
Quoted 6 lines
Quoted 5 lines
You mentioned IGMP previously, if we have a class for ICMP, it seems
reasonable to have one for IGMP, don't you think? Although this does
spiral a bit if we consider all the IPPROTO* protocols.
Quoted 13 lines
I thought about it, but the kernel does not provide IGMP sockets per se,
unlike ICMP or SCTP sockets (i.e. ipv4/af_inet.c:inetsw_array[] defines
an entry forSOCK_DGRAM,IPPROTO_ICMPandsctp/protocol.cdefines and registersinet_protoswentries forSOCK_STREAM,IPPROTO_SCTPandSOCK_SEQPACKET,IPPROTO_SCTP; there is no equivalent for IGMP unless I
missed it). So IGMP sockets are just raw IP sockets with a particular
protocol value; they have no stream, seqpacket, or dgram semantics, and
it is unclear it is worthwhile to distinguish them in policy.
I suppose distinguishing IGMP packets brings little benefit in terms of security.
Regards,
Guido