ktls / af_ktls

Linux Kernel TLS/DTLS Module
GNU General Public License v2.0
157 stars 25 forks source link

Race condition in KTLS_RECV_READY #71

Closed lancerchao closed 8 years ago

lancerchao commented 8 years ago

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

fridex commented 8 years ago

Nice catch! IMHO I like 3) the most.

lancerchao commented 8 years ago

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