"ssl_receive_packet" in file "wiced_tls.c" hangs CPU (SDK 6.4 on CYW943907AEVAL1F)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ChMa_3922746
Level 5
Level 5
10 likes received 10 likes given 5 likes given

Here is a surprising finding:  With mutual TLS authentication enabled (i.e., certificate enabled on both Firefox client and WICED HTTPS server), the function ssl_receive_packet in the file wiced_tls.c has a propensity to hang the CPU unless I delay the function by 50ms if the len parameter is less than 5:

static int ssl_receive_packet( void *ctx, unsigned char **buf, size_t len )

{

    wiced_result_t result;

    wiced_tcp_socket_t* socket = ( wiced_tcp_socket_t* ) ctx;

    uint16_t available_data_length = 0;

    uint16_t length = 0;

    WPRINT_SECURITY_DEBUG (("TLS library asked for [%d] bytes \n", len ));

    // delay workaround to prevent from hanging the CPU

    if (len <= 5)

        device_wait_ms(50);

...

It used to hang almost immediately without the delay, but it seems to last longer with the delay.  The reason I found that a delay improves things is that when I enabled the debug print statements, the problem became much less severe.  Example debug print output that seemed to help (log level 0):

TLS library asked for [5] bytes

Received new TCP packet with length [427]

TLS library asked for [422] bytes

Skip [5] no of bytes from TCP received packet with length : [427]

check if multiple TLS records present in single TCP pkt

TLS library asked for [5] bytes

Skip [427] no of bytes from TCP received packet with length : [427]

wiced_packet_get_data failed with result : [4]

TLS library asked for [5] bytes

Received new TCP packet with length [395]

There must be a timing-related problem in the code.

Perhaps the dev team investigated this function in the past in this regard?

0 Likes
1 Solution

Hello,

I tried to replicate the problem with the same setup.

HTTPS server in WICED device CYW943907AEVAL1F with ThreadX/Netx-Duo stack and Firefox runnign on Linux laptop as client. I tried  to reload the server 15-20 times from the firefox browser and the system is reponding to all requests.

View solution in original post

0 Likes
4 Replies
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hello,

Can you please let me know the OS you are using? Is the issue seen during handshake or application data exchange?

It will be helpful if you can list out the steps to reproduce the issue.

Thank you very much for your reply.  I am using Firefox on Linux and connecting to an HTTPS server running on the WICED device.

I can invoke the failure most easily by rapid-firing page reloads via Firefox to the HTTPS server with a certificate mismatch.  If I keep it up, then eventually the CPU grinds to a halt and does not recover.  Have more than one HTTPS client requesting pages provokes the problem even further and more quickly.

Attached is a Wireshark capture.  The bottom-most RST is where the CPU is no longer responsive.  It seems that the CPU gets progressively bogged down by the page reloads.

My suspicion is around TLS due to the fact that adding the delay seems to help.  It could be that mbedTLS doesn't do well in the face of a barrage of incoming packets.  It would be Ok if it failed gracefully in a way that didn't freeze or force a reboot, however (in a way that could be more easily recovered).

I look forward to any advice or input you might have.  Thank you!

0 Likes

Hello,

I tried to replicate the problem with the same setup.

HTTPS server in WICED device CYW943907AEVAL1F with ThreadX/Netx-Duo stack and Firefox runnign on Linux laptop as client. I tried  to reload the server 15-20 times from the firefox browser and the system is reponding to all requests.

0 Likes

Thank you very much for trying to replicate the problem.  I think it might take more than 15-20 times.. kind of like a DOS attack   If you can get more than one client going at the same time, you will probably see the failure.  I know it isn't easy to replicate, but once you do, you will see what I mean...

0 Likes