Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Race condition in C_WaitForSlotEvent

Aperta
#3,387 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
c
Ambito
security

Direzione di ricerca

Start with reader-pcsc.c around line 1874, then trace sc_wait_for_event() and accesses to pcsc_global_private_data.pcsc_wait_ctx. Check how the context is initialized, used, and restored across concurrent C_WaitForSlotEvent calls. The issue is resolved when this shared-resource race is addressed and Coverity's reported missing-restore path is accounted for.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

reader-pcsc.c is implemented so that there is some collection of global resources that is available to all possible threads accessing the reader's context. In particular, struct pcsc_global_private_data holds a SCARDCONTEXT in pcsc_wait_ctx which is used for detecting reader events (e.g. insertion/removal of cards). Accessing this global context is typically not a problem with respect to race conditions on (de)initializing or using these global resources, because

  • minidriver performs its own separation of threads and processes
  • OpenSC's PKCS#11 layer uses sc_pkcs11_lock() to access some token (C_Initialize uses a global lock to avoid concurrency)
  • macOS uses one single process (without threads?) to access a token, which should avoid concurrency

However, there is one case in PKCS#11 that isn't covered with a lock: C_WaitForSlotEvent. Here, sc_wait_for_event() is called without being protected with a lock. This poses the risk of modifying the global ressources by different threads at the same time.

Coverity scan reports this problem at reader-pcsc.c:1874:

CID 361010: (#1 of 1): Failure to restore non-local value (MISSING_RESTORE)
42. end_of_path: Value of non-local gpriv->pcsc_wait_ctx that was verified to be -1L is not restored as it was along other paths.

The recommendation here would be to either avoid the global resources or to avoid the race conditions by, e.g. using locks.

Lingua principale
C
Stelle
3.1k
Fork
858
Merge medio
4g 4h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenSC/OpenSC

Tutte le issue di OpenSC/OpenSC

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.