Commit ff89a819 authored by Mark Brown's avatar Mark Brown Committed by Catalin Marinas

kselftest/arm64: Validate contents of EXTRA_CONTEXT blocks

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: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220829160703.874492-8-broonie@kernel.orgSigned-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent 1998c823
...@@ -25,7 +25,8 @@ struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic, ...@@ -25,7 +25,8 @@ struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic,
return found; 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; struct _aarch64_ctx *term;
...@@ -47,6 +48,9 @@ bool validate_extra_context(struct extra_context *extra, char **err) ...@@ -47,6 +48,9 @@ bool validate_extra_context(struct extra_context *extra, char **err)
if (*err) if (*err)
return false; return false;
*extra_data = (void *)extra->datap;
*extra_size = extra->size;
return true; return true;
} }
...@@ -111,6 +115,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) ...@@ -111,6 +115,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
struct za_context *za = NULL; struct za_context *za = NULL;
struct _aarch64_ctx *head = struct _aarch64_ctx *head =
(struct _aarch64_ctx *)uc->uc_mcontext.__reserved; (struct _aarch64_ctx *)uc->uc_mcontext.__reserved;
void *extra_data = NULL;
size_t extra_sz = 0;
if (!err) if (!err)
return false; return false;
...@@ -125,10 +131,20 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) ...@@ -125,10 +131,20 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
switch (head->magic) { switch (head->magic) {
case 0: case 0:
if (head->size) if (head->size) {
*err = "Bad size for terminator"; *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; terminated = true;
}
break; break;
case FPSIMD_MAGIC: case FPSIMD_MAGIC:
if (flags & FPSIMD_CTX) if (flags & FPSIMD_CTX)
...@@ -196,7 +212,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) ...@@ -196,7 +212,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err)
} }
if (new_flags & EXTRA_CTX) if (new_flags & EXTRA_CTX)
if (!validate_extra_context(extra, err)) if (!validate_extra_context(extra, err,
&extra_data, &extra_sz))
return false; return false;
if (new_flags & SVE_CTX) if (new_flags & SVE_CTX)
if (!validate_sve_context(sve, err)) if (!validate_sve_context(sve, err))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment