Probably memory leak on handshake when KTLS enabled

Xinzhe Wang matrixwxz at
Fri Jun 12 04:01:53 UTC 2020

When KTLS is enabled, multiple client's handshake will lead to unexpected
eof while reading and data corrupt(possible memory leak).

Tested OpenSSL version: master, 3.0.0-alpha1
Kernel version: 5.4.43-1-MANJARO
Reproduce step(using docker):

sudo modprobe tls
git clone
sudo docker run -it -v $(pwd)/openssl:/openssl archlinux

# [In docker]
pacman -Sy make gcc vim
cd openssl
./config enable-ktls
make build_sw -j4
pacman -Rdd openssl
make install_sw

cd /
vim server.cpp
vim client.cpp
vim server.pem
vim serverkey.pem

g++ -c -o client.o client.cpp
g++ -o client client.o -lssl -lcrypto
g++ -c -o server.o server.cpp
g++ -o server server.o -lssl -lcrypto
export LD_LIBRARY_PATH=/usr/local/lib
./server &

You will see like this

 Vtest test
Mljtest test
Error creating SSL connection.  err=ffffffff
error:14000126:SSL routines::unexpected eof while reading

When OpenSSL is compiled without ktls, the client will print test
infinitely, but when enable ktls, some data are corrupted and sometimes
result in unexpected eof while reading.

Even when you remove SSL_write(ssl, reply, strlen(reply)); in server and
RecvPacket(); in client, it will also result in unexpected eof while
reading so I think there is something wrong with handshake procedure when
ktls is enabled, maybe memory leak or UAF.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the openssl-users mailing list