Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Message Queue Limit to Prevent Memory Exhaustion in Embedded Devices #626

Closed
jkralik opened this issue May 15, 2024 · 0 comments · Fixed by #629
Closed

Implement Message Queue Limit to Prevent Memory Exhaustion in Embedded Devices #626

jkralik opened this issue May 15, 2024 · 0 comments · Fixed by #629
Labels
bug Something isn't working

Comments

@jkralik
Copy link
Member

jkralik commented May 15, 2024

Description

The current network thread can produce unlimited messages to the queue which is consumed by the event thread. In embedded devices, we have limited memory, so a DDOS attack could exhaust the memory.

Acceptance Criteria

  • To fix this issue, we want to use the macro OC_MAX_NUM_CONCURRENT_REQUESTS along with setting OC_DYNAMIC_ALLOCATION, which defines the maximum number of messages in the queue. The default value of OC_MAX_NUM_CONCURRENT_REQUESTS is 32 for OC_DYNAMIC_ALLOCATION.
  • If the number of messages reaches the limit, all sockets in the network thread that produce oc_message_t will be removed from select/poll.
  • If the limit is not reached, the sockets will be set back to select/poll. When more sockets are available for reading after select, one will be randomly picked, the message will be read, and then pushed to the queue.
  • Implement to ports linux / esp32 / windows.
@jkralik jkralik added the bug Something isn't working label May 15, 2024
Danielius1922 added a commit that referenced this issue Jun 20, 2024
…d Devices

The current network thread can produce unlimited messages to the queue
which is consumed by the event thread. In embedded devices, we have limited
memory, so a DDOS attack could exhaust the memory.

Fixes Issue: #626

To fix this issue, (when OC_DYNAMIC_ALLOCATION is enabled) we use the macro
OC_MAX_NUM_CONCURRENT_REQUESTS , which defines the maximum number
of messages in the queue per device.
The default value of OC_MAX_NUM_CONCURRENT_REQUESTS is 32.

If the number of messages reaches the limit, all file descriptors in the network
thread that produce oc_message_t are removed from select/poll. The file
descriptor for monitoring the control flow is always set and is used to wake up
from select() when the queue is ready to accept events again.
When more file descriptors are ready to be read than the number of available
queue slots, a subset is randomly selected to be pushed to the queue.

---------

Co-authored-by: sp-milos <[email protected]>
Co-authored-by: Daniel Adam <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant