ktls/af_ktls

Race condition in KTLS_RECV_READY

Closed this issue · 2 comments

The KTLS_RECV_READY macro is used to check whether or not the aead has been set up for decryption, however, it merely checks that the keys are set, when tls_init_aead is called after keys are set, so an interrupt that checks KTLS_RECV_READY(such as tls_data_ready) that occurs between settings keys and initializing aead would cause a crash.

3 options:

  1. Acquire the socket lock during decryption so that settings keys and initializing aead occurs atomically, which means that decryption cannot happen in a irqroutine like tls_data_ready.
  2. Use an atomic flag that is set after key setup.
  3. Set keys before changing the sk_data_ready callback

Nice catch! IMHO I like 3) the most.

Closed. Fixed in #73 , which makes sure that lock_sock is always called prior to checking KTLS_RECV_READY