Skip to contentSkip to conversation

semodule-utils: add bad-data tests for link/expand neverallow

PATCH In review Akhil Kohli 2 participants 3 messages Jul 30 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 semodule-utils: add bad-data tests for link/expand neverallow

Add link/expand bad-data tests for neverallow and neverallowxperm enforcement at semodule_expand: cross-module base violations, same-module neverallow conflicts, and checkmodule deferral document tests.

Adapt same-module neverallowxperm for libsepol 3.11 (enforced at expand) while still passing on older userspace where enforcement is deferred. Refactor link/expand helpers through run_link_expand().

Add a cross-module require test: link rejects a consumer module when a required type is only declared in a separate provider module.

---
 .../bad-data/fixtures/base/minimal_base.conf  |  15 +
 .../bad-data/fixtures/modules/module_a.te     |   8 +
 .../bad-data/fixtures/modules/module_b.te     |   8 +
 .../fixtures/modules/neverallow_good.te       |   8 +
 .../fixtures/modules/neverallow_self.te       |  10 +
 .../fixtures/modules/neverallow_violator.te   |   8 +
 .../fixtures/modules/neverallow_xperm_self.te |  11 +
 .../modules/neverallow_xperm_violator.te      |   9 +
 semodule-utils/tests/bad-data/run.sh          | 342 +++++++++++++++++-
 9 files changed, 414 insertions(+), 5 deletions(-)
 create mode 100644 semodule-utils/tests/bad-data/fixtures/base/minimal_base.conf
 create mode 100644 semodule-utils/tests/bad-data/fixtures/modules/module_a.te
 create mode 100644 semodule-utils/tests/bad-data/fixtures/modules/module_b.te
 create mode 100644 semodule-utils/tests/bad-data/fixtures/modules/neverallow_good.te
 create mode 100644 semodule-utils/tests/bad-data/fixtures/modules/neverallow_self.te
 create mode 100644 semodule-utils/tests/bad-data/fixtures/modules/neverallow_violator.te
 create mode 100644 semodule-utils/tests/bad-data/fixtures/modules/neverallow_xperm_self.te
 create mode 100644 semodule-utils/tests/bad-data/fixtures/modules/neverallow_xperm_violator.te
semodule-utils/tests/bad-data/fixtures/base/minimal_base.conf new file +15 -0
new file mode 100644
index 00000000..4e058c77
@@ -0,0 +1,15 @@
+# Base .conf: bare class declaration, then permission block (checkmodule requires both).
+class file
+sid kernel
+class file { read write ioctl }
+
+type base_t;
+
+allow base_t base_t : file read;
+neverallow base_t base_t : file write;
+neverallowxperm base_t base_t : file ioctl 0x1000;
+
+role object_r;
+role object_r types { base_t };
+user user_u roles { object_r };
+sid kernel user_u:object_r:base_t
semodule-utils/tests/bad-data/fixtures/modules/module_a.te new file +8 -0
new file mode 100644
index 00000000..04d16238
@@ -0,0 +1,8 @@
+module module_a 1.0;
+
+require {
+	type other_t;
+	class file { read };
+}
+
+allow other_t other_t : file read;
semodule-utils/tests/bad-data/fixtures/modules/module_b.te new file +8 -0
new file mode 100644
index 00000000..2b8caed7
@@ -0,0 +1,8 @@
+module module_b 1.0;
+
+require {
+	class file { read };
+}
+
+type other_t;
+allow other_t other_t : file read;
semodule-utils/tests/bad-data/fixtures/modules/neverallow_good.te new file +8 -0
new file mode 100644
index 00000000..f9850b8b
@@ -0,0 +1,8 @@
+module neverallow_good 1.0;
+
+require {
+	type base_t;
+	class file { read };
+}
+
+allow base_t base_t : file read;
semodule-utils/tests/bad-data/fixtures/modules/neverallow_self.te new file +10 -0
new file mode 100644
index 00000000..255fb391
@@ -0,0 +1,10 @@
+module neverallow_self 1.0;
+
+require {
+	class file { read write };
+}
+
+type foo_t;
+
+allow foo_t foo_t : file { read write };
+neverallow foo_t foo_t : file write;
semodule-utils/tests/bad-data/fixtures/modules/neverallow_violator.te new file +8 -0
new file mode 100644
index 00000000..fb8aade4
@@ -0,0 +1,8 @@
+module neverallow_violator 1.0;
+
+require {
+	type base_t;
+	class file { read write };
+}
+
+allow base_t base_t : file write;
semodule-utils/tests/bad-data/fixtures/modules/neverallow_xperm_self.te new file +11 -0
new file mode 100644
index 00000000..965f86af
@@ -0,0 +1,11 @@
+module neverallow_xperm_self 1.0;
+
+require {
+	class file { read write ioctl };
+}
+
+type foo_t;
+
+allow foo_t foo_t : file ioctl;
+allowxperm foo_t foo_t : file ioctl 0x2000;
+neverallowxperm foo_t foo_t : file ioctl 0x2000;
semodule-utils/tests/bad-data/fixtures/modules/neverallow_xperm_violator.te new file +9 -0
new file mode 100644
index 00000000..7dbf889f
@@ -0,0 +1,9 @@
+module neverallow_xperm_violator 1.0;
+
+require {
+	type base_t;
+	class file { read write ioctl };
+}
+
+allow base_t base_t : file ioctl;
+allowxperm base_t base_t : file ioctl 0x1000;
semodule-utils/tests/bad-data/run.sh +337 -5

365 lines not on this page · raw message

Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Akhil Kohli

Add link/expand bad-data tests for neverallow and neverallowxperm enforcement at semodule_expand: cross-module base violations, same-module neverallow conflicts, and checkmodule deferral document tests.

Quoted 8 lines

Adapt same-module neverallowxperm for libsepol 3.11 (enforced at expand) while still passing on older userspace where enforcement is deferred. Refactor link/expand helpers through run_link_expand().

Add a cross-module require test: link rejects a consumer module when a required type is only declared in a separate provider module.

maintainer
#2 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 9 lines · Akhil Kohli

Add link/expand bad-data tests for neverallow and neverallowxperm enforcement at semodule_expand: cross-module base violations, same-module neverallow conflicts, and checkmodule deferral document tests.

Adapt same-module neverallowxperm for libsepol 3.11 (enforced at expand) while still passing on older userspace where enforcement is deferred. Refactor link/expand helpers through run_link_expand().

Quoted 6 lines
Quoted 4 lines

Add a cross-module require test: link rejects a consumer module when a required type is only declared in a separate provider module.

Merged.