Use after free in FreeRDP WinPR linked list enumerator
Key facts
- Attack vector
- Local
- Privileges required
- None
- User interaction
- None
- Attack complexity
- High
- Impact type
- —
- Confidentiality · integrity · availability
- Low · None · Low
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-76c4-7552-ffhv. Fix status from GitHub.
Summary
FreeRDP up to and including 3.33.0 contains a use after free flaw in the WinPR linked list enumerator (CWE-416). The enumerator keeps a pointer to a list node after that node is removed, so a later move or read touches freed memory. A local attacker with no privileges and no user interaction can read freed memory, though the attack complexity is high. The impact is low confidentiality and low availability.
Written with Claude Haiku 5.5 from the sources below · 2026-11-16
Description from the GitHub advisory
### Summary The enumerator built into `wLinkedList` (WinPR collections) can keep a pointer to a list node after that node has been freed. `LinkedList_Enumerator_Reset()` stores the current head node in `list->current`, and none of the functions that remove nodes update `list->current`. If the node it points to is removed, the next `LinkedList_Enumerator_MoveNext()` or `LinkedList_Enumerator_Current()` reads freed memory. ASan reports a heap-use-after-free READ of size 8. Tested on the 3.32.1 release (bf217a504e54) and on master 6acacf1f8d4b (2026-10-19). `winpr/libwinpr/utils/collections/LinkedList.c` is identical in 3.32.2 and in current master (59f5458d116a), and `Reset` has cached the head node like this since the list was added in 2013. Whether this is a bug or a misuse of the API is for you to decide; see "Bug or misuse?" below. ### Details `winpr/libwinpr/utils/collections/LinkedList.c` (excerpt; the comments are mine): ```c void LinkedList_Enumerator_Reset(wLinkedList* list) { WINPR_ASSERT(list); list->initial = 1; list->current = list->head; /* caches the head node */ } BOOL LinkedList_Enumerator_MoveNext(wLinkedList* list) { WINPR_ASSERT(list); if (list->initial) list->initial = 0; /* first call: no dereference, only the NULL check below */ else if (list->current) list->current = list->current->next; if (!list->current) return FALSE; return TRUE; } ``` `LinkedList_FreeNode()`, used by `LinkedList_Remove()`, `LinkedList_RemoveFirst()`, `LinkedList_RemoveLast()` and `LinkedList_Clear()`, updates `head`, `tail`, the neighbouring nodes and `count` and frees the node, but does not touch `list->current`. Two call sequences reach the freed node: 1. `Reset`, then remove the first element (the reproducer adds the same value back, which creates a new node), then `MoveNext` and `Current`. `MoveNext` only clears `initial` and sees a non-NULL `current`, so it returns TRUE; `Current` then reads `current->value` from the freed node. 2. `Reset` and `MoveNext`, then remove the current element, then `MoveNext` again, which reads `current->next` from the freed node. ### Reproducer Public API only (`poc.c`): ```c #include <stdio.h> #include <winpr/collections.h> static int a = 1; static int b = 2; int main(int argc, char* argv[]) { (void)argv; wLinkedList* list = LinkedList_New(); if (!list || !LinkedList_AddLast(list, &a) || !LinkedList_AddLast(list, &b)) return 1; LinkedList_Enumerator_Reset(list); if (argc > 1) { /* case 2: remove the current element during the enumeration */ if (!LinkedList_Enumerator_MoveNext(list)) return 1; if (!LinkedList_Remove(list, LinkedList_Enumerator_Current(list))) return 1; } else { /* case 1: after Reset, remove the first element and add the same value again */ void* first = LinkedList_First(list); LinkedList_RemoveFirst(list); if (!LinkedList_AddFirst(list, first)) return 1; } while (LinkedList_Enumerator_MoveNext(list)) { const int* v = LinkedList_Enumerator_Current(list); printf("%d\n", v ? *v : -1); } LinkedList_Free(list); return 0; } ``` Build from a FreeRDP checkout (clang; the `-DWITH_*=OFF` options only drop optional dependencies that WinPR does not need): ```sh cmake -S . -B build-asan -G Ninja -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \ "-DCMAKE_C_FLAGS=-fsanitize=address -fno-omit-frame-pointer" \ -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address -DCMAKE_SHARED_LINKER_FLAGS=-fsanitize=address \ -DWITH_CLIENT=OFF -DWITH_SERVER=OFF -DWITH_FFMPEG=OFF -DWITH_SWSCALE=OFF -DWITH_UNICODE_BUILTIN=ON \ -DWITH_CUPS=OFF -DWITH_PULSE=OFF -DWITH_ALSA=OFF -DWITH_OSS=OFF -DWITH_X11=OFF -DWITH_FUSE=OFF \ -DWITH_OPUS=OFF -DCHANNEL_URBDRC=OFF -DWITH_SYSTEMD=OFF cmake --build build-asan --target winpr clang -g -fsanitize=address -Iwinpr/include -Ibuild-asan/winpr/include poc.c \ -Lbuild-asan/winpr/libwinpr -lwinpr3 -Wl,-rpath,$PWD/build-asan/winpr/libwinpr -o poc ./poc # case 1 ./poc x # case 2 ``` Case 1 (master 6acacf1f8d4b, ASan output trimmed): ``` ERROR: AddressSanitizer: heap-use-after-free READ of size 8 thread T0 #0 in LinkedList_Enumerator_Current winpr/libwinpr/utils/collections/LinkedList.c:326 #1 in main poc.c:34 freed by thread T0 here: #0 in free #1 in LinkedList_FreeNode winpr/libwinpr/utils/collections/LinkedList.c:150 #2 in LinkedList_RemoveFirst winpr/libwinpr/utils/collections/LinkedList.c:290 #3 in main poc.c:27 previously allocated by thread T0 here: #0 in calloc #1 in LinkedList_Create winpr/libwinpr/utils/collections/LinkedList.c:180 #2 in LinkedList_AddLast winpr/libwinpr/utils/collections/LinkedList.c:235 #3 in main poc.c:11 ``` Case 2: ``` ERROR: AddressSanitizer: heap-use-after-free READ of size 8 thread T0 #0 in LinkedList_Enumerator_MoveNext winpr/libwinpr/utils/collections/LinkedList.c:341 #1 in main poc.c:32 freed by thread T0 here: #0 in free #1 in LinkedList_FreeNode winpr/libwinpr/utils/collections/LinkedList.c:150 #2 in LinkedList_Remove winpr/libwinpr/utils/collections/LinkedList.c:272 #3 in main poc.c:20 previously allocated by thread T0 here: #0 in calloc #1 in LinkedList_Create winpr/libwinpr/utils/collections/LinkedList.c:180 #2 in LinkedList_AddLast winpr/libwinpr/utils/collections/LinkedList.c:235 #3 in main poc.c:11 ``` The same happens on 3.32.1. ### Suggested fix ```diff --- a/winpr/libwinpr/utils/collections/LinkedList.c +++ b/winpr/libwinpr/utils/collections/LinkedList.c @@ -141,6 +141,14 @@ if (node == list->tail) list->tail = node->prev; + if (node == list->current) + { + /* Never leave the enumerator on a freed node: the next MoveNext continues after the removed node. */ + list->current = prev; + if (!prev) + list->initial = 1; + } + if (list->object.fnObjectUninit) list->object.fnObjectUninit(node); @@ -309,7 +317,7 @@ { WINPR_ASSERT(list); list->initial = 1; - list->current = list->head; + list->current = nullptr; } /* @@ -336,7 +344,10 @@ { WINPR_ASSERT(list); if (list->initial) + { list->initial = 0; + list->current = list->head; + } else if (list->current) list->current = list->current->next; ``` - `Reset` no longer caches the head; `MoveNext` reads `list->head` when the enumeration starts. - When `LinkedList_FreeNode()` frees the node the enumerator points at, the enumerator moves back to the previous node, or to the "not started" state if there is none, so the next `MoveNext` continues with the element after the removed one. - With the patch, `./poc` prints `1 2` and `./poc x` prints `2`, without ASan reports. - The usual pattern (`Reset`, then `while (MoveNext) Current`, without changing the list inside the loop) behaves as before. The existing `TestLinkedList` passes unchanged, and the one enumerator loop in `libfreerdp/utils/smartcard_call.c` follows that pattern. Separate and optional: a list returned by `LinkedList_New()` has `initial == 0` and `current == NULL`, so `MoveNext` returns FALSE until `Reset` has been called. In the .NET model, a new enumerator starts before the first element. Setting `list->initial = 1` in `LinkedList_New()` would make a new list behave like one after `Reset`. The memory-safety fix does not need this. ### Regression test ```diff diff --git a/winpr/libwinpr/utils/test/CMakeLists.txt b/winpr/libwinpr/utils/test/CMakeLists.txt index 8a9f99b..f15e054 100644 --- a/winpr/libwinpr/utils/test/CMakeLists.txt +++ b/winpr/libwinpr/utils/test/CMakeLists.txt @@ -18,6 +18,7 @@ set(${MODULE_PREFIX}_TESTS TestBitStream.c TestArrayList.c TestLinkedList.c + TestLinkedListEnumerator.c TestListDictionary.c TestCmdLine.c TestASN1.c diff --git a/winpr/libwinpr/utils/test/TestLinkedListEnumerator.c b/winpr/libwinpr/utils/test/TestLinkedListEnumerator.c new file mode 100644 index 0000000..f7cfe64 --- /dev/null +++ b/winpr/libwinpr/utils/test/TestLinkedListEnumerator.c @@ -0,0 +1,106 @@ +/* Regression test: the enumerator must not keep a pointer to a node the list has freed. */ +#include <winpr/crt.h> +#include <winpr/collections.h> + +static BOOL test_modify_between_reset_and_movenext(void) +{ + BOOL rc = FALSE; + wLinkedList* list = LinkedList_New(); + if (!list) + return FALSE; + if (!LinkedList_AddLast(list, (void*)(size_t)1) || !LinkedList_AddLast(list, (void*)(size_t)2)) + goto out; + + LinkedList_Enumerator_Reset(list); + /* remove the first element and add the same value again: a new node at the head */ + void* first = LinkedList_First(list); + LinkedList_RemoveFirst(list); + if (!LinkedList_AddFirst(list, first)) + goto out; + + if (!LinkedList_Enumerator_MoveNext(list)) + goto out; + if (LinkedList_Enumerator_Current(list) != (void*)(size_t)1) + goto out; + if (!LinkedList_Enumerator_MoveNext(list)) + goto out; + if (LinkedList_Enumerator_Current(list) != (void*)(size_t)2) + goto out; + if (LinkedList_Enumerator_MoveNext(list)) + goto out; + rc = TRUE; +out: + LinkedList_Free(list); + return rc; +} + +static BOOL test_remove_current_during_enumeration(void) +{ + BOOL rc = FALSE; + size_t seen = 0; + wLinkedList* list = LinkedList_New(); + if (!list) + return FALSE; + for (size_t i = 1; i <= 3; i++) + { + if (!LinkedList_AddLast(list, (void*)i)) + goto out; + } + + /* remove every element while it is the current one; the enumeration still visits all of them */ + LinkedList_Enumerator_Reset(list); + while (LinkedList_Enumerator_MoveNext(list) && seen < 8) + { + void* v = LinkedList_Enumerator_Current(list); + if (v != (void*)(seen + 1)) + goto out; + if (!LinkedList_Remove(list, v)) + goto out; + seen++; + } + if (seen != 3 || LinkedList_Count(list) != 0) + goto out; + + /* removing the current element in the middle continues with the element after it */ + for (size_t i = 6; i <= 8; i++) + { + if (!LinkedList_AddLast(list, (void*)i)) + goto out; + } + LinkedList_Enumerator_Reset(list); + if (!LinkedList_Enumerator_MoveNext(list) || !LinkedList_Enumerator_MoveNext(list)) + goto out; + if (!LinkedList_Remove(list, (void*)(size_t)7)) + goto out; + if (!LinkedList_Enumerator_MoveNext(list) || LinkedList_Enumerator_Current(list) != (void*)(size_t)8) + goto out; + if (LinkedList_Enumerator_MoveNext(list)) + goto out; + LinkedList_Clear(list); + + /* clearing the list in the middle of an enumeration ends it */ + if (!LinkedList_AddLast(list, (void*)(size_t)4) || !LinkedList_AddLast(list, (void*)(size_t)5)) + goto out; + LinkedList_Enumerator_Reset(list); + if (!LinkedList_Enumerator_MoveNext(list)) + goto out; + LinkedList_Clear(list); + if (LinkedList_Enumerator_MoveNext(list)) + goto out; + rc = TRUE; +out: + LinkedList_Free(list); + return rc; +} + +int TestLinkedListEnumerator(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!test_modify_between_reset_and_movenext()) + return -1; + if (!test_remove_current_during_enumeration()) + return -2; + return 0; +} ``` On master 6acacf1f8d4b, configured as above plus `-DBUILD_TESTING=ON`, `ctest -R TestLinkedList` fails `TestLinkedListEnumerator` with the heap-use-after-free above when only the test is applied. With the fix as well, `TestLinkedList` and `TestLinkedListEnumerator` both pass. ### Bug or misuse? - `collections.h` names the type after `System.Collections.Generic.LinkedList<T>`. In .NET, changing the collection invalidates its enumerator, and the next `MoveNext` throws `InvalidOperationException`. By that model, both sequences above are invalid usage. - WinPR's own documentation (the comments in `collections.h`) does not say that changing the list invalidates the enumerator, or that `Reset` has to be called again afterwards. Nothing detects it either, so the result is a read of freed memory instead of an error. - Could you decide whether you treat this as a bug or as a misuse of the API? If it is misuse, please consider the patch, or a note in `collections.h`, as hardening. ### Severity CVSS 3.1: `CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:L` (4.0). It is a read of freed memory (a pointer-sized field); no write was observed. It happens only when the calling code removes the element the enumerator points at: the first element after `Reset`, or the current element during an enumeration. The .NET model treats both as invalid. I have not looked into exploitability; please adjust the score if you see it differently. ### Credit I found this during research that is not published yet. Please credit: Pu Cheng
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | FreeRDP (c) | <= 3.33.0 | 3.33.1 | Patch available | GHSA-76c4-7552-ffhv |
- FreeRDP (c) Vendor— Affected <= 3.33.0 Fixed in 3.33.1 Patch available GHSA-76c4-7552-ffhv
Remediation
Update FreeRDP to version 3.33.1, which fixes the flaw.
Written with Claude Haiku 5.5 from the sources below · 2026-11-16
- Fix · GHSA-76c4-7552-ffhv FreeRDP (c) Fixed in 3.33.1 Advisory →
Timeline
- 2026-11-16 Threatist record created from GHSA-76c4-7552-ffhv
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences