Tech Implementing a Custom Memory Allocator for Embedded Systems

Today I want to share my experience implementing a custom memory allocator for a resource-constrained embedded system. When working with devices that have limited RAM, the standard malloc/free implementations are often too heavy and inefficient.

The key requirements were:

  • Deterministic allocation times
  • Low fragmentation
  • Small memory overhead

Here's the core implementation of the block allocation strategy:

typedef struct block_meta {
    size_t size;
    struct block_meta *next;
    int free;
} block_meta_t;

#define META_SIZE sizeof(block_meta_t)

static block_meta_t *global_base = NULL;

// Find a free block of sufficient size
block_meta_t *find_free_block(block_meta_t **last, size_t size) {
    block_meta_t *current = global_base;
    while (current && !(current->free && current->size >= size)) {
        *last = current;
        current = current->next;
    }
    return current;
}

The main challenge was handling fragmentation efficiently while maintaining real-time constraints. I ended up implementing a hybrid approach using fixed-size blocks for common allocations and a more dynamic approach for larger requests.

Read more...
Security Exploiting UART Debug Ports in Embedded Devices

I recently explored hardware security techniques involving exposed UART debug ports on IoT devices. Here's what I discovered about gaining shell access through these debug interfaces:

First, I identified the UART pins on the PCB using a logic analyzer:

$ sudo minicom -D /dev/ttyUSB0 -b 115200
Welcome to Debug Console v1.2
Username: admin
Password: ********
Authentication failed.

After analyzing the boot sequence, I discovered a timing vulnerability in the authentication routine that could be exploited to bypass security measures entirely.

Read more...
Troubleshoot Solving the "Disappearing Network Interfaces After Suspend" Issue on Linux

I've been struggling with a frustrating issue on my Linux laptop where network interfaces would occasionally disappear after resuming from suspend. After much debugging, I finally found the root cause and solution.

The Problem:

After resuming from suspend, both WiFi and Ethernet interfaces would be missing. Running ip link would show no network devices except for loopback. This made the laptop essentially unusable until a full reboot was performed.

Through careful investigation of system logs and kernel behavior, I discovered that this was related to power management issues with the specific network hardware in my laptop.

Read more...