RadioLibInterface: clear static instance on destruction to prevent UAF (#10254)
The constructor sets `RadioLibInterface::instance = this` immediately, before `init()` runs. `initLoRa()` in RadioInterface.cpp creates each radio variant with `new SX1262Interface(...)` or similar, then calls `init()`, and if init fails the `unique_ptr<RadioInterface>` is reset to nullptr — destroying the object — while the static `instance` pointer continues to point at the freed memory. Main loop then checks `RadioLibInterface::instance != nullptr` and calls `pollMissedIrqs()` or `resetAGC()` on the dangling pointer → Guru Meditation (IllegalInstruction / LoadProhibited). Reported in #9880 on an ESP32-S3 dev board without radio hardware attached, where init always fails and the leftover pointer crashes the device on the next `loop()` iteration. Fix: add a virtual destructor to `RadioLibInterface` that clears the static pointer iff it still references this object. A later successful init() may have replaced `instance` with a different interface — the `instance == this` guard preserves that case. Fixes #9880 Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
co-authored by
GitHub
Ben Meadors
parent
4c24218afb
commit
66971a0a26
@@ -136,6 +136,13 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified
|
||||
RadioLibInterface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst,
|
||||
RADIOLIB_PIN_TYPE busy, PhysicalLayer *iface = NULL);
|
||||
|
||||
/**
|
||||
* Clear the static `instance` pointer if it still points at us, so callers
|
||||
* that check `RadioLibInterface::instance != nullptr` don't dereference a
|
||||
* freed object after a failed init() + unique_ptr reset.
|
||||
*/
|
||||
virtual ~RadioLibInterface();
|
||||
|
||||
virtual ErrorCode send(meshtastic_MeshPacket *p) override;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user