Trace native Windows clock RPC failure without changing trust checks
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -71,20 +71,47 @@ typedef struct {
|
||||
} RmmClockStatus;
|
||||
_Static_assert(sizeof(RmmClockStatus) == 64, "Rust numeric clock ABI");
|
||||
_Static_assert(sizeof(RMM_W32TIME_STATUS) == 120, "MS-W32T x64 structure ABI");
|
||||
static uint32_t invoke_status(RPC_BINDING_HANDLE binding, RmmClockStatus *out) {
|
||||
/* Diagnostic-only numeric ABI. No strings, names, pointers or remote arrays
|
||||
* leave C. A zero native return is meaningful only when return_present is1.
|
||||
* Stages:10 compose,20 binding,30 auth,40 call-timeout,50 arena,
|
||||
* 60 invoking,61 returned,62 raw numeric status,70 local guard,80 mapped,
|
||||
* 90 contained RPC/SEH exception. Never used by the clock trust evaluator.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t stage, native_rpc_return, native_rpc_return_present, rpc_exception;
|
||||
uint32_t status_present, ul_size, c_entries, p_entries_present;
|
||||
} RmmClockTrace;
|
||||
_Static_assert(sizeof(RmmClockTrace) == 32, "Rust numeric diagnostic ABI");
|
||||
static uint32_t invoke_status(RPC_BINDING_HANDLE binding, RmmClockStatus *out, RmmClockTrace *trace) {
|
||||
RMM_W32TIME_STATUS *status = NULL;
|
||||
unsigned long result = 0;
|
||||
Arena arena = {0};
|
||||
if (trace) trace->stage = 50;
|
||||
if (!result && !InitOnceExecuteOnce(&arena_once, initialize_arena, NULL, NULL)) result = ERROR_NOT_ENOUGH_MEMORY;
|
||||
if (!result && TlsGetValue(arena_index)) result = ERROR_BUSY;
|
||||
if (!result && !TlsSetValue(arena_index, &arena)) result = GetLastError();
|
||||
if (!result) {
|
||||
RpcTryExcept {
|
||||
if (trace) trace->stage = 60;
|
||||
result = RmmW32TimeQueryStatus(binding, &status);
|
||||
if (trace) {
|
||||
trace->stage = 61; trace->native_rpc_return_present = 1;
|
||||
trace->native_rpc_return = result;
|
||||
}
|
||||
if (!result) {
|
||||
if (!status || status->ulSize != sizeof(*status) || status->cEntries || status->pEntries)
|
||||
if (trace) {
|
||||
trace->stage = 62; trace->status_present = status != NULL;
|
||||
if (status) {
|
||||
trace->ul_size = status->ulSize; trace->c_entries = status->cEntries;
|
||||
trace->p_entries_present = status->pEntries != NULL;
|
||||
}
|
||||
}
|
||||
if (!status || status->ulSize != sizeof(*status) || status->cEntries || status->pEntries) {
|
||||
if (trace) trace->stage = 70;
|
||||
result = RPC_X_BAD_STUB_DATA;
|
||||
}
|
||||
else {
|
||||
if (trace) trace->stage = 80;
|
||||
out->leap = status->eLeapIndicator; out->stratum = status->nStratum;
|
||||
out->state = status->ulLcState; out->flags = status->ulTSFlags;
|
||||
out->last_result = status->eLastSyncResult; out->size = status->ulSize;
|
||||
@@ -95,21 +122,24 @@ static uint32_t invoke_status(RPC_BINDING_HANDLE binding, RmmClockStatus *out) {
|
||||
}
|
||||
} RpcExcept(RpcExceptionFilter(RpcExceptionCode())) {
|
||||
result = RpcExceptionCode();
|
||||
if (trace) {trace->stage = 90; trace->rpc_exception = result;}
|
||||
} RpcEndExcept
|
||||
release_allocations(&arena);
|
||||
TlsSetValue(arena_index, NULL);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
uint32_t rmm_clock_query(RmmClockStatus *out) {
|
||||
static uint32_t pipe_query(RmmClockStatus *out, RmmClockTrace *trace) {
|
||||
RPC_WSTR text = NULL;
|
||||
RPC_BINDING_HANDLE binding = NULL;
|
||||
RPC_SECURITY_QOS qos = {0};
|
||||
unsigned long result;
|
||||
memset(out, 0, sizeof(*out));
|
||||
if (trace) trace->stage = 10;
|
||||
result = RpcStringBindingComposeW(NULL, (RPC_WSTR)L"ncacn_np", NULL,
|
||||
(RPC_WSTR)L"\\pipe\\W32TIME_ALT", NULL, &text);
|
||||
if (result) return result;
|
||||
if (trace) trace->stage = 20;
|
||||
result = RpcBindingFromStringBindingW(text, &binding);
|
||||
RpcStringFreeW(&text);
|
||||
if (result) return result;
|
||||
@@ -117,13 +147,23 @@ uint32_t rmm_clock_query(RmmClockStatus *out) {
|
||||
qos.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;
|
||||
qos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
|
||||
qos.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY;
|
||||
if (trace) trace->stage = 30;
|
||||
result = RpcBindingSetAuthInfoExW(binding, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
||||
RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NONE, &qos);
|
||||
if (!result) result = RpcBindingSetOption(binding, RPC_C_OPT_CALL_TIMEOUT, 1500);
|
||||
if (!result) result = invoke_status(binding, out);
|
||||
if (!result) {
|
||||
if (trace) trace->stage = 40;
|
||||
result = RpcBindingSetOption(binding, RPC_C_OPT_CALL_TIMEOUT, 1500);
|
||||
}
|
||||
if (!result) result = invoke_status(binding, out, trace);
|
||||
RpcBindingFree(&binding);
|
||||
return result;
|
||||
}
|
||||
uint32_t rmm_clock_query(RmmClockStatus *out) { return pipe_query(out, NULL); }
|
||||
uint32_t rmm_clock_query_trace(RmmClockTrace *trace) {
|
||||
RmmClockStatus ignored = {0};
|
||||
memset(trace, 0, sizeof(*trace));
|
||||
return pipe_query(&ignored, trace);
|
||||
}
|
||||
/* Kernel-authenticated ALPC only. No automatic fallback to named pipes.
|
||||
* The expected SID is fixed locally, never adopted from endpoint metadata.
|
||||
*/
|
||||
@@ -188,7 +228,7 @@ static uint32_t alpc_query(RmmClockStatus *out, unsigned control) {
|
||||
qos.ServerSecurityDescriptor = &descriptor;
|
||||
result = RpcBindingSetAuthInfoExW(binding, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
|
||||
RPC_C_AUTHN_WINNT, NULL, RPC_C_AUTHZ_NONE, (RPC_SECURITY_QOS *)&qos);
|
||||
if (!result) result = invoke_status(binding, out);
|
||||
if (!result) result = invoke_status(binding, out, NULL);
|
||||
}
|
||||
RpcBindingFree(&binding);
|
||||
break; /* no retry, alternate identity, endpoint or weaker transport */
|
||||
|
||||
Reference in New Issue
Block a user