[PATCH 3/3] ntdll: Validate xstate alignment in validate_context_xstate().
Paul Gofman
wine at gitlab.winehq.org
Thu Jun 16 14:08:47 CDT 2022
From: Paul Gofman <pgofman at codeweavers.com>
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
dlls/ntdll/tests/exception.c | 14 ++++++++++++++
dlls/ntdll/unix/thread.c | 2 ++
2 files changed, 16 insertions(+)
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index 820e435bc1b..06a38756f80 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -9445,6 +9445,7 @@ static void test_extended_context(void)
CONTEXT_EX *context_ex;
CONTEXT *context;
unsigned data[8];
+ NTSTATUS status;
HANDLE thread;
ULONG64 mask;
XSTATE *xs;
@@ -10227,6 +10228,19 @@ static void test_extended_context(void)
thread = CreateThread(NULL, 0, test_extended_context_thread, 0, CREATE_SUSPENDED, NULL);
ok(!!thread, "Failed to create thread.\n");
+ /* Unaligned xstate. */
+ length = sizeof(context_buffer);
+ memset(context_buffer, 0xcc, sizeof(context_buffer));
+ bret = pInitializeContext(context_buffer, CONTEXT_FULL | CONTEXT_XSTATE | CONTEXT_FLOATING_POINT,
+ &context, &length);
+ ok(bret, "Got unexpected bret %#x.\n", bret);
+ context_ex = (CONTEXT_EX *)(context + 1);
+ context_ex->XState.Offset += 0x10;
+ status = pNtGetContextThread(thread, context);
+ ok(status == STATUS_INVALID_PARAMETER, "Unexpected status %#lx.\n", status);
+ status = pNtGetContextThread(GetCurrentThread(), context);
+ ok(status == STATUS_INVALID_PARAMETER, "Unexpected status %#lx.\n", status);
+
bret = pInitializeContext(context_buffer, CONTEXT_FULL | CONTEXT_XSTATE | CONTEXT_FLOATING_POINT,
&context, &length);
ok(bret, "Got unexpected bret %#x.\n", bret);
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c
index b393315e6fe..00ee607a671 100644
--- a/dlls/ntdll/unix/thread.c
+++ b/dlls/ntdll/unix/thread.c
@@ -167,6 +167,8 @@ BOOL validate_context_xstate( CONTEXT *context )
|| context_ex->XState.Length > sizeof(XSTATE))
return FALSE;
+ if (((ULONG_PTR)context_ex + context_ex->XState.Offset) & 63) return FALSE;
+
return TRUE;
}
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/260
More information about the wine-devel
mailing list