# CVE-2023-35631 — win32k.sys patch diff

`win32k.sys` 10.0.22621.2792 -> 10.0.22621.2861 (ghidriff).

## `KfGetJobProvidingUILimit`  (modified)

```diff
--- KfGetJobProvidingUILimit
+++ KfGetJobProvidingUILimit
@@ -1,48 +1,11 @@
 

-/* WARNING: Function: __security_check_cookie replaced with injection: security_check_cookie */

+/* WARNING: Function: _guard_dispatch_icall replaced with injection: guard_dispatch_icall */

 

-ulonglong KfGetJobProvidingUILimit(undefined8 param_1,uint param_2)

+void KfGetJobProvidingUILimit(void)

 

 {

-  int iVar1;

-  uint uVar2;

-  ulonglong uVar3;

-  undefined4 extraout_var;

-  ulonglong unaff_RBX;

-  longlong unaff_RBP;

-  ulonglong unaff_RDI;

-  undefined8 in_R9;

-  ulonglong in_stack_00000020;

-  

-  uVar3 = in_stack_00000020 & unaff_RBX;

-  iVar1 = ZwQueryInformationJobObject

-                    ((int)unaff_RBX + 0x10,(int)unaff_RBX + 3,unaff_RBP + -0x20,in_R9,uVar3);

-  if ((-1 < iVar1) && (iVar1 = *(int *)(unaff_RBP + -0x20), iVar1 != 0)) {

-    if (iVar1 == 1) {

-      unaff_RBX = unaff_RBP - 0x20;

-      unaff_RDI = 1;

-    }

-    else {

-      iVar1 = iVar1 * 8 + 8;

-      unaff_RBX = ExAllocatePool2(0x100,iVar1,0x626a7355);

-      if (unaff_RBX != 0) {

-        uVar2 = ZwQueryInformationJobObject

-                          (*(undefined8 *)(unaff_RBP + -0x30),3,unaff_RBX,iVar1,uVar3 & unaff_RDI);

-        unaff_RDI = (ulonglong)(~uVar2 >> 0x1f);

-      }

-    }

-  }

-  uVar3 = ZwClose(*(undefined8 *)(unaff_RBP + -0x30));

-  if ((int)unaff_RDI != 0) {

-    *(ulonglong *)(unaff_RBP + -0x28) = unaff_RBX;

-    uVar2 = PsGetJobSessionId();

-    iVar1 = W32AttachToSessionAndExecute<<lambda_a68a4ae4ab423316b921358be06460a3>_>

-                      (uVar2,(undefined8 *)(unaff_RBP + -0x28));

-    uVar3 = CONCAT44(extraout_var,iVar1);

-  }

-  if ((unaff_RBX != 0) && (uVar3 = unaff_RBP - 0x20, unaff_RBX != uVar3)) {

-    uVar3 = ExFreePoolWithTag(unaff_RBX,0);

-  }

-  return uVar3;

+                    /* 0x188d0  194  KfGetJobProvidingUILimit */

+  (*DAT_0)();

+  return;

 }
```

## `KfGetJobIdentity`  (modified)

```diff
--- KfGetJobIdentity
+++ KfGetJobProvidingUILimit
@@ -1,65 +1,48 @@
 

 /* WARNING: Function: __security_check_cookie replaced with injection: security_check_cookie */

 

-ulonglong KfGetJobIdentity(uint param_1)

+ulonglong KfGetJobProvidingUILimit(undefined8 param_1,uint param_2)

 

 {

-  char cVar1;

-  int iVar2;

-  uint uVar3;

-  undefined8 in_RAX;

-  ulonglong uVar5;

+  int iVar1;

+  uint uVar2;

+  ulonglong uVar3;

   undefined4 extraout_var;

-  char *in_RDX;

   ulonglong unaff_RBX;

   longlong unaff_RBP;

-  longlong in_R11;

-  undefined8 in_XMM0_Qa;

-  undefined8 in_XMM0_Qb;

+  ulonglong unaff_RDI;

+  undefined8 in_R9;

   ulonglong in_stack_00000020;

-  char *pcVar4;

   

-  cVar1 = (char)in_RAX + -0x46;

-  pcVar4 = (char *)CONCAT71((int7)((ulonglong)in_RAX >> 8),cVar1);

-  *in_RDX = *in_RDX + cVar1;

-  *pcVar4 = *pcVar4 + cVar1;

-  *(undefined8 *)(unaff_RBP + -0x20) = in_XMM0_Qa;

-  *(undefined8 *)(unaff_RBP + -0x18) = in_XMM0_Qb;

-  *(undefined8 *)(in_R11 + -0x68) = *(undefined8 *)pcVar4;

-  uVar5 = ObOpenObjectByPointer();

-  if (-1 < (int)uVar5) {

-    iVar2 = ZwQueryInformationJobObject

-                      (*(undefined8 *)(unaff_RBP + -0x30),(int)unaff_RBX + 3,unaff_RBP + -0x20,

-                       (int)unaff_RBX + 0x10,in_stack_00000020 & unaff_RBX);

-    uVar3 = 0;

-    if ((-1 < iVar2) && (iVar2 = *(int *)(unaff_RBP + -0x20), iVar2 != 0)) {

-      if (iVar2 == 1) {

-        unaff_RBX = unaff_RBP - 0x20;

-        uVar3 = 1;

-      }

-      else {

-        iVar2 = iVar2 * 8 + 8;

-        unaff_RBX = ExAllocatePool2(0x100,iVar2,0x626a7355);

-        uVar3 = 0;

-        if (unaff_RBX != 0) {

-          uVar3 = ZwQueryInformationJobObject

-                            (*(undefined8 *)(unaff_RBP + -0x30),3,unaff_RBX,iVar2,0);

-          uVar3 = ~uVar3 >> 0x1f;

-        }

+  uVar3 = in_stack_00000020 & unaff_RBX;

+  iVar1 = ZwQueryInformationJobObject

+                    ((int)unaff_RBX + 0x10,(int)unaff_RBX + 3,unaff_RBP + -0x20,in_R9,uVar3);

+  if ((-1 < iVar1) && (iVar1 = *(int *)(unaff_RBP + -0x20), iVar1 != 0)) {

+    if (iVar1 == 1) {

+      unaff_RBX = unaff_RBP - 0x20;

+      unaff_RDI = 1;

+    }

+    else {

+      iVar1 = iVar1 * 8 + 8;

+      unaff_RBX = ExAllocatePool2(0x100,iVar1,0x626a7355);

+      if (unaff_RBX != 0) {

+        uVar2 = ZwQueryInformationJobObject

+                          (*(undefined8 *)(unaff_RBP + -0x30),3,unaff_RBX,iVar1,uVar3 & unaff_RDI);

+        unaff_RDI = (ulonglong)(~uVar2 >> 0x1f);

       }

     }

-    uVar5 = ZwClose(*(undefined8 *)(unaff_RBP + -0x30));

-    if (uVar3 != 0) {

-      *(ulonglong *)(unaff_RBP + -0x28) = unaff_RBX;

-      uVar3 = PsGetJobSessionId();

-      iVar2 = W32AttachToSessionAndExecute<<lambda_a68a4ae4ab423316b921358be06460a3>_>

-                        (uVar3,(undefined8 *)(unaff_RBP + -0x28));

-      uVar5 = CONCAT44(extraout_var,iVar2);

-    }

-    if ((unaff_RBX != 0) && (uVar5 = unaff_RBP - 0x20, unaff_RBX != uVar5)) {

-      uVar5 = ExFreePoolWithTag(unaff_RBX,0);

-    }

   }

-  return uVar5;

+  uVar3 = ZwClose(*(undefined8 *)(unaff_RBP + -0x30));

+  if ((int)unaff_RDI != 0) {

+    *(ulonglong *)(unaff_RBP + -0x28) = unaff_RBX;

+    uVar2 = PsGetJobSessionId();

+    iVar1 = W32AttachToSessionAndExecute<<lambda_a68a4ae4ab423316b921358be06460a3>_>

+                      (uVar2,(undefined8 *)(unaff_RBP + -0x28));

+    uVar3 = CONCAT44(extraout_var,iVar1);

+  }

+  if ((unaff_RBX != 0) && (uVar3 = unaff_RBP - 0x20, unaff_RBX != uVar3)) {

+    uVar3 = ExFreePoolWithTag(unaff_RBX,0);

+  }

+  return uVar3;

 }
```

## `Win32kKernelExportsSetImpl`  (modified)

```diff
--- Win32kKernelExportsSetImpl
+++ Win32kKernelExportsSetImpl
@@ -1,12 +1,38 @@
+

+/* WARNING: Function: __security_check_cookie replaced with injection: security_check_cookie */

 

 undefined8 Win32kKernelExportsSetImpl(uint param_1,void *param_2,uint param_3)

 

 {

-  code *pcVar1;

-  undefined8 uVar2;

+  bool bVar1;

+  uint uVar2;

+  undefined1 auStack_48 [32];

+  uint local_28 [4];

+  ulonglong local_18;

   

-  pcVar1 = (code *)swi(3);

-  uVar2 = (*pcVar1)();

-  return uVar2;

+  local_18 = __security_cookie ^ (ulonglong)auStack_48;

+  ApiVersionInUse = 3;

+  if (param_1 != 3) {

+    if (param_1 < 4) {

+      local_28[0] = 1;

+      local_28[1] = 4;

+      local_28[2] = 5;

+      uVar2 = local_28[param_1];

+      ApiVersionInUse = param_1;

+    }

+    else {

+      uVar2 = 6;

+    }

+    bVar1 = param_3 < uVar2;

+    param_3 = uVar2;

+    if (bVar1) {

+      return 0xc00000bb;

+    }

+  }

+  if (6 < param_3) {

+    return 0xc00000bb;

+  }

+  memcpy(&KernelExports,param_2,(ulonglong)param_3 << 3);

+  return 0;

 }
```

## `KfSetJobUILimits`  (modified)

```diff
--- KfSetJobUILimits
+++ KfSetJobUILimits
@@ -1,9 +1,11 @@
 

-undefined8 KfSetJobUILimits(void)

+/* WARNING: Function: _guard_dispatch_icall replaced with injection: guard_dispatch_icall */

+

+void KfSetJobUILimits(void)

 

 {

-  undefined8 in_RAX;

-  

-  return in_RAX;

+                    /* 0x18960  198  KfSetJobUILimits */

+  (*DAT_0)();

+  return;

 }
```
