tests/netlink_socket: skip iscsi subtest when NETLINK_ISCSI is unsupported
PATCH 1/3 tests/netlink_socket: skip iscsi subtest when NETLINK_ISCSI is unsupported
test_netlink_iscsi_socket_t's ability to create a NETLINK_ISCSI socket depends on kernel support for the iSCSI netlink transport. On systems built without it, socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ISCSI) fails regardless of SELinux confinement, so the create/deny pair of subtests fail without exercising any access control.
Probe support unconfined before running the confined cases, and skip just those two subtests when unavailable, leaving the rest of the netlink_socket tests (netfilter, generic, crypto) unaffected.
--- tests/netlink_socket/test | 42 +++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-)
tests/netlink_socket/test +27 -15
@@ -1,28 +1,40 @@ #!/usr/bin/perl -use Test; -BEGIN { plan tests => 8 } +use Test::More; -$basedir = $0; -$basedir =~ s|(.*)/[^/]*|$1|; +BEGIN { + $basedir = $0; + $basedir =~ s|(.*)/[^/]*|$1|; -# Verify that test_netlink_iscsi_socket_t can create a NETLINK_ISCSI socket. -$result = system( - "runcon -t test_netlink_iscsi_socket_t -- $basedir/netlinkcreate iscsi 2>&1" -); -ok( $result, 0 ); + # Determine if the kernel supports NETLINK_ISCSI. Probe unconfined so a + # failure here means the protocol isn't available, not an SELinux denial. + $test_iscsi = + system("$basedir/netlinkcreate iscsi 2>/dev/null") == 0 ? 1 : 0; + + plan tests => 8; +} + +SKIP: { + skip( "NETLINK_ISCSI not supported by this kernel", 2 ) unless $test_iscsi; + + # Verify that test_netlink_iscsi_socket_t can create a NETLINK_ISCSI socket. + $result = system( +"runcon -t test_netlink_iscsi_socket_t -- $basedir/netlinkcreate iscsi 2>&1" + ); + ok( $result == 0 ); # Verify that test_no_netlink_iscsi_socket_t cannot create a NETLINK_ISCSI socket. -$result = system( + $result = system( "runcon -t test_no_netlink_iscsi_socket_t -- $basedir/netlinkcreate iscsi 2>&1" -); -ok($result); + ); + ok($result); +} # Verify that test_netlink_netfilter_socket_t can create a NETLINK_NETFILTER socket. $result = system( "runcon -t test_netlink_netfilter_socket_t -- $basedir/netlinkcreate netfilter 2>&1" ); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_no_netlink_netfilter_socket_t cannot create a NETLINK_NETFILTER socket. $result = system(
@@ -34,7 +46,7 @@ ok($result); $result = system( "runcon -t test_netlink_generic_socket_t -- $basedir/netlinkcreate generic 2>&1" ); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_no_netlink_generic_socket_t cannot create a NETLINK_GENERIC socket. $result = system(
@@ -46,7 +58,7 @@ ok($result); $result = system( "runcon -t test_netlink_crypto_socket_t -- $basedir/netlinkcreate crypto 2>&1" ); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_no_netlink_crypto_socket_t cannot create a NETLINK_CRYPTO socket. $result = system(
Signature · 1 line
2.55.0
PATCH 2/3 tests: skip io_uring when unsupported or disabled
Gate the io_uring SUBDIRS entry on liburing.h being available at build time. Runtime kernel support is checked in the test itself instead of via /lib/modules/$(uname -r)/config: that file isn't reliable for hand-built/booted kernels. Since the kernel.io_uring_disabled sysctl only exists when CONFIG_IO_URING is set, checking it at runtime covers both the "not built in" and the "administratively disabled" cases without relying on the config file.
Also fix a latent bug from converting to Test::More: ok($result, 0) treats "0" as a test label, not an expected value, so it silently inverted the pass/fail logic for the "should succeed" cases. Use ok($result == 0) instead.
--- tests/Makefile | 6 ++++++ tests/io_uring/test | 35 ++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-)
tests/Makefile +6 -0
@@ -172,9 +172,15 @@ ifeq ($(shell [ -d /sys/fs/selinux/class/memfd_file ] && grep -q 1 $(SELINUXFS)/ SUBDIRS += memfd endif +# Skip when liburing-devel (providing liburing.h) isn't installed to build +# against. Runtime kernel support (CONFIG_IO_URING, io_uring_disabled) is +# probed by the test itself rather than here, since kernel config files +# aren't reliable for hand-built/booted kernels. ifeq ($(shell grep -q io_uring $(POLDEV)/include/support/all_perms.spt && echo true),true) +ifeq ($(shell test -e $(INCLUDEDIR)/liburing.h && echo true),true) SUBDIRS += io_uring endif +endif ifeq ($(DISTRO),RHEL4) SUBDIRS:=$(filter-out bounds dyntrace dyntrans inet_socket mmap nnp_nosuid overlay unix_socket, $(SUBDIRS))
tests/io_uring/test +28 -7
@@ -1,17 +1,38 @@ #!/usr/bin/perl -use Test; -BEGIN { plan tests => 11 } +use Test::More; -$basedir = $0; -$basedir =~ s|(.*)/[^/]*|$1|; +BEGIN { + $basedir = $0; + $basedir =~ s|(.*)/[^/]*|$1|; + + # kernel.io_uring_disabled only exists when the kernel has io_uring + # support built in, so a missing sysctl means CONFIG_IO_URING isn't + # set. A value of 2 means io_uring is administratively disabled even + # for privileged processes. Check this at runtime rather than kernel + # config files, which aren't reliable for hand-built/booted kernels. + my $io_uring_disabled = `sysctl -n kernel.io_uring_disabled 2>/dev/null`; + my $sysctl_rc = $?; + chomp($io_uring_disabled); + + if ( $sysctl_rc != 0 ) { + plan skip_all => "io_uring not supported by this kernel"; + } + elsif ( $io_uring_disabled eq "2" ) { + plan skip_all => + "io_uring is disabled via the kernel.io_uring_disabled sysctl"; + } + else { + plan tests => 11; + } +} # Remove any leftover test files from prior runs. system("rm -f $basedir/iouring.out"); # Verify that test_io_uring_t passes the t1 test $result = system("runcon -t test_io_uring_t $basedir/iouring t1"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_no_override_t fails the t1 test on io_uring override_creds $result = system(
@@ -44,7 +65,7 @@ chomp($serange); $childctx = "$seuser:$serole:test_io_uring_child_t:$serange"; $result = system("runcon -t test_io_uring_parent_t $basedir/iouring t1 $childctx"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_child_no_override_t fails the t1 test on io_uring override_creds $childctx = "$seuser:$serole:test_io_uring_child_no_override_t:$serange";
@@ -72,7 +93,7 @@ ok($result); # Verify that test_io_uring_sqpoll_t passes the sqpoll test $result = system("runcon -t test_io_uring_sqpoll_t $basedir/iouring sqpoll"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_no_sqpoll_t fails the sqpoll test $result = system(
Signature · 1 line
2.55.0
Stephen Smalley
maintainerRe: [PATCH 2/3] tests: skip io_uring when unsupported or disabled
Quoted 9 lines · Brian Grech
Gate the
io_uringSUBDIRS entry onliburing.hbeing available at build time. Runtime kernel support is checked in the test itself instead of via /lib/modules/$(uname -r)/config: that file isn't reliable for hand-built/booted kernels. Since the kernel.io_uring_disabled sysctl only exists whenCONFIG_IO_URINGis set, checking it at runtime covers both the "not built in" and the "administratively disabled" cases without relying on the config file.
Quoted 4 lines
Also fix a latent bug from converting to
Test::More:ok($result, 0)treats "0" as a test label, not an expected value, so it silently inverted the pass/fail logic for the "should succeed" cases. Use ok($result == 0) instead.
Nit: this file was still on "use Test;" before this patch, so the ok($r, 0) -> ok($r==0) rewrite is a consequence of this patch's own Test -> Test:More conversion, not a pre-existing bug. Also see comments below.
Quoted 15 lines
Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>--- tests/Makefile | 6 ++++++ tests/io_uring/test | 35 ++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-)tests/Makefile +0
-0@@ -172,9 +172,15 @@ ifeq ($(shell [ -d /sys/fs/selinux/class/memfd_file ] && grep -q 1 $(SELINUXFS)/ SUBDIRS += memfd endif
tests/Makefile ifeq ($(shell [ -d /sys/fs/selinux/class/memfd_file ] && grep -q 1 $(SELINUXFS)/ · line 183
Quoted 10 lines
tests/Makefile +6
-0+# Skip when liburing-devel (providing liburing.h) isn't installed to build +# against. Runtime kernel support (CONFIG_IO_URING, io_uring_disabled) is +# probed by the test itself rather than here, since kernel config files +# aren't reliable for hand-built/booted kernels. ifeq ($(shell grep -q io_uring $(POLDEV)/include/support/all_perms.spt && echo true),true) +ifeq ($(shell test -e $(INCLUDEDIR)/liburing.h && echo true),true) SUBDIRS += io_uring endif +endif
I'm not clear why we need/want this - liburing-devel is stated as a build dependency in the README.md. Not strongly opposed but not sure we do this for other stated build dependencies?
Not sure we want to silently skip tests because we forgot to install something required by the README.md file. Open to other maintainer feedback here.
Quoted 19 lines
tests/io_uring/test +7
-4@@ -1,17 +1,38 @@ #!/usr/bin/perl -use Test; -BEGIN { plan tests => 11 } +use Test::More; -$basedir = $0; -$basedir =~ s|(.*)/[^/]*|$1|; +BEGIN { + $basedir = $0; + $basedir =~ s|(.*)/[^/]*|$1|; + + # kernel.io_uring_disabled only exists when the kernel has io_uring + # support built in, so a missing sysctl means CONFIG_IO_URING isn't
tests/io_uring/test line 20
Quoted 10 lines
tests/io_uring/test +10
-0+ # set. A value of 2 means io_uring is administratively disabled even + # for privileged processes. Check this at runtime rather than kernel + # config files, which aren't reliable for hand-built/booted kernels. + my $io_uring_disabled = `sysctl -n kernel.io_uring_disabled 2>/dev/null`; + my $sysctl_rc = $?; + chomp($io_uring_disabled); + + if ( $sysctl_rc != 0 ) { + plan skip_all => "io_uring not supported by this kernel"; + }
The kernel.io_uring_disabled sysctl was only added in v6.6 while the SELinux io_uring class/permissions this test exercises have existed since v5.16. On a 5.16-6.5 kernel built with CONFIG_IO_URING=y the sysctl doesn't exist, so this will skip_all a test that currently runs and passes.
I'd suggest treating a missing sysctl the same as 0 (run), and probing the "io_uring not built in at all" case directly - e.g. a tiny probe mode on the iouring helper that just does io_uring_queue_init() and exits 0/1, run unconfined like 1/3 does for netlinkcreate. Then the sysctl check only needs to handle the "== 2" admin-disabled case.
Stephen Smalley
maintainerRe: [PATCH 2/3] tests: skip io_uring when unsupported or disabled
Quoted 37 lines · Stephen Smalley
Quoted 9 lines · Brian Grech
Gate the
io_uringSUBDIRS entry onliburing.hbeing available at build time. Runtime kernel support is checked in the test itself instead of via /lib/modules/$(uname -r)/config: that file isn't reliable for hand-built/booted kernels. Since the kernel.io_uring_disabled sysctl only exists whenCONFIG_IO_URINGis set, checking it at runtime covers both the "not built in" and the "administratively disabled" cases without relying on the config file.Quoted 4 lines
Also fix a latent bug from converting to
Test::More:ok($result, 0)treats "0" as a test label, not an expected value, so it silently inverted the pass/fail logic for the "should succeed" cases. Use ok($result == 0) instead.Nit: this file was still on "use Test;" before this patch, so the
ok($r, 0)-> ok($r==0) rewrite is a consequence of this patch's own Test -> Test:More conversion, not a pre-existing bug. Also see comments below.Quoted 16 lines
Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>--- tests/Makefile | 6 ++++++ tests/io_uring/test | 35 ++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-)tests/Makefile +0
-0@@ -172,9 +172,15 @@ ifeq ($(shell [ -d /sys/fs/selinux/class/memfd_file ] && grep -q 1 $(SELINUXFS)/ SUBDIRS += memfd endif
Quoted 16 lines
tests/Makefile ifeq ($(shell [ -d /sys/fs/selinux/class/memfd_file ] && grep -q 1 $(SELINUXFS)/ · line 183
Quoted 9 lines
tests/Makefile +6
-0+# Skip when liburing-devel (providing liburing.h) isn't installed to build +# against. Runtime kernel support (CONFIG_IO_URING, io_uring_disabled) is +# probed by the test itself rather than here, since kernel config files +# aren't reliable for hand-built/booted kernels. ifeq ($(shell grep -q io_uring $(POLDEV)/include/support/all_perms.spt && echo true),true) +ifeq ($(shell test -e $(INCLUDEDIR)/liburing.h && echo true),true) SUBDIRS += io_uring endif +endifI'm not clear why we need/want this - liburing-devel is stated as a build dependency in the README.md. Not strongly opposed but not sure we do this for other stated build dependencies?
Not sure we want to silently skip tests because we forgot to install something required by the README.md file. Open to other maintainer feedback here.
Actually I see that we already do this for keyutils so I guess there is precedent and this part can stay unchanged. The other comments still apply.
Quoted 42 lines
Quoted 20 lines
tests/io_uring/test +7
-4@@ -1,17 +1,38 @@ #!/usr/bin/perl -use Test; -BEGIN { plan tests => 11 } +use Test::More; -$basedir = $0; -$basedir =~ s|(.*)/[^/]*|$1|; +BEGIN { + $basedir = $0; + $basedir =~ s|(.*)/[^/]*|$1|; + + # kernel.io_uring_disabled only exists when the kernel has io_uring + # support built in, so a missing sysctl means CONFIG_IO_URING isn'ttests/io_uring/test line 20
Quoted 10 lines
tests/io_uring/test +10
-0+ # set. A value of 2 means io_uring is administratively disabled even + # for privileged processes. Check this at runtime rather than kernel + # config files, which aren't reliable for hand-built/booted kernels. + my $io_uring_disabled = `sysctl -n kernel.io_uring_disabled 2>/dev/null`; + my $sysctl_rc = $?; + chomp($io_uring_disabled); + + if ( $sysctl_rc != 0 ) { + plan skip_all => "io_uring not supported by this kernel"; + }The kernel.io_uring_disabled sysctl was only added in v6.6 while the SELinux
io_uringclass/permissions this test exercises have existed since v5.16. On a 5.16-6.5 kernel built withCONFIG_IO_URING=ythe sysctl doesn't exist, so this willskip_alla test that currently runs and passes.I'd suggest treating a missing sysctl the same as 0 (run), and probing the "
io_uringnot built in at all" case directly - e.g. a tiny probe mode on the iouring helper that just doesio_uring_queue_init()and exits 0/1, run unconfined like 1/3 does for netlinkcreate. Then the sysctl check only needs to handle the "== 2" admin-disabled case.
PATCH v2 1/1 tests: skip io_uring when unsupported or disabled
In reply to Brian GrechGate io_uring on liburing.h at build time (documented dependency, same pattern as key_socket/keyutils.h).
At runtime, probe unconfined via a new iouring "probe" mode (io_uring_queue_init()/exit()) rather than kernel config files or the io_uring_disabled sysctl alone: that sysctl (v6.6+) postdates the io_uring permission being tested (v5.16), so its absence does not mean unsupported. Use it only for the "== 2" admin-disabled case.
Converting to Test::More also requires ok($result, 0) -> ok($result == 0): the two-arg form silently inverts the "should succeed" checks under Test::More.
--- tests/Makefile | 6 ++++++ tests/io_uring/iouring.c | 20 +++++++++++++++++++- tests/io_uring/test | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 8 deletions(-)
tests/Makefile +6 -0
@@ -176,9 +176,15 @@ ifeq ($(shell [ -d /sys/fs/selinux/class/memfd_file ] && grep -q 1 $(SELINUXFS)/ SUBDIRS += memfd endif +# Skip when liburing-devel (providing liburing.h) isn't installed to build +# against. Runtime kernel support (CONFIG_IO_URING, io_uring_disabled) is +# probed by the test itself rather than here, since kernel config files +# aren't reliable for hand-built/booted kernels. ifeq ($(shell grep -q io_uring $(POLDEV)/include/support/all_perms.spt && echo true),true) +ifeq ($(shell test -e $(INCLUDEDIR)/liburing.h && echo true),true) SUBDIRS += io_uring endif +endif ifeq ($(DISTRO),RHEL4) SUBDIRS:=$(filter-out bounds dyntrace dyntrans inet_socket mmap nnp_nosuid overlay unix_socket, $(SUBDIRS))
tests/io_uring/iouring.c +19 -1
@@ -479,6 +479,7 @@ int main(int argc, char *argv[])struct rlimit rlim;enum {TST_UNKNOWN , +TST_PROBE ,TST_SQPOLL ,TST_T1_PARENT ,TST_T1_CHILD } tst_method;
@@ -486,7 +487,9 @@ int main(int argc, char *argv[])/* parse the command line and do some sanity checks */ tst_method =TST_UNKNOWN ;if (argc >=2 ) { -if (!strcmp (argv[1 ],"sqpoll" )) +if (!strcmp (argv[1 ],"probe" )) + tst_method =TST_PROBE ; +else if (!strcmp (argv[1 ],"sqpoll" )) tst_method =TST_SQPOLL ;else if (!strcmp (argv[1 ],"t1" ) || !strcmp (argv[1 ],"t1_parent" ))
@@ -499,6 +502,21 @@ int main(int argc, char *argv[])exit (EINVAL ); } +/* +* Minimal probe: just check whether the kernel supports io_uring at +* all, without any of the SELinux-specific setup below. Meant to be +* run unconfined so a failure here means io_uring isn't available, +* not that it was denied by policy. Exits 0 if supported, 1 if not. +*/ +if (tst_method ==TST_PROBE ) { +struct io_uring probe_ring; + +if (io_uring_queue_init (URING_ENTRIES , &probe_ring,0 ) <0 ) +exit (1 ); +io_uring_queue_exit (&probe_ring); +exit (0 ); + } + progname =strdup (argv[0 ]); progdir =dirname (progname);
tests/io_uring/test +31 -7
@@ -1,17 +1,41 @@ #!/usr/bin/perl -use Test; -BEGIN { plan tests => 11 } +use Test::More; -$basedir = $0; -$basedir =~ s|(.*)/[^/]*|$1|; +BEGIN { + $basedir = $0; + $basedir =~ s|(.*)/[^/]*|$1|; + + # Probe unconfined so a failure here means io_uring isn't built into + # the kernel at all, not that it was denied by policy. + my $io_uring_supported = + system("$basedir/iouring probe >/dev/null 2>&1") == 0 ? 1 : 0; + + # kernel.io_uring_disabled was only added in v6.6, well after the + # io_uring support being tested here (v5.16), so its absence does not + # mean io_uring is unsupported - only a value of 2 means io_uring is + # administratively disabled, even for privileged processes. + chomp( my $io_uring_disabled = + `sysctl -n kernel.io_uring_disabled 2>/dev/null` ); + + if ( !$io_uring_supported ) { + plan skip_all => "io_uring not supported by this kernel"; + } + elsif ( $io_uring_disabled eq "2" ) { + plan skip_all => + "io_uring is disabled via the kernel.io_uring_disabled sysctl"; + } + else { + plan tests => 11; + } +} # Remove any leftover test files from prior runs. system("rm -f $basedir/iouring.out"); # Verify that test_io_uring_t passes the t1 test $result = system("runcon -t test_io_uring_t $basedir/iouring t1"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_no_override_t fails the t1 test on io_uring override_creds $result = system(
@@ -44,7 +68,7 @@ chomp($serange); $childctx = "$seuser:$serole:test_io_uring_child_t:$serange"; $result = system("runcon -t test_io_uring_parent_t $basedir/iouring t1 $childctx"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_child_no_override_t fails the t1 test on io_uring override_creds $childctx = "$seuser:$serole:test_io_uring_child_no_override_t:$serange";
@@ -72,7 +96,7 @@ ok($result); # Verify that test_io_uring_sqpoll_t passes the sqpoll test $result = system("runcon -t test_io_uring_sqpoll_t $basedir/iouring sqpoll"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_no_sqpoll_t fails the sqpoll test $result = system(
Signature · 1 line
2.55.0
Re: [PATCH v2] tests: skip io_uring when unsupported or disabled
Quoted 49 lines · Brian Grech
Gate
io_uringonliburing.hat build time (documented dependency, same pattern askey_socket/keyutils.h).At runtime, probe unconfined via a new iouring "probe" mode (io_uring_queue_init()/exit()) rather than kernel config files or the
io_uring_disabledsysctl alone: that sysctl (v6.6+) postdates theio_uringpermission being tested (v5.16), so its absence does not mean unsupported. Use it only for the "== 2" admin-disabled case.Converting to
Test::Morealso requiresok($result, 0)-> ok($result == 0): the two-arg form silently inverts the "should succeed" checks underTest::More.Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>--- tests/Makefile | 6 ++++++ tests/io_uring/iouring.c | 20 +++++++++++++++++++- tests/io_uring/test | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 8 deletions(-)tests/io_uring/test +14
-4@@ -1,17 +1,41 @@ #!/usr/bin/perl -use Test; -BEGIN { plan tests => 11 } +use Test::More; -$basedir = $0; -$basedir =~ s|(.*)/[^/]*|$1|; +BEGIN { + $basedir = $0; + $basedir =~ s|(.*)/[^/]*|$1|; + + # Probe unconfined so a failure here means io_uring isn't built into + # the kernel at all, not that it was denied by policy. + my $io_uring_supported = + system("$basedir/iouring probe >/dev/null 2>&1") == 0 ? 1 : 0; + + # kernel.io_uring_disabled was only added in v6.6, well after the + # io_uring support being tested here (v5.16), so its absence does not + # mean io_uring is unsupported - only a value of 2 means io_uring is + # administratively disabled, even for privileged processes.
tests/io_uring/test line 27
Quoted 10 lines
tests/io_uring/test +10
-0+ chomp( my $io_uring_disabled = + `sysctl -n kernel.io_uring_disabled 2>/dev/null` ); + + if ( !$io_uring_supported ) { + plan skip_all => "io_uring not supported by this kernel"; + } + elsif ( $io_uring_disabled eq "2" ) { + plan skip_all => + "io_uring is disabled via the kernel.io_uring_disabled sysctl"; + }
One non-blocking observation: with io_uring_disabled=2 the unconfined probe itself fails (io_uring_setup() -> -EPERM) so the first skip_all fires with "not supported by this kernel" and the sysctl elsif is never reached. Harmless - the test skips either way - just the message is less specific than it could be if the sysctl check came first.
Otherwise,
Quoted 36 lines
tests/io_uring/test +7
-4+ else { + plan tests => 11; + } +} # Remove any leftover test files from prior runs. system("rm -f $basedir/iouring.out"); # Verify that test_io_uring_t passes the t1 test $result = system("runcon -t test_io_uring_t $basedir/iouring t1"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_no_override_t fails the t1 test on io_uring override_creds $result = system(@@ -44,7 +68,7 @@ chomp($serange); $childctx = "$seuser:$serole:test_io_uring_child_t:$serange"; $result = system("runcon -t test_io_uring_parent_t $basedir/iouring t1 $childctx"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_child_no_override_t fails the t1 test on io_uring override_creds $childctx = "$seuser:$serole:test_io_uring_child_no_override_t:$serange";@@ -72,7 +96,7 @@ ok($result); # Verify that test_io_uring_sqpoll_t passes the sqpoll test $result = system("runcon -t test_io_uring_sqpoll_t $basedir/iouring sqpoll"); -ok( $result, 0 ); +ok( $result == 0 ); # Verify that test_io_uring_no_sqpoll_t fails the sqpoll test $result = system( --2.55.0
Stephen Smalley
maintainerRe: [PATCH v2] tests: skip io_uring when unsupported or disabled
Quoted 68 lines · Stephen Smalley
Quoted 49 lines · Brian Grech
Gate
io_uringonliburing.hat build time (documented dependency, same pattern askey_socket/keyutils.h).At runtime, probe unconfined via a new iouring "probe" mode (io_uring_queue_init()/exit()) rather than kernel config files or the
io_uring_disabledsysctl alone: that sysctl (v6.6+) postdates theio_uringpermission being tested (v5.16), so its absence does not mean unsupported. Use it only for the "== 2" admin-disabled case.Converting to
Test::Morealso requiresok($result, 0)-> ok($result == 0): the two-arg form silently inverts the "should succeed" checks underTest::More.Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>--- tests/Makefile | 6 ++++++ tests/io_uring/iouring.c | 20 +++++++++++++++++++- tests/io_uring/test | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 8 deletions(-)tests/io_uring/test +14
-4@@ -1,17 +1,41 @@ #!/usr/bin/perl -use Test; -BEGIN { plan tests => 11 } +use Test::More; -$basedir = $0; -$basedir =~ s|(.*)/[^/]*|$1|; +BEGIN { + $basedir = $0; + $basedir =~ s|(.*)/[^/]*|$1|; + + # Probe unconfined so a failure here means io_uring isn't built into + # the kernel at all, not that it was denied by policy. + my $io_uring_supported = + system("$basedir/iouring probe >/dev/null 2>&1") == 0 ? 1 : 0; + + # kernel.io_uring_disabled was only added in v6.6, well after the + # io_uring support being tested here (v5.16), so its absence does not + # mean io_uring is unsupported - only a value of 2 means io_uring is + # administratively disabled, even for privileged processes.tests/io_uring/test line 27
Quoted 10 lines
tests/io_uring/test +10
-0+ chomp( my $io_uring_disabled = + `sysctl -n kernel.io_uring_disabled 2>/dev/null` ); + + if ( !$io_uring_supported ) { + plan skip_all => "io_uring not supported by this kernel"; + } + elsif ( $io_uring_disabled eq "2" ) { + plan skip_all => + "io_uring is disabled via the kernel.io_uring_disabled sysctl"; + }One non-blocking observation: with io_uring_disabled=2 the unconfined probe itself fails (
io_uring_setup()->-EPERM) so the firstskip_allfires with "not supported by this kernel" and the sysctl elsif is never reached. Harmless - the test skips either way - just the message is less specific than it could be if the sysctl check came first.
Quoted 2 lines
Otherwise,
Reviewed-by Stephen Smalley <[email protected]>
This patch has been merged but if you want to post a follow-up to improve the issue noted above, feel free.
PATCH 3/3 tests/filesystem: probe ext4 quota support before enabling it
In reply to Brian GrechAdd ext4_native_quota_supported() and legacy_quota_supported() to Filesystem.pm: instead of inferring quota support from kernel version, actually create a small loopback ext4 filesystem and try to mount it (with the native quota feature, and separately via the legacy quotacheck(8)/quotaon(8) mechanism) to see if the kernel can really handle it. Use native quota only when supported; fall back to the legacy path only when that works either; and skip quota testing entirely (without breaking basic ext4 mount/unmount tests) when neither mechanism is usable.
The probe uses an isolated tempdir under /tmp rather than the ext4 test's own $basedir: per-filesystem test directories (tests/filesystem/ ext4, .../jfs, etc.) are symlinks back to tests/filesystem itself, so writing probe files into $basedir would share state with every other filesystem test, and incomplete cleanup (a stuck loop device or mount) could corrupt whichever filesystem test runs next in SUBDIRS order.
--- tests/filesystem/Filesystem.pm | 58 ++++++++++++++++++++++++++++++++-- tests/filesystem/test | 42 +++++++++++++++++------- tests/fs_filesystem/test | 42 +++++++++++++++++------- 3 files changed, 118 insertions(+), 24 deletions(-)
tests/filesystem/Filesystem.pm +56 -2
@@ -1,7 +1,61 @@ package Filesystem; -use Exporter qw(import); +use Exporter qw(import); +use File::Temp qw(tempdir); our @EXPORT_OK = - qw(check_config udisks2_stop udisks2_restart get_loop_dev attach_dev make_fs mk_mntpoint_1 mk_mntpoint_2 cleanup cleanup1 reaper nfs_gen_opts); + qw(check_config udisks2_stop udisks2_restart get_loop_dev attach_dev make_fs mk_mntpoint_1 mk_mntpoint_2 cleanup cleanup1 reaper nfs_gen_opts ext4_native_quota_supported legacy_quota_supported); + +# EXT4 native quota (-O quota) is a RO_COMPAT feature: any kernel that +# doesn't support it (e.g. built without CONFIG_QUOTA) will refuse to +# mount *any* filesystem carrying that feature bit, not just quota-using +# ones. Probe it directly instead of relying on kernel version alone, so +# a single unmountable feature flag can't take down the whole test. +# +# Use an isolated tempdir under /tmp rather than the caller's $basedir: +# per-filesystem test directories (tests/filesystem/ext4, .../jfs, etc.) +# are symlinks back to tests/filesystem itself, so writing probe files +# into $basedir would pollute the directory every other filesystem test +# shares, and any incomplete cleanup here (a stuck loop device or mount) +# could corrupt whichever filesystem test runs next. +sub ext4_native_quota_supported { + my $dir = tempdir( "ext4_quota_probe.XXXXXX", TMPDIR => 1, CLEANUP => 1 ); + my $img = "$dir/probe.img"; + my $mnt = "$dir/probe.mnt"; + + system("dd if=/dev/zero of=$img bs=1M count=8 status=none 2>/dev/null"); + system("mkfs.ext4 -q -F -O quota $img >/dev/null 2>&1"); + mkdir($mnt); + my $rc = system("mount -o loop $img $mnt >/dev/null 2>&1"); + system("umount $mnt >/dev/null 2>&1") if $rc == 0; + + return $rc == 0 ? 1 : 0; +} + +# The legacy quota mechanism (external vfsv0 quota files, activated via +# quotacheck(8) + quotaon(8)) needs a registered kernel quota format +# (CONFIG_QFMT_V1/V2) just as much as native quota does - it is not a +# fallback that works whenever native quota doesn't. Probe it the same +# way, so callers can tell "use legacy" apart from "no quota mechanism +# is usable at all on this kernel". Uses an isolated tempdir for the same +# reason as ext4_native_quota_supported(). +sub legacy_quota_supported { + my $dir = tempdir( "ext4_quota_probe.XXXXXX", TMPDIR => 1, CLEANUP => 1 ); + my $img = "$dir/probe.img"; + my $mnt = "$dir/probe.mnt"; + + system("dd if=/dev/zero of=$img bs=1M count=8 status=none 2>/dev/null"); + system("mkfs.ext4 -q -F $img >/dev/null 2>&1"); + mkdir($mnt); + my $rc = + system("mount -o loop,usrquota,grpquota $img $mnt >/dev/null 2>&1"); + if ( $rc == 0 ) { + system("quotacheck -ugF vfsv0 $mnt >/dev/null 2>&1"); + $rc = system("quotaon -ug $mnt >/dev/null 2>&1"); + system("quotaoff -ug $mnt >/dev/null 2>&1") if $rc == 0; + } + system("umount $mnt >/dev/null 2>&1"); + + return $rc == 0 ? 1 : 0; +} sub check_config { my ( $base, $fanotify_fs, $nfs_enabled, $vfat_enabled ) = @_;
tests/filesystem/test +31 -11
71 lines not on this page · raw message
tests/fs_filesystem/test +31 -11
71 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH 3/3] tests/filesystem: probe ext4 quota support before enabling it
Quoted 18 lines · Brian Grech
Add
ext4_native_quota_supported()andlegacy_quota_supported()to Filesystem.pm: instead of inferring quota support from kernel version, actually create a small loopback ext4 filesystem and try to mount it (with the native quota feature, and separately via the legacy quotacheck(8)/quotaon(8) mechanism) to see if the kernel can really handle it. Use native quota only when supported; fall back to the legacy path only when that works either; and skip quota testing entirely (without breaking basic ext4 mount/unmount tests) when neither mechanism is usable.The probe uses an isolated tempdir under /tmp rather than the ext4 test's own $basedir: per-filesystem test directories (tests/filesystem/ ext4, .../jfs, etc.) are symlinks back to tests/filesystem itself, so writing probe files into $basedir would share state with every other filesystem test, and incomplete cleanup (a stuck loop device or mount) could corrupt whichever filesystem test runs next in SUBDIRS order.
Quoted 2 lines
Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>
Stephen Smalley
maintainerRe: [PATCH 3/3] tests/filesystem: probe ext4 quota support before enabling it
Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Brian Grech
Add
ext4_native_quota_supported()andlegacy_quota_supported()to Filesystem.pm: instead of inferring quota support from kernel version, actually create a small loopback ext4 filesystem and try to mount it (with the native quota feature, and separately via the legacy quotacheck(8)/quotaon(8) mechanism) to see if the kernel can really handle it. Use native quota only when supported; fall back to the legacy path only when that works either; and skip quota testing entirely (without breaking basic ext4 mount/unmount tests) when neither mechanism is usable.The probe uses an isolated tempdir under /tmp rather than the ext4 test's own $basedir: per-filesystem test directories (tests/filesystem/ ext4, .../jfs, etc.) are symlinks back to tests/filesystem itself, so writing probe files into $basedir would share state with every other filesystem test, and incomplete cleanup (a stuck loop device or mount) could corrupt whichever filesystem test runs next in SUBDIRS order.
Quoted 4 lines
Quoted 2 lines
Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>Reviewed-by Stephen Smalley <[email protected]>
This patch (not the entire series) has been merged.
Quoted 7 lines · Brian Grech
test_netlink_iscsi_socket_t's ability to create a
NETLINK_ISCSIsocket depends on kernel support for the iSCSI netlink transport. On systems built without it,socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ISCSI)fails regardless of SELinux confinement, so the create/deny pair of subtests fail without exercising any access control.
Quoted 6 lines
Probe support unconfined before running the confined cases, and skip just those two subtests when unavailable, leaving the rest of the
netlink_sockettests (netfilter, generic, crypto) unaffected.Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>
Stephen Smalley
maintainerQuoted 9 lines · Stephen Smalley
Quoted 7 lines · Brian Grech
test_netlink_iscsi_socket_t's ability to create a
NETLINK_ISCSIsocket depends on kernel support for the iSCSI netlink transport. On systems built without it,socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ISCSI)fails regardless of SELinux confinement, so the create/deny pair of subtests fail without exercising any access control.
Quoted 8 lines
Quoted 6 lines
Probe support unconfined before running the confined cases, and skip just those two subtests when unavailable, leaving the rest of the
netlink_sockettests (netfilter, generic, crypto) unaffected.Assisted-by Claude Code:claude-sonnet-5Signed-off-by Brian Grech <[email protected]>Reviewed-by Stephen Smalley <[email protected]>
This patch (not the entire series) has been merged.