Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 871 of 93612. IoT Connectivity and SecurityFree lesson

Protecting Against Network-Based Denial of Service

Apply rate limiting and input validation techniques to harden the network stack against common resource-exhaustion attacks targeting embedded connectivity.

In this lesson, you will learn how to harden your embedded network stack against resource-exhaustion attacks by implementing rate limiting and rigorous input validation.

The Anatomy of Resource Exhaustion

In resource-constrained embedded systems, the most common Denial of Service (DoS) attack is a "resource exhaustion" event. Because your device likely has limited RAM and a fixed number of available file descriptors or network buffers (often allocated statically as discussed in earlier lessons), an attacker can crash your system by sending a flood of malformed packets or opening too many concurrent connections.

Implementing Rate Limiting

Rate limiting acts as a throttle on the incoming traffic pipeline. Instead of allowing every packet to trigger a process or kernel callback, you implement a "token bucket" algorithm or a simple counter within your network driver or application logic. If a specific source exceeds the allowed packets-per-second, the system drops the traffic at the earliest possible stage—ideally before the packet is passed up the stack to higher-level protocols.

// Simplified rate limiting logic
static int handle_packet(struct packet *p) {
    if (get_packet_rate(p->source_ip) > MAX_RATE_THRESHOLD) {
        drop_packet(p); // Discard to protect system resources
        return -1;
    }
    // Proceed to process...
}

Rigorous Input Validation

Many DoS attacks leverage malformed headers to trigger buffer overflows or recursive logic errors in the TCP/IP stack. Your implementation must treat every field in an incoming frame as untrusted.

  1. Size Constraints: Always validate length fields against the static buffer sizes configured during your LwIP setup. If a packet claims to be larger than your pre-allocated memory pools, reject it immediately.
  2. State Machine Integrity: When managing connections, ensure that incoming control packets (like TCP SYN or FIN flags) only trigger state changes that are logically valid for the current socket status. This prevents an attacker from exhausting your connection table with "half-open" requests.

By validating input at the hardware abstraction layer and throttling throughput, you ensure that the system remains responsive to legitimate commands even under heavy network pressure.

Key Takeaway: Protecting against DoS in embedded systems requires early-stage packet filtering and strictly enforced memory constraints to ensure that unexpected traffic cannot overwhelm your static resource allocation.