selinux-testsuite: add secmark tests
PATCH 1/1 selinux-testsuite: add secmark tests
Add tests for SECMARK. To support this, we add a -n option to the client and server test programs to disable the testing of SO_PEERSEC and SCM_SECURITY since SECMARK does not provide peer labeling, only internal packet labeling.
Signed-off-by Stephen Smalley <[email protected]>
--- README | 11 +++++++--- policy/test_inet_socket.te | 9 ++++++++ tests/inet_socket/client.c | 42 +++++++++++++++++++++++++++++--------- tests/inet_socket/iptables-flush | 4 ++++ tests/inet_socket/iptables-load | 29 ++++++++++++++++++++++++++ tests/inet_socket/server.c | 44 +++++++++++++++++++++++++++++----------- tests/inet_socket/test | 44 +++++++++++++++++++++++++++++++++++++++- 7 files changed, 157 insertions(+), 26 deletions(-) create mode 100755 tests/inet_socket/iptables-flush create mode 100755 tests/inet_socket/iptables-load
README +8 -3
@@ -21,6 +21,10 @@ CONFIG_SECURITY_NETWORK=y CONFIG_SECURITY_NETWORK_XFRM=y CONFIG_SECURITY_SELINUX=y CONFIG_NETLABEL=y +CONFIG_NETWORK_SECMARK=y +CONFIG_NF_CONNTRACK_SECMARK=y +CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=m +CONFIG_NETFILTER_XT_TARGET_SECMARK=m # Filesystem security labeling support. # Only need to enable the ones for the filesystems on which you are testing.
@@ -70,9 +74,10 @@ rely upon the SELinux extensions being integrated into the coreutils package, with support for the chcon and runcon commands as well as the SELinux options to existing utilities such as ls and mkdir. -The inet_socket tests depend on netlabel_tools being installed in -order to load NetLabel configuration, and on ipsec-tools being installed -in order to load labeled IPSEC configuration. +The inet_socket tests depend on netlabel_tools, ipsec-tools, and +iptables in order to load the relevant configurations for testing +netlabel peer labeling, labeled IPSEC peer labeling, and SECMARK +packet labeling. In addition to the libselinux shared library, the libselinux headers are required in order to build certain testcases. These can be found in
policy/test_inet_socket.te +9 -0
@@ -139,6 +139,15 @@ allow test_inet_client_t test_spd_t:association polmatch; allow test_inet_bad_client_t test_spd_t:association polmatch; # +# SECMARK-specific policy +# + +type test_server_packet_t; +allow unconfined_t test_server_packet_t:packet relabelto; +allow test_inet_server_t test_server_packet_t:packet { send recv }; +allow test_inet_client_t test_server_packet_t:packet { send recv }; + +# # Common rules for all inet socket test domains. #
tests/inet_socket/client.c +32 -10
73 lines not on this page · raw message
tests/inet_socket/iptables-flush new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh +# Flush the security table. +iptables -t security -F +iptables -t security -X NEWCONN
tests/inet_socket/iptables-load new file +29 -0
@@ -0,0 +1,29 @@ +#!/bin/sh +# Based on http://james-morris.livejournal.com/11010.html. +# +# Modifications: +# - Changed to use the security table, which was created for SECMARK to +# avoid conflicts with other users of the mangle table. +# - Added entries for udp traffic for testing udp as well. +# - Specified the interface since the tests are only performed over loopback. +# - Set the port number and context to the values used by the test script and policy. + +# Flush the security table. +iptables -t security -F + +# Create a chain for new connection marking. +iptables -t security -N NEWCONN + +# Accept incoming connections, label SYN packets, and copy labels to connections. +iptables -t security -A INPUT -i lo -p tcp --dport 65535 -m state --state NEW -j NEWCONN +iptables -t security -A NEWCONN -j SECMARK --selctx system_u:object_r:test_server_packet_t:s0 +iptables -t security -A NEWCONN -j CONNSECMARK --save +iptables -t security -A NEWCONN -j ACCEPT + +# Common rules which copy connection labels to established and related packets. +iptables -t security -A INPUT -m state --state ESTABLISHED,RELATED -j CONNSECMARK --restore +iptables -t security -A OUTPUT -m state --state ESTABLISHED,RELATED -j CONNSECMARK --restore + +# Label UDP packets similarly. +iptables -t security -A INPUT -i lo -p udp --dport 65535 -j SECMARK --selctx system_u:object_r:test_server_packet_t:s0 +iptables -t security -A OUTPUT -o lo -p udp --sport 65535 -j SECMARK --selctx system_u:object_r:test_server_packet_t:s0
tests/inet_socket/server.c +32 -12
83 lines not on this page · raw message
tests/inet_socket/test +43 -1
54 lines not on this page · raw message
Signature · 1 line
2.1.0