diff --git a/meta-arm-gcs/gcs.yml b/meta-arm-gcs/gcs.yml index 9daafa4f..06aad95d 100644 --- a/meta-arm-gcs/gcs.yml +++ b/meta-arm-gcs/gcs.yml @@ -53,7 +53,7 @@ local_conf_header: IMAGE_CLASSES += "testimage" TEST_SUITES = "ping ssh gcs" IMAGE_FEATURES += "ssh-server-dropbear" - CORE_IMAGE_EXTRA_INSTALL += "ssh-pregen-hostkeys binutils kselftest" + CORE_IMAGE_EXTRA_INSTALL += "ssh-pregen-hostkeys binutils kselftest gcs-test" target: - core-image-full-cmdline diff --git a/meta-arm-gcs/lib/oeqa/runtime/cases/gcs.py b/meta-arm-gcs/lib/oeqa/runtime/cases/gcs.py index 3e9a676d..852f0d6d 100644 --- a/meta-arm-gcs/lib/oeqa/runtime/cases/gcs.py +++ b/meta-arm-gcs/lib/oeqa/runtime/cases/gcs.py @@ -47,6 +47,21 @@ class GCSTests(OERuntimeTestCase): self.assertEqual(status, 0, f"ls failed: {output}") self.assertEqual(output, "/usr") + def test_chkfeat(self): + """ + Verify that CHKFEAT reports GCS as enabled when running with the tunables. + + If this fails then GCS is not being properly enabled at runtime glibc. The kernel + and glibc patches may be out of sync. + """ + cmd = "GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1:glibc.cpu.aarch64_gcs_policy=2 gcs-test" + status, output = self.target.run(cmd) + self.assertEqual(status, 0, f"gcs-test failed: {output}") + + # gcs-test should return 1 if GCS is not enabled via the tunables + cmd = "gcs-test" + status, output = self.target.run(cmd) + self.assertEqual(status, 1, f"gcs-test failed: {output}") @OEHasPackage(['kselftest']) @unittest.expectedFailure diff --git a/meta-arm-gcs/recipes-test/gcs-test/files/chkfeat.s b/meta-arm-gcs/recipes-test/gcs-test/files/chkfeat.s new file mode 100644 index 00000000..5bf7843c --- /dev/null +++ b/meta-arm-gcs/recipes-test/gcs-test/files/chkfeat.s @@ -0,0 +1,22 @@ +/* Copyright (C) 2024 Arm Ltd */ +/* SPDX-License-Identifier: MIT */ + +.global gcs_enabled +.type gcs_enabled,@function +gcs_enabled: + mov x16, #0x1 + hint 40 + eor x0, x16, #0x1 + ret + +.pushsection .note.gnu.property, "a" +.balign 8 +.long 4 +.long 0x10 +.long 0x5 +.asciz "GNU" +.long 0xc0000000 +.long 4 +.long 4 +.long 0 +.popsection diff --git a/meta-arm-gcs/recipes-test/gcs-test/files/gcs_enabled.c b/meta-arm-gcs/recipes-test/gcs-test/files/gcs_enabled.c new file mode 100644 index 00000000..50cff8ad --- /dev/null +++ b/meta-arm-gcs/recipes-test/gcs-test/files/gcs_enabled.c @@ -0,0 +1,9 @@ +// Copyright (C) 2024 Arm Ltd +// SPDX-License-Identifier: MIT + +extern int gcs_enabled(void); + +int main(void) +{ + return gcs_enabled() ? 0 : 1; +} diff --git a/meta-arm-gcs/recipes-test/gcs-test/gcs-test.bb b/meta-arm-gcs/recipes-test/gcs-test/gcs-test.bb new file mode 100644 index 00000000..b40d00a1 --- /dev/null +++ b/meta-arm-gcs/recipes-test/gcs-test/gcs-test.bb @@ -0,0 +1,18 @@ +SUMMARY = "test" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +SRC_URI = "file://chkfeat.s file://gcs_enabled.c" + +S = "${WORKDIR}" + +LDFLAGS:append = " -z experimental-gcs=always" + +do_compile() { + ${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/gcs_enabled.c ${WORKDIR}/chkfeat.s -o gcs-test +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 gcs-test ${D}${bindir} +}