tests/inet_socket: test CALIPSO over the IPv6 forwarding path
PATCH 1/1 tests/inet_socket: test CALIPSO over the IPv6 forwarding path
The existing CALIPSO tests only run over loopback, so the code that rewrites the IPv6 header of forwarded packets (calipso_skbuff_delattr() and calipso_skbuff_setattr(), called from selinux_ip_forward()) is not covered.
Add two subtests that build a client -- router -- server topology out of network namespaces and send traffic through the router:
- the client labels its packets with CALIPSO and the router, mapped to unlabeled, removes the option;
- the client sends unlabeled packets and the router adds a CALIPSO option.
The first one catches the payload_len bug fixed by "calipso: update payload_len when removing the CALIPSO option": without the fix the server drops the forwarded packet as truncated (Ip6InTruncatedPkts).
Commands inside the namespaces use nsenter(1) as "ip netns exec" and "ip -n" remount /sys, which is denied when running as sysadm_t. The policy now allows unlabeled_t traffic on the generic interface and node, needed for the unlabeled packets the router forwards.
Tested on Fedora 44 (aarch64), as unconfined_t and sysadm_t:
- 6.19.10-300.fc44: the new removal subtest fails (udp, tcp, mptcp), the new addition subtest passes;
- 7.3-rc6 with the fix: all inet_socket and sctp tests pass.
---
Also posted as https://github.com/SELinuxProject/selinux-testsuite/pull/106
(now closed in favour of this posting).
Until "calipso: update payload_len when removing the CALIPSO option" reaches the kernel used by the CI, the removal subtest is expected to fail there; I can gate it on a kernel version once the fix is merged, if preferred.
policy/test_inet_socket.te | 8 ++++ tests/inet_socket/calipso-fwd-add-load | 10 +++++ tests/inet_socket/calipso-fwd-cleanup | 6 +++ tests/inet_socket/calipso-fwd-del-load | 9 ++++ tests/inet_socket/calipso-fwd-flush | 7 +++ tests/inet_socket/calipso-fwd-setup | 50 +++++++++++++++++++++ tests/inet_socket/test | 60 +++++++++++++++++++++++++- 7 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 tests/inet_socket/calipso-fwd-add-load create mode 100644 tests/inet_socket/calipso-fwd-cleanup create mode 100644 tests/inet_socket/calipso-fwd-del-load create mode 100644 tests/inet_socket/calipso-fwd-flush create mode 100644 tests/inet_socket/calipso-fwd-setup
policy/test_inet_socket.te +8 -0
@@ -12,6 +12,14 @@ gen_require(` corenet_inout_generic_if(netlabel_peer_t) corenet_inout_generic_node(netlabel_peer_t) +# Allow unlabeled traffic to be forwarded, as done by the CALIPSO +# forwarding tests. +gen_require(` + type unlabeled_t; +') +corenet_inout_generic_if(unlabeled_t) +corenet_inout_generic_node(unlabeled_t) + # Do not break NFS when we load NetLabel configuration. gen_require(` type kernel_t;
tests/inet_socket/calipso-fwd-add-load new file +10 -0
@@ -0,0 +1,10 @@ +#!/bin/sh +# The client sends unlabeled packets; the router labels unlabeled packets +# forwarded to the server with CALIPSO. +netlabelctl calipso add pass doi:16 +netlabelctl map del default +netlabelctl map add default address:0.0.0.0/0 protocol:unlbl +netlabelctl map add default address:::/0 protocol:unlbl +netlabelctl map add domain:unlabeled_t address:fd00:2::2 protocol:calipso,16 +netlabelctl map add domain:unlabeled_t address:::/0 protocol:unlbl +netlabelctl map add domain:unlabeled_t address:0.0.0.0/0 protocol:unlbl
tests/inet_socket/calipso-fwd-cleanup new file +6 -0
@@ -0,0 +1,6 @@ +#!/bin/sh +# Remove the namespaces created by calipso-fwd-setup (and their veths). +for ns in selinux-ns-c selinux-ns-r selinux-ns-s; do + ip netns del $ns 2>/dev/null +done +true
tests/inet_socket/calipso-fwd-del-load new file +9 -0
@@ -0,0 +1,9 @@ +#!/bin/sh +# Label packets sent by the client domain with CALIPSO; everything else, +# including the router forwarding them, is unlabeled. The router therefore +# removes the CALIPSO option from the forwarded packets. +netlabelctl calipso add pass doi:16 +netlabelctl map del default +netlabelctl map add default address:0.0.0.0/0 protocol:unlbl +netlabelctl map add default address:::/0 protocol:unlbl +netlabelctl map add domain:test_inet_client_t address:fd00:2::2 protocol:calipso,16
tests/inet_socket/calipso-fwd-flush new file +7 -0
@@ -0,0 +1,7 @@ +#!/bin/sh +# Reset NetLabel configuration to unlabeled after the CALIPSO forwarding tests. +netlabelctl map del domain:test_inet_client_t 2>/dev/null +netlabelctl map del domain:unlabeled_t 2>/dev/null +netlabelctl map del default +netlabelctl calipso del doi:16 +netlabelctl map add default protocol:unlbl
tests/inet_socket/calipso-fwd-setup new file +50 -0
50 lines not on this page · raw message
tests/inet_socket/test +58 -2
91 lines not on this page · raw message
Quoted 23 lines · Joas Antonio dos Santos
The existing CALIPSO tests only run over loopback, so the code that rewrites the IPv6 header of forwarded packets (
calipso_skbuff_delattr()andcalipso_skbuff_setattr(), called fromselinux_ip_forward()) is not covered.Add two subtests that build a client -- router -- server topology out of network namespaces and send traffic through the router:
- the client labels its packets with CALIPSO and the router, mapped to unlabeled, removes the option;
- the client sends unlabeled packets and the router adds a CALIPSO option.The first one catches the
payload_lenbug fixed by "calipso: updatepayload_lenwhen removing the CALIPSO option": without the fix the server drops the forwarded packet as truncated (Ip6InTruncatedPkts).Commands inside the namespaces use nsenter(1) as "ip netns exec" and "ip -n" remount /sys, which is denied when running as
sysadm_t. The policy now allowsunlabeled_ttraffic on the generic interface and node, needed for the unlabeled packets the router forwards.
Quoted 6 lines
Tested on Fedora 44 (aarch64), as
unconfined_tandsysadm_t:
- 6.19.10-300.fc44: the new removal subtest fails (udp, tcp, mptcp), the new addition subtest passes;
- 7.3-rc6 with the fix: allinet_socketand sctp tests pass.Signed-off-by Joas Antonio dos Santos <[email protected]>
Agree that we may want this to be bracketed with a kvercmp guard to avoid breaking testing older kernels but otherwise:
Ondrej Mosnáček
reviewerQuoted 31 lines · Stephen Smalley
Quoted 28 lines · Joas Antonio dos Santos
The existing CALIPSO tests only run over loopback, so the code that rewrites the IPv6 header of forwarded packets (
calipso_skbuff_delattr()andcalipso_skbuff_setattr(), called fromselinux_ip_forward()) is not covered.Add two subtests that build a client -- router -- server topology out of network namespaces and send traffic through the router:
- the client labels its packets with CALIPSO and the router, mapped to unlabeled, removes the option;
- the client sends unlabeled packets and the router adds a CALIPSO option.The first one catches the
payload_lenbug fixed by "calipso: updatepayload_lenwhen removing the CALIPSO option": without the fix the server drops the forwarded packet as truncated (Ip6InTruncatedPkts).Commands inside the namespaces use nsenter(1) as "ip netns exec" and "ip -n" remount /sys, which is denied when running as
sysadm_t. The policy now allowsunlabeled_ttraffic on the generic interface and node, needed for the unlabeled packets the router forwards.Tested on Fedora 44 (aarch64), as
unconfined_tandsysadm_t:
- 6.19.10-300.fc44: the new removal subtest fails (udp, tcp, mptcp), the new addition subtest passes;
- 7.3-rc6 with the fix: allinet_socketand sctp tests pass.
Quoted 5 lines
Quoted 1 line
Signed-off-by Joas Antonio dos Santos <[email protected]>Agree that we may want this to be bracketed with a kvercmp guard to avoid breaking testing older kernels but otherwise:
Acked-by Stephen Smalley <[email protected]>
If we assume that the kernel fix eventually goes to stable kernels, I don't think a version check is necessary. Tracking exactly which kernels have the fix would be tedious and hard to keep in sync with reality (esp. if we wanted to take various cherry-picked distro kernels into account...), so I think it's better to leave that logic out of selinux-testsuite (for backportable fixes, that is) and leave it up to the users to work around if the fix is missing in the kernels they are testing.
I would normally just wait with merging the testsuite patch until the corresponding fix is merged and shipped at least in the Fedora kernels we test in the CI, but otherwise I think a kvercmp guard is not necessary here.
Stephen Smalley
maintainerQuoted 49 lines · Ondrej Mosnáček
Quoted 31 lines · Stephen Smalley
Quoted 28 lines · Joas Antonio dos Santos
The existing CALIPSO tests only run over loopback, so the code that rewrites the IPv6 header of forwarded packets (
calipso_skbuff_delattr()andcalipso_skbuff_setattr(), called fromselinux_ip_forward()) is not covered.Add two subtests that build a client -- router -- server topology out of network namespaces and send traffic through the router:
- the client labels its packets with CALIPSO and the router, mapped to unlabeled, removes the option;
- the client sends unlabeled packets and the router adds a CALIPSO option.The first one catches the
payload_lenbug fixed by "calipso: updatepayload_lenwhen removing the CALIPSO option": without the fix the server drops the forwarded packet as truncated (Ip6InTruncatedPkts).Commands inside the namespaces use nsenter(1) as "ip netns exec" and "ip -n" remount /sys, which is denied when running as
sysadm_t. The policy now allowsunlabeled_ttraffic on the generic interface and node, needed for the unlabeled packets the router forwards.Tested on Fedora 44 (aarch64), as
unconfined_tandsysadm_t:
- 6.19.10-300.fc44: the new removal subtest fails (udp, tcp, mptcp), the new addition subtest passes;
- 7.3-rc6 with the fix: allinet_socketand sctp tests pass.Quoted 5 lines
Quoted 1 line
Signed-off-by Joas Antonio dos Santos <[email protected]>Agree that we may want this to be bracketed with a kvercmp guard to avoid breaking testing older kernels but otherwise:
Acked-by Stephen Smalley <[email protected]>If we assume that the kernel fix eventually goes to stable kernels, I don't think a version check is necessary. Tracking exactly which kernels have the fix would be tedious and hard to keep in sync with reality (esp. if we wanted to take various cherry-picked distro kernels into account...), so I think it's better to leave that logic out of selinux-testsuite (for backportable fixes, that is) and leave it up to the users to work around if the fix is missing in the kernels they are testing.
Quoted 4 lines
I would normally just wait with merging the testsuite patch until the corresponding fix is merged and shipped at least in the Fedora kernels we test in the CI, but otherwise I think a kvercmp guard is not necessary here.
That makes sense to me - feel free to merge it then once the fix has gone upstream.