Qualify Windows IPC client runtime and prepare bounded native providers
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -5,11 +5,32 @@
|
||||
#include <windows.h>
|
||||
#include <rpc.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "w32time.h"
|
||||
/* Documented public SDK API; older MinGW headers omit its declaration. */
|
||||
int RPC_ENTRY RpcExceptionFilter(unsigned long exception_code);
|
||||
/* Older MinGW headers stop at V3. This is the documented x64 V5 SDK layout,
|
||||
* not a fallback to an older authentication contract. MSVC also checks it
|
||||
* directly against its native SDK declaration. Windows x64 is the only target.
|
||||
* https://learn.microsoft.com/windows/win32/api/rpcdce/ns-rpcdce-rpc_security_qos_v5_w
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned long Version, Capabilities, IdentityTracking, ImpersonationType;
|
||||
unsigned long AdditionalSecurityInfoType;
|
||||
union { RPC_HTTP_TRANSPORT_CREDENTIALS_W *HttpCredentials; } u;
|
||||
void *Sid;
|
||||
unsigned int EffectiveOnly;
|
||||
void *ServerSecurityDescriptor;
|
||||
} RmmRpcQosV5;
|
||||
_Static_assert(sizeof(RmmRpcQosV5) == 56, "x64 RPC QOS V5 ABI");
|
||||
_Static_assert(offsetof(RmmRpcQosV5, Sid) == offsetof(RPC_SECURITY_QOS_V3_W, Sid), "SDK QOS prefix ABI");
|
||||
_Static_assert(offsetof(RmmRpcQosV5, ServerSecurityDescriptor) == 48, "x64 server descriptor ABI");
|
||||
#ifdef _MSC_VER
|
||||
_Static_assert(sizeof(RmmRpcQosV5) == sizeof(RPC_SECURITY_QOS_V5_W), "native SDK QOS V5 ABI");
|
||||
_Static_assert(offsetof(RmmRpcQosV5, ServerSecurityDescriptor) == offsetof(RPC_SECURITY_QOS_V5_W, ServerSecurityDescriptor), "native SDK descriptor ABI");
|
||||
#endif
|
||||
|
||||
typedef struct Allocation { struct Allocation *next; size_t size; } Allocation;
|
||||
typedef struct { Allocation *head; size_t total; } Arena;
|
||||
@@ -106,7 +127,7 @@ uint32_t rmm_clock_query(RmmClockStatus *out) {
|
||||
/* Kernel-authenticated ALPC only. No automatic fallback to named pipes.
|
||||
* The expected SID is fixed locally, never adopted from endpoint metadata.
|
||||
*/
|
||||
uint32_t rmm_clock_alpc_query(RmmClockStatus *out) {
|
||||
static uint32_t alpc_query(RmmClockStatus *out, unsigned control) {
|
||||
RPC_IF_ID id = {0};
|
||||
RPC_EP_INQ_HANDLE inquiry = NULL;
|
||||
RPC_STATUS result;
|
||||
@@ -132,15 +153,39 @@ uint32_t rmm_clock_alpc_query(RmmClockStatus *out) {
|
||||
if (result) {RpcBindingFree(&binding);break;}
|
||||
if (local) {
|
||||
_Alignas(8) BYTE expected_sid[SECURITY_MAX_SID_SIZE];
|
||||
_Alignas(8) BYTE service_sid[SECURITY_MAX_SID_SIZE];
|
||||
_Alignas(8) BYTE acl_buffer[sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + SECURITY_MAX_SID_SIZE];
|
||||
SECURITY_DESCRIPTOR descriptor;
|
||||
WCHAR domain[64];
|
||||
DWORD domain_size = sizeof(domain) / sizeof(domain[0]);
|
||||
DWORD service_sid_size = sizeof(service_sid);
|
||||
SID_NAME_USE sid_type;
|
||||
DWORD sid_size = sizeof(expected_sid);
|
||||
RPC_SECURITY_QOS_V3_W qos = {0};
|
||||
if (!CreateWellKnownSid(WinLocalServiceSid, NULL, expected_sid, &sid_size)) result = GetLastError();
|
||||
RmmRpcQosV5 qos = {0};
|
||||
/* An account-only SID19 binding also accepts other LocalService
|
||||
* processes, including our network agent. The client-owned V5
|
||||
* descriptor therefore requires the separate W32Time service SID.
|
||||
* No descriptor/identity is obtained from endpoint metadata.
|
||||
* Controls are fixed read-only diagnostics, never production modes.
|
||||
*/
|
||||
if (!CreateWellKnownSid(control == 1 ? WinLocalSystemSid : WinLocalServiceSid,
|
||||
NULL, expected_sid, &sid_size)) result = GetLastError();
|
||||
if (!result && !LookupAccountNameW(NULL,
|
||||
control == 2 ? L"NT SERVICE\\RmmDiscoveryWindows" : L"NT SERVICE\\W32Time",
|
||||
service_sid, &service_sid_size, domain, &domain_size, &sid_type)) result = GetLastError();
|
||||
if (!result && (!IsValidSid(service_sid) || service_sid_size > sizeof(service_sid))) result = ERROR_INVALID_SID;
|
||||
if (!result && !InitializeAcl((PACL)acl_buffer, sizeof(acl_buffer), ACL_REVISION)) result = GetLastError();
|
||||
if (!result && !AddAccessAllowedAce((PACL)acl_buffer, ACL_REVISION, GENERIC_ALL, service_sid)) result = GetLastError();
|
||||
if (!result && !InitializeSecurityDescriptor(&descriptor, SECURITY_DESCRIPTOR_REVISION)) result = GetLastError();
|
||||
if (!result && !SetSecurityDescriptorDacl(&descriptor, TRUE, (PACL)acl_buffer, FALSE)) result = GetLastError();
|
||||
if (!result) {
|
||||
qos.Version = RPC_C_SECURITY_QOS_VERSION_3;
|
||||
qos.Version = 5; /* RPC_C_SECURITY_QOS_VERSION_5 */
|
||||
qos.Capabilities = RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH;
|
||||
qos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
|
||||
qos.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY;
|
||||
qos.Sid = expected_sid;
|
||||
qos.EffectiveOnly = TRUE;
|
||||
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);
|
||||
@@ -154,3 +199,6 @@ uint32_t rmm_clock_alpc_query(RmmClockStatus *out) {
|
||||
RpcMgmtEpEltInqDone(&inquiry);
|
||||
return result == RPC_X_NO_MORE_ENTRIES ? EPT_S_NOT_REGISTERED : result;
|
||||
}
|
||||
uint32_t rmm_clock_alpc_query(RmmClockStatus *out) { return alpc_query(out, 0); }
|
||||
uint32_t rmm_clock_wrong_account(RmmClockStatus *out) { return alpc_query(out, 1); }
|
||||
uint32_t rmm_clock_wrong_service(RmmClockStatus *out) { return alpc_query(out, 2); }
|
||||
|
||||
Reference in New Issue
Block a user