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

[Bug]: some kind of buffer overflow in MQTT? #5136

Closed
jointerCZ opened this issue Oct 24, 2024 · 3 comments · Fixed by #5619
Closed

[Bug]: some kind of buffer overflow in MQTT? #5136

jointerCZ opened this issue Oct 24, 2024 · 3 comments · Fixed by #5619
Assignees
Labels
bug Something isn't working pinned Exclude from stale processing

Comments

@jointerCZ
Copy link

Category

Other

Hardware

T-Beam S3

Firmware Version

2.5.7

Description

Hello,
I have 2 Lilygo Supreme devices. When I configure WiFi and enable MQTT, the devices randomly reboots.
One device is very close to AP one more far away and based on logs they do not drop connection to wifi.
But I found this in the middle of the serial log, it seems it is randomly loosing connection and reconnects:
INFO | 08:08:44 863 [Router] MQTT not connected, queueing packet

ERROR | 08:08:44 863 [RadioIf] ignoring received packet due to error=-7

DEBUG | 08:08:44 863 [RadioIf] Packet received (noise?) : 170ms

INFO | 08:08:44 863 [mqtt] Using non-TLS-encrypted session

INFO | 08:08:44 863 [mqtt] Attempting to connect directly to MQTT server mqtt.meshtastic.org, port: 1883, username: meshdev, password: large4cats

INFO | 08:08:47 867 [mqtt] MQTT connected

INFO | 08:08:47 867 [mqtt] Subscribing to msh/CZ/2/e/redacted/+

INFO | 08:08:47 867 [mqtt] Subscribing to msh/CZ/2/e/PKI/+

DEBUG | 08:08:47 867 [mqtt] Publishing enqueued MQTT message

However eventually I get a panic due to buffer being full, see log.
It seems this situation is not handled well.

Can I avoid this somehow and keep MQTT? If I connect it to Linux meshtasticd and maybe process MQTT there somehow?
Or is it public server issue?

Relevant log output

INFO | 07:34:56 2085 [mqtt] Attempting to connect directly to MQTT server mqtt.meshtastic.org, port: 1883, username: meshdev, password: large4cats

INFO | 07:34:57 2086 [mqtt] MQTT connected

DEBUG | 07:34:57 2086 [mqtt] Publishing enqueued MQTT message

ERROR | 07:34:57 2086 [mqtt] Panic: can't encode protobuf reason='bytes size exceeded'
@jointerCZ jointerCZ added the bug Something isn't working label Oct 24, 2024
@jointerCZ
Copy link
Author

jointerCZ commented Oct 25, 2024

Subjective observation is that during night the device was without reboot, but now it started rebooting again.
Feels like some kind of traffic or node can be causing it (speculation).

INFO | 10:13:59 1201 [DeviceTelemetryModule] (Sending local stats): uptime=1201, channel_utilization=12.259999, air_util_tx=0.785444, num_online_nodes=43, num_total_nodes=100

INFO | 10:13:59 1201 [DeviceTelemetryModule] num_packets_tx=137, num_packets_rx=234, num_packets_rx_bad=68

DEBUG | 10:13:59 1201 [DeviceTelemetryModule] Partially randomized packet id 2424609705

ERROR | 10:13:59 1201 [RadioIf] ignoring received packet due to error=-7

DEBUG | 10:13:59 1201 [RadioIf] Packet received (noise?) : 207ms

INFO | 10:13:59 1201 [mqtt] Using non-TLS-encrypted session

INFO | 10:13:59 1201 [mqtt] Attempting to connect directly to MQTT server mqtt.meshtastic.org, port: 1883, username: meshdev, password: large4cats

INFO | 10:14:00 1202 [mqtt] MQTT connected

DEBUG | 10:14:00 1202 [mqtt] Publishing enqueued MQTT message

ERROR | 10:14:00 1202 [mqtt] Panic: can't encode protobuf reason='bytes size exceeded'

@jointerCZ
Copy link
Author

I have to confirm with 2.5.8 it still remains (as expected).

@caveman99 caveman99 added the pinned Exclude from stale processing label Oct 30, 2024
@esev
Copy link
Contributor

esev commented Dec 19, 2024

I might have spotted something related here. Looks like a potential use-after-free bug.

env->packet = (meshtastic_MeshPacket *)&mp_encrypted;

I'm not sure that type cast is safe when queuing env, and I suspect the original const meshtastic_MeshPacket &mp_encrypted reference has gone out of scope in the calling function by the time the item is pulled from the mqttQueue.

Callers:

I've been digging around in the MQTT code recently. I'll send a PR to fix. Might be a few days though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned Exclude from stale processing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants