Merge ~alexmurray/qa-regression-testing:kernel-lockdown-support into qa-regression-testing:master

Proposed by Alex Murray
Status: Rejected
Rejected by: Alex Murray
Proposed branch: ~alexmurray/qa-regression-testing:kernel-lockdown-support
Merge into: qa-regression-testing:master
Diff against target: 44 lines (+22/-0)
2 files modified
scripts/test-apparmor.py (+1/-0)
scripts/testlib.py (+21/-0)
Reviewer Review Type Date Requested Status
Steve Beattie Pending
Review via email: mp+416573@code.launchpad.net

Description of the change

The apparmor regression tests fail when using UEFI secure boot (and hence when kernel lockdown is enabled) since the ioperm/iopl tests fail due to being disallowed by locked when they are expected to pass.

To post a comment you must log in.
Revision history for this message
Steve Beattie (sbeattie) wrote :

On Wed, Mar 09, 2022 at 06:09:21AM -0000, Alex Murray wrote:
> Alex Murray has proposed merging ~alexmurray/qa-regression-testing:kernel-lockdown-support into qa-regression-testing:master.
>
> Requested reviews:
> Steve Beattie (sbeattie)
>
> For more details, see:
> https://code.launchpad.net/~alexmurray/qa-regression-testing/+git/qa-regression-testing/+merge/416573
>
> The apparmor regression tests fail when using UEFI secure boot (and
> hence when kernel lockdown is enabled) since the ioperm/iopl tests
> fail due to being disallowed by locked when they are expected to pass.

I understand why you want to fix this in this way, but this is
realistically a bug in the upstream test suite; if in lockdown mode,
the ioperm/opl tests should be skipped or possibly by XFAIL.

(Would also be nice to have some lockdown tests against the kernel
that ensure the things that are supposed to be enforced by lockdown
actually are.)

> --
> You are requested to review the proposed merge of ~alexmurray/qa-regression-testing:kernel-lockdown-support into qa-regression-testing:master.

> diff --git a/scripts/test-apparmor.py b/scripts/test-apparmor.py
> index 7a92efc..14a8f6f 100755
> --- a/scripts/test-apparmor.py
> +++ b/scripts/test-apparmor.py
> @@ -3211,6 +3211,7 @@ class ApparmorUnixDomainConnect(testlib.TestlibCase):
>
> if __name__ == '__main__':
> testlib.require_sudo()
> + testlib.require_nolockdown()
>
> if (len(sys.argv) > 1 and sys.argv[1] != '-v'):
> if "--with-subdomain-stress" in sys.argv:
> diff --git a/scripts/testlib.py b/scripts/testlib.py
> index 5bce8fa..e92312b 100644
> --- a/scripts/testlib.py
> +++ b/scripts/testlib.py
> @@ -225,6 +225,27 @@ def timeout(secs, f, *args):
> return result
>
>
> +def is_lockeddown():
> + rc, _ = cmd_pipe(["journalctl", "-k", "-b0"], ["grep", "-q", "-i", "kernel is locked down from EFI secure boot"])
> + if rc == 0:
> + return True
> + # try interrogating /sys/kernel/security/lockdown
> + if os.path.exists("/sys/kernel/security/lockdown"):
> + rc = cmd(["grep", "-q", "\\[none\\]", "/sys/kernel/security/lockdown"])
> + if rc == 0:
> + return True
> + return False
> +
> +def require_nolockdown():
> + if is_lockeddown():
> + print("This series of tests requires the lockdown LSM to be disabled.", file=sys.stderr)
> + sys.exit(1)
> +
> +def require_lockdown():
> + if not is_lockeddown():
> + print("This series of tests requires the lockdown LSM to be enabled.", file=sys.stderr)
> + sys.exit(1)
> +
> def require_nonroot():
> if os.geteuid() == 0:
> print("This series of tests should be run as a regular user with sudo access, not as root.", file=sys.stderr)

--
Steve Beattie
<email address hidden>

Revision history for this message
Steve Beattie (sbeattie) wrote :

On Tue, Mar 15, 2022 at 09:27:16PM -0000, Steve Beattie wrote:
> I understand why you want to fix this in this way, but this is
> realistically a bug in the upstream test suite; if in lockdown mode,
> the ioperm/opl tests should be skipped or possibly by XFAIL.

FYI, https://gitlab.com/apparmor/apparmor/-/issues/226 was filed for
this issue with upstream apparmor. When we have a fix there, we can
incorporate it as a patch into qrt like some of the other apparmor
regression test fixes we've had to bring back.

Thanks.

--
Steve Beattie
<email address hidden>

Unmerged commits

17a4edf... by Alex Murray

scripts/test-apparmor.py: Specify that test requires no lockdown

Since the apparmor regression tests wants to use ioperm / iopl but this is
disabled when the kernel is locked down, fail early in this case.

Signed-off-by: Alex Murray <email address hidden>

b6c5954... by Alex Murray

scripts/testlib.py: Add support for detecting kernel lockdown

Signed-off-by: Alex Murray <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/scripts/test-apparmor.py b/scripts/test-apparmor.py
2index 7a92efc..14a8f6f 100755
3--- a/scripts/test-apparmor.py
4+++ b/scripts/test-apparmor.py
5@@ -3211,6 +3211,7 @@ class ApparmorUnixDomainConnect(testlib.TestlibCase):
6
7 if __name__ == '__main__':
8 testlib.require_sudo()
9+ testlib.require_nolockdown()
10
11 if (len(sys.argv) > 1 and sys.argv[1] != '-v'):
12 if "--with-subdomain-stress" in sys.argv:
13diff --git a/scripts/testlib.py b/scripts/testlib.py
14index 5bce8fa..e92312b 100644
15--- a/scripts/testlib.py
16+++ b/scripts/testlib.py
17@@ -225,6 +225,27 @@ def timeout(secs, f, *args):
18 return result
19
20
21+def is_lockeddown():
22+ rc, _ = cmd_pipe(["journalctl", "-k", "-b0"], ["grep", "-q", "-i", "kernel is locked down from EFI secure boot"])
23+ if rc == 0:
24+ return True
25+ # try interrogating /sys/kernel/security/lockdown
26+ if os.path.exists("/sys/kernel/security/lockdown"):
27+ rc = cmd(["grep", "-q", "\\[none\\]", "/sys/kernel/security/lockdown"])
28+ if rc == 0:
29+ return True
30+ return False
31+
32+def require_nolockdown():
33+ if is_lockeddown():
34+ print("This series of tests requires the lockdown LSM to be disabled.", file=sys.stderr)
35+ sys.exit(1)
36+
37+def require_lockdown():
38+ if not is_lockeddown():
39+ print("This series of tests requires the lockdown LSM to be enabled.", file=sys.stderr)
40+ sys.exit(1)
41+
42 def require_nonroot():
43 if os.geteuid() == 0:
44 print("This series of tests should be run as a regular user with sudo access, not as root.", file=sys.stderr)

Subscribers

People subscribed via source and target branches