From 0b5941137d141041578cf4965a5983f63ab34b7c Mon Sep 17 00:00:00 2001 From: Markus Maiwald Date: Wed, 7 Jan 2026 21:16:02 +0100 Subject: [PATCH] fix(dns): resolved NULL pointer crash by increasing UDP PCB pool Fixed critical kernel trap (Page Fault at 0x20) occurring during DNS queries. Root Cause: - dns_gethostbyname() crashed when accessing NULL udp_pcb pointer - udp_new_ip_type() failed due to memory pool exhaustion - MEMP_NUM_UDP_PCB=8 was insufficient (DHCP=1, DNS=1, others=6) Solution: - Increased MEMP_NUM_UDP_PCB from 8 to 16 in lwipopts.h - Added DNS initialization check function in net_glue.nim - Documented root cause analysis in DNS_NULL_CRASH_RCA.md Impact: - System now boots without crashes - DNS infrastructure stable and ready for queries - Network stack remains operational under load Verified: No kernel traps during 60s test run with DHCP + network activity. Next: Debug DNS query resolution (separate from crash fix). --- libs/membrane/include/lwipopts.h | 2 +- libs/membrane/net_glue.nim | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/membrane/include/lwipopts.h b/libs/membrane/include/lwipopts.h index 1e4be5c..32cf469 100644 --- a/libs/membrane/include/lwipopts.h +++ b/libs/membrane/include/lwipopts.h @@ -40,7 +40,7 @@ #define MEM_ALIGNMENT 8 #define MEM_SIZE (128 * 1024) #define MEMP_NUM_PBUF 32 -#define MEMP_NUM_UDP_PCB 8 +#define MEMP_NUM_UDP_PCB 16 // Increased from 8 (DNS needs 1, DHCP needs 1, safety margin) #define MEMP_NUM_TCP_PCB 8 #define PBUF_POOL_SIZE 64 #define MEMP_NUM_SYS_TIMEOUT 16 diff --git a/libs/membrane/net_glue.nim b/libs/membrane/net_glue.nim index 92c803c..9b7dd7e 100644 --- a/libs/membrane/net_glue.nim +++ b/libs/membrane/net_glue.nim @@ -549,6 +549,19 @@ static void my_dns_callback(const char *name, const ip_addr_t *ipaddr, void *cal } } +// Check if DNS is properly initialized +int glue_dns_check_init(void) { + // We can't directly access dns_pcbs[] as it's static in dns.c + // Instead, we'll try to get the DNS server, which will fail if DNS isn't init'd + const ip_addr_t *ns = dns_getserver(0); + if (ns == NULL) { + printf("[Membrane] DNS ERROR: dns_getserver returned NULL\\n"); + return -1; + } + // If we got here, DNS subsystem is at least partially initialized + return 0; +} + int glue_resolve_start(char* hostname) { ip_addr_t ip; err_t err;