Public bug reported: seahorse crashes at exit in libpcsclite when another thread is still inside an SCard*() call. The fault is in pcsc-lite, not seahorse: the library destructor (added in c94aeb5, first released in 1.9.8) frees contextMapList and destroys contextMapList_lock without synchronising with in-flight API calls. list_destroy() frees the sentinels but leaves the pointers set, so the next list_seek() walks freed memory:
#0 list_seek (simclist.c:741) #1 SCardGetContextTH (winscard_clnt.c:3445) #2 SCardGetAndLockContext (:3417) #3 SCardGetStatusChange (:1774) Error tracker: https://errors.ubuntu.com/problem/9695b2fc5c3ff60562a0a223707e523473a00c6b Signature: /usr/bin/seahorse:11:list_seek:SCardGetContextTH:SCardGetAndLockContext:SCardGetStatusChange:SCardGetStatusChange The path is seahorse -> gck -> p11-kit -> opensc C_Initialize -> SCardGetStatusChange. Quitting seahorse while the Gck thread pool is still enumerating PKCS#11 modules leaves a worker inside libpcsclite while the main thread runs ELF destructors. Scope: the destructor is present in 2.0.3 (noble), 2.4.1 (resolute), 2.5.1 (stonking/tenacious) and 2.5.4 (tenacious-proposed); 1.9.5 (jammy) does not have it. The crash was reproduced on 2.4.1, 2.5.1 and 2.5.4. Any PKCS#11 application that exits during enumeration is affected, not only seahorse. A minimal "do not free the list" fix is not sufficient: it leaves the list looking empty and reintroduces a dlopen/dlclose leak. It also turns a second path into a double free: SCardEstablishContext() racing exit reaches SCardAddContext() -> list_append() -> list_insert_at(), which frees the caller's SCONTEXTMAP even when copy_data is 0; SCardAddContext() then frees it again (glibc "double free detected in tcache 2"). Upstream: https://github.com/LudovicRousseau/PCSC/issues/271 (patch and reproducers attached there). The proposed fix clears the list in list_destroy(), only frees inserted data when copy_data is set, statically initialises contextMapList_lock, and keeps the dlclose free. Verified on 2.4.1 built from the Ubuntu source: - SCardGetStatusChange-at-exit: 20/20 SIGSEGV before, 0/20 after; - SCardEstablishContext-at-exit: minimal patch 50/50 SIGABRT, fixed 0/50; - 5000 dlopen/dlclose cycles: minimal patch +112 B/cycle, fixed flat. An SRU is being prepared for resolute (2.4.1-1ubuntu0.1). The fix should also go to tenacious, where 2.5.1-1 and 2.5.4-1 are affected. Noble is affected but not targeted here. Volume at the 2026-12-02 sync: 125 crashes/week on Ubuntu 26.04. ** Affects: pcsc-lite (Ubuntu) Importance: Undecided Status: In Progress ** Affects: pcsc-lite (Ubuntu Resolute) Importance: Undecided Status: In Progress ** Affects: pcsc-lite (Ubuntu Tenacious) Importance: Undecided Status: In Progress ** Tags: desktop-needs-sru resolute tenacious -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2190903 Title: pcsc-lite: use-after-free and double free when an SCard call races the destructor To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/pcsc-lite/+bug/2190903/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
