kselftest/arm64: Validate contents of EXTRA_CONTEXT blocks
authorMark Brown <broonie@kernel.org>
Mon, 29 Aug 2022 16:07:00 +0000 (17:07 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Wed, 7 Sep 2022 13:25:46 +0000 (14:25 +0100)
Currently in validate_reserved() we check the basic form and contents of
an EXTRA_CONTEXT block but do not actually validate anything inside the
data block it provides. Extend the validation to do so, when we get to the
terminator for the main data block reset and start walking the extra data
block instead.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220829160703.874492-8-broonie@kernel.org
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
tools/testing/selftests/arm64/signal/testcases/testcases.c

index 0b3c9b4b1d39f30441b7d8bb9cafe802fd1fa929..e1c625b20ac4cb818f01f049b70e9dd417da5a08 100644 (file)
@@ -25,7 +25,8 @@ struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic,
        return found;
 }
 
-bool validate_extra_context(struct extra_context *extra, char **err)
+bool validate_extra_context(struct extra_context *extra, char **err,
+                           void **extra_data, size_t *extra_size)
 {
        struct _aarch64_ctx *term;
 
@@ -47,6 +48,9 @@ bool validate_extra_context(struct extra_context *extra, char **err)
        if (*err)
                return false;
 
+       *extra_data = (void *)extra->datap;
+       *extra_size = extra->size;
+
        return true;
 }
 
@@ -111,6 +115,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
        struct za_context *za = NULL;
        struct _aarch64_ctx *head =
                (struct _aarch64_ctx *)uc->uc_mcontext.__reserved;
+       void *extra_data = NULL;
+       size_t extra_sz = 0;
 
        if (!err)
                return false;
@@ -125,10 +131,20 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
 
                switch (head->magic) {
                case 0:
-                       if (head->size)
+                       if (head->size) {
                                *err = "Bad size for terminator";
-                       else
+                       } else if (extra_data) {
+                               /* End of main data, walking the extra data */
+                               head = extra_data;
+                               resv_sz = extra_sz;
+                               offs = 0;
+
+                               extra_data = NULL;
+                               extra_sz = 0;
+                               continue;
+                       } else {
                                terminated = true;
+                       }
                        break;
                case FPSIMD_MAGIC:
                        if (flags & FPSIMD_CTX)
@@ -196,7 +212,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
                }
 
                if (new_flags & EXTRA_CTX)
-                       if (!validate_extra_context(extra, err))
+                       if (!validate_extra_context(extra, err,
+                                                   &extra_data, &extra_sz))
                                return false;
                if (new_flags & SVE_CTX)
                        if (!validate_sve_context(sve, err))