[NTOS:SE] NtQueryInformationToken: implement token sandbox inert querying
authorGeorge Bișoc <george.bisoc@reactos.org>
Sun, 12 Jun 2022 12:30:44 +0000 (14:30 +0200)
committerGeorge Bișoc <george.bisoc@reactos.org>
Mon, 13 Jun 2022 16:17:10 +0000 (18:17 +0200)
ntoskrnl/include/internal/se.h
ntoskrnl/se/token.c
ntoskrnl/se/tokencls.c

index db2dd0b..de65310 100644 (file)
@@ -443,6 +443,11 @@ SeCopyClientToken(
     _In_ KPROCESSOR_MODE PreviousMode,
     _Out_ PACCESS_TOKEN* NewToken);
 
+BOOLEAN
+NTAPI
+SeTokenIsInert(
+    _In_ PTOKEN Token);
+
 ULONG
 RtlLengthSidAndAttributes(
     _In_ ULONG Count,
index 83b962f..ad2dd8e 100644 (file)
@@ -1180,6 +1180,27 @@ SeCopyClientToken(
     return Status;
 }
 
+/**
+ * @brief
+ * Determines if a token is a sandbox inert token or not,
+ * based upon the token flags.
+ *
+ * @param[in] Token
+ * A valid access token to determine if such token is inert.
+ *
+ * @return
+ * Returns TRUE if the token is inert, FALSE otherwise.
+ */
+BOOLEAN
+NTAPI
+SeTokenIsInert(
+    _In_ PTOKEN Token)
+{
+    PAGED_CODE();
+
+    return (((PTOKEN)Token)->TokenFlags & TOKEN_SANDBOX_INERT) != 0;
+}
+
 /**
  * @brief
  * Internal function that deals with access token object destruction and deletion.
index b9d1615..50e81a9 100644 (file)
@@ -984,9 +984,26 @@ NtQueryInformationToken(
             }
 
             case TokenSandBoxInert:
-                DPRINT1("NtQueryInformationToken(TokenSandboxInert) not implemented\n");
-                Status = STATUS_NOT_IMPLEMENTED;
+            {
+                ULONG IsTokenSandBoxInert;
+
+                DPRINT("NtQueryInformationToken(TokenSandBoxInert)\n");
+
+                IsTokenSandBoxInert = SeTokenIsInert(Token);
+                _SEH2_TRY
+                {
+                    /* Buffer size was already verified, no need to check here again */
+                    *(PULONG)TokenInformation = IsTokenSandBoxInert;
+                    *ReturnLength = sizeof(ULONG);
+                }
+                _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+                {
+                    Status = _SEH2_GetExceptionCode();
+                }
+                _SEH2_END;
+
                 break;
+            }
 
             case TokenSessionId:
             {