|
| 1 | +From bcdc1467253d444c8ace779fefae94b1c3f29b54 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Olivier Fourdan < [email protected]> |
| 3 | +Date: Wed, 10 Sep 2025 15:58:57 +0200 |
| 4 | +Subject: [PATCH 1/2] xkb: Free the XKB resource when freeing XkbInterest |
| 5 | +MIME-Version: 1.0 |
| 6 | +Content-Type: text/plain; charset=UTF-8 |
| 7 | +Content-Transfer-Encoding: 8bit |
| 8 | + |
| 9 | +XkbRemoveResourceClient() would free the XkbInterest data associated |
| 10 | +with the device, but not the resource associated with it. |
| 11 | + |
| 12 | +As a result, when the client terminates, the resource delete function |
| 13 | +gets called and accesses already freed memory: |
| 14 | + |
| 15 | + | Invalid read of size 8 |
| 16 | + | at 0x5BC0C0: XkbRemoveResourceClient (xkbEvents.c:1047) |
| 17 | + | by 0x5B3391: XkbClientGone (xkb.c:7094) |
| 18 | + | by 0x4DF138: doFreeResource (resource.c:890) |
| 19 | + | by 0x4DFB50: FreeClientResources (resource.c:1156) |
| 20 | + | by 0x4A9A59: CloseDownClient (dispatch.c:3550) |
| 21 | + | by 0x5E0A53: ClientReady (connection.c:601) |
| 22 | + | by 0x5E4FEF: ospoll_wait (ospoll.c:657) |
| 23 | + | by 0x5DC834: WaitForSomething (WaitFor.c:206) |
| 24 | + | by 0x4A1BA5: Dispatch (dispatch.c:491) |
| 25 | + | by 0x4B0070: dix_main (main.c:277) |
| 26 | + | by 0x4285E7: main (stubmain.c:34) |
| 27 | + | Address 0x1893e278 is 184 bytes inside a block of size 928 free'd |
| 28 | + | at 0x4842E43: free (vg_replace_malloc.c:989) |
| 29 | + | by 0x49C1A6: CloseDevice (devices.c:1067) |
| 30 | + | by 0x49C522: CloseOneDevice (devices.c:1193) |
| 31 | + | by 0x49C6E4: RemoveDevice (devices.c:1244) |
| 32 | + | by 0x5873D4: remove_master (xichangehierarchy.c:348) |
| 33 | + | by 0x587921: ProcXIChangeHierarchy (xichangehierarchy.c:504) |
| 34 | + | by 0x579BF1: ProcIDispatch (extinit.c:390) |
| 35 | + | by 0x4A1D85: Dispatch (dispatch.c:551) |
| 36 | + | by 0x4B0070: dix_main (main.c:277) |
| 37 | + | by 0x4285E7: main (stubmain.c:34) |
| 38 | + | Block was alloc'd at |
| 39 | + | at 0x48473F3: calloc (vg_replace_malloc.c:1675) |
| 40 | + | by 0x49A118: AddInputDevice (devices.c:262) |
| 41 | + | by 0x4A0E58: AllocDevicePair (devices.c:2846) |
| 42 | + | by 0x5866EE: add_master (xichangehierarchy.c:153) |
| 43 | + | by 0x5878C2: ProcXIChangeHierarchy (xichangehierarchy.c:493) |
| 44 | + | by 0x579BF1: ProcIDispatch (extinit.c:390) |
| 45 | + | by 0x4A1D85: Dispatch (dispatch.c:551) |
| 46 | + | by 0x4B0070: dix_main (main.c:277) |
| 47 | + | by 0x4285E7: main (stubmain.c:34) |
| 48 | + |
| 49 | +To avoid that issue, make sure to free the resources when freeing the |
| 50 | +device XkbInterest data. |
| 51 | + |
| 52 | +CVE-2025-62230, ZDI-CAN-27545 |
| 53 | + |
| 54 | +This vulnerability was discovered by: |
| 55 | +Jan-Niklas Sohn working with Trend Micro Zero Day Initiative |
| 56 | + |
| 57 | +Signed-off-by: Olivier Fourdan < [email protected]> |
| 58 | +Reviewed-by: Michel Dänzer < [email protected]> |
| 59 | +Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2086> |
| 60 | +--- |
| 61 | + xkb/xkbEvents.c | 2 ++ |
| 62 | + 1 file changed, 2 insertions(+) |
| 63 | + |
| 64 | +diff --git a/xkb/xkbEvents.c b/xkb/xkbEvents.c |
| 65 | +index f8f65d4..7c669c9 100644 |
| 66 | +--- a/xkb/xkbEvents.c |
| 67 | ++++ b/xkb/xkbEvents.c |
| 68 | +@@ -1055,6 +1055,7 @@ XkbRemoveResourceClient(DevicePtr inDev, XID id) |
| 69 | + autoCtrls = interest->autoCtrls; |
| 70 | + autoValues = interest->autoCtrlValues; |
| 71 | + client = interest->client; |
| 72 | ++ FreeResource(interest->resource, RT_XKBCLIENT); |
| 73 | + free(interest); |
| 74 | + found = TRUE; |
| 75 | + } |
| 76 | +@@ -1066,6 +1067,7 @@ XkbRemoveResourceClient(DevicePtr inDev, XID id) |
| 77 | + autoCtrls = victim->autoCtrls; |
| 78 | + autoValues = victim->autoCtrlValues; |
| 79 | + client = victim->client; |
| 80 | ++ FreeResource(victim->resource, RT_XKBCLIENT); |
| 81 | + free(victim); |
| 82 | + found = TRUE; |
| 83 | + } |
| 84 | +-- |
| 85 | +2.45.4 |
| 86 | + |
| 87 | + |
| 88 | +From f6a70756f4b556a1a84792096b61bf1021ac8438 Mon Sep 17 00:00:00 2001 |
| 89 | +From: Olivier Fourdan < [email protected]> |
| 90 | +Date: Wed, 10 Sep 2025 15:55:06 +0200 |
| 91 | +Subject: [PATCH 2/2] xkb: Make the RT_XKBCLIENT resource private |
| 92 | +MIME-Version: 1.0 |
| 93 | +Content-Type: text/plain; charset=UTF-8 |
| 94 | +Content-Transfer-Encoding: 8bit |
| 95 | + |
| 96 | +Currently, the resource in only available to the xkb.c source file. |
| 97 | + |
| 98 | +In preparation for the next commit, to be able to free the resources |
| 99 | +from XkbRemoveResourceClient(), make that variable private instead. |
| 100 | + |
| 101 | +This is related to: |
| 102 | + |
| 103 | +CVE-2025-62230, ZDI-CAN-27545 |
| 104 | + |
| 105 | +This vulnerability was discovered by: |
| 106 | +Jan-Niklas Sohn working with Trend Micro Zero Day Initiative |
| 107 | + |
| 108 | +Signed-off-by: Olivier Fourdan < [email protected]> |
| 109 | +Reviewed-by: Michel Dänzer < [email protected]> |
| 110 | +(cherry picked from commit 99790a2c9205a52fbbec01f21a92c9b7f4ed1d8f) |
| 111 | + |
| 112 | +Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2087> |
| 113 | +Signed-off-by: rpm-build <rpm-build> |
| 114 | +Upstream-reference: https://gitlab.freedesktop.org/ofourdan/xserver/-/commit/10c94238bdad17c11707e0bdaaa3a9cd54c504be.patch https://gitlab.freedesktop.org/ofourdan/xserver/-/commit/865089ca70840c0f13a61df135f7b44a9782a175.patch |
| 115 | +--- |
| 116 | + include/xkbsrv.h | 2 ++ |
| 117 | + xkb/xkb.c | 2 +- |
| 118 | + 2 files changed, 3 insertions(+), 1 deletion(-) |
| 119 | + |
| 120 | +diff --git a/include/xkbsrv.h b/include/xkbsrv.h |
| 121 | +index bd74785..d801cd4 100644 |
| 122 | +--- a/include/xkbsrv.h |
| 123 | ++++ b/include/xkbsrv.h |
| 124 | +@@ -58,6 +58,8 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 125 | + #include "inputstr.h" |
| 126 | + #include "events.h" |
| 127 | + |
| 128 | ++extern RESTYPE RT_XKBCLIENT; |
| 129 | ++ |
| 130 | + typedef struct _XkbInterest { |
| 131 | + DeviceIntPtr dev; |
| 132 | + ClientPtr client; |
| 133 | +diff --git a/xkb/xkb.c b/xkb/xkb.c |
| 134 | +index ac154e2..6c102af 100644 |
| 135 | +--- a/xkb/xkb.c |
| 136 | ++++ b/xkb/xkb.c |
| 137 | +@@ -50,7 +50,7 @@ int XkbKeyboardErrorCode; |
| 138 | + CARD32 xkbDebugFlags = 0; |
| 139 | + static CARD32 xkbDebugCtrls = 0; |
| 140 | + |
| 141 | +-static RESTYPE RT_XKBCLIENT; |
| 142 | ++RESTYPE RT_XKBCLIENT = 0; |
| 143 | + |
| 144 | + /***====================================================================***/ |
| 145 | + |
| 146 | +-- |
| 147 | +2.45.4 |
| 148 | + |
0 commit comments