Skip to content

GpsGuard: range-check the GPS date and time for both NMEA and RAK12500 🤖🤖 - #3972

Open
MarkRose wants to merge 2 commits into
meshcore-dev:devfrom
MarkRose:fix/gps-date-range-checks
Open

MarkRose wants to merge 2 commits into
meshcore-dev:devfrom
MarkRose:fix/gps-date-range-checks

Conversation

@MarkRose

@MarkRose MarkRose commented Nov 27, 2026 •

Copy link
Copy Markdown

Both GPS paths turned the receiver's date and time into an epoch without checking the fields. RTClib's DateTime (NMEA) and SparkFun's getUnixEpoch() (RAK12500) both index their days-per-month tables with the month unchecked. So a bad date read past the table and could move the clock.

This adds GpsGuard::epochFromFields(): date/time fields → epoch, or 0 if any field is out of range. It's static, so it works with or without GPS_GUARD, and both providers now use it. The RAK12500 driver also waits for its first NAV-PVT before reporting a fix, because until then the library's fix flag is uninitialised.

Needs a faulty or hostile GNSS module; not reachable over the radio. Tested with host harnesses against the real MicroNMEA and SparkFun libraries; builds for RAK_4631 and Heltec_v3 (also with GPS_GUARD). Not tested on hardware.

Written with Claude (AI), reviewed by me.

🤖 Generated with Claude Code

@fdlamotte

Copy link
Copy Markdown
Collaborator

Hi,

Don't know for the RAK12500 (for which nobody dare giving me feedback wether it works or not :( ... maybe you have that answer, which would be good)

But for the plausibility of dates, this should be already be taken care of with GpsGuard, please don't add other mechanisms (if it is not in GpsGuard, get in touch with its original writer to see how we can make this better)

And please, I don't know if you're following the PR count, but the PR number are becoming unmanageable ... please try to feed things that can be managed by humans, get in touch with us if you find important things, don't let AI write PR texts are they are too long and complex to read for things that should be simple ... it's becoming tough to follow things

MarkRose and others added 2 commits November 28, 2026 16:12
MicroNMEA turns any two characters of a checksum-valid GGA/RMC time or
date field into a number, so month, day, hour, minute and second can
each be 0..255. getTimestamp() passed them to RTClib's DateTime, whose
date2days() walks its 11-entry days-per-month table up to the given
month: a read of up to 243 bytes past it. The result was then written
to the RTC. GpsGuard only sees the epoch afterwards, and only when
GPS_GUARD is enabled.

Add GpsGuard::epochFromFields(), which returns 0 for a date or time out
of range (year 2020..2099, the day checked against the month). It is
static and available with or without GPS_GUARD. The NMEA provider uses
it for its timestamp, and doesn't sync the clock, report a clock offset
or apply GPS time when the fields are out of range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
getTimestamp() called the SparkFun library's getUnixEpoch(), which
indexes its day tables with the module's year and month unchecked. Use
GpsGuard::epochFromFields() instead, which returns 0 (already treated as
"no time" by RakLocationProvider) for an implausible date.

hasFix() returned the library's fix flag before any NAV-PVT had
arrived. The library doesn't clear that record, so until the first
reply the flag, position and date were whatever was on the heap. Wait
for the first NAV-PVT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MarkRose

Copy link
Copy Markdown
Author

Hi,

Don't know for the RAK12500 (for which nobody dare giving me feedback wether it works or not :( ... maybe you have that answer, which would be good)

But for the plausibility of dates, this should be already be taken care of with GpsGuard, please don't add other mechanisms (if it is not in GpsGuard, get in touch with its original writer to see how we can make this better)

And please, I don't know if you're following the PR count, but the PR number are becoming unmanageable ... please try to feed things that can be managed by humans, get in touch with us if you find important things, don't let AI write PR texts are they are too long and complex to read for things that should be simple ... it's becoming tough to follow things

Hello!

Unfortunately I don't have a RAK12500, but I may buy or borrow one. I'll ask around. That said, I am a MeshCore user and repeater operator in Edmonton. As such, I thought it would be interesting and useful to have Mythos look for vulnerabilities in MeshCore. I've submitted a few issues privately. Along the way numerous other bugs were discovered and I thought it useful to open up PRs to fix them. This was one of them.

GpsGuard doesn't appear to cover this particular case:

I'll rework this PR so that GpsGuard can be used here, too.

I'll hold back on opening fix PRs for the 13 other identified issues/improvements:

Ready as small fixes (one commit each):

  1. ESPAsyncWebServer 3.10.3: it has two published CVEs in its OTA upload parser, a NULL write and an endless loop. Bumping to 3.12.1 fixes both.
  2. T1000-E battery temperature: the NTC lookup table is indexed out of range when the ADC reads 0.
  3. TFT displays: CP437 block characters draw nothing.
  4. RTC drivers: an invalid date from the clock chip reads past RTClib's month table. This overlaps with open Read and write the RV3028 clock atomically, and reject switchover-garbled transfers 🤖🤖 #3421.
  5. ESP-NOW bridge: received frames longer than a packet aren't checked before use. This overlaps with the stale PR Synchronize ESPNOWRadio RX frame handoff #2061.
  6. RAK12035 soil sensor: equal calibration values cause a division that turns into NaN. This is marginal.

Routing (low impact):

  1. Shared rate limits: the repeater's anonymous-request and discovery limits are one global counter, so anyone can use up the window for everyone.
  2. Unknown payload types: direct routing relays any payload type, including undefined ones, if the first path hash matches.

Reliability:

  1. Radio state flag: the radio interrupt and the main loop update state without masking interrupts, so an event (a received frame or "send complete") is occasionally lost.
  2. nRF52 BLE queues: these are updated from the BLE callback and the main loop without a lock, so a frame is occasionally lost, duplicated or mixed.

Build and release:

  1. Floating dependencies: many lib_deps, including the Crypto library, and the nRF52 platform aren't pinned to exact versions.
  2. Release workflows: the build jobs get a contents: write token, and third-party actions are pinned by tag.
  3. Checksums: release assets have no checksums.

-Mark

@MarkRose
MarkRose force-pushed the fix/gps-date-range-checks branch from ad59496 to 5879802 Compare November 28, 2026 22:29
@MarkRose

Copy link
Copy Markdown
Author

@AlexandrTyshchenko This PR modifies code you wrote. Do you have any concerns or comments?

@MarkRose MarkRose changed the title Range-check GPS date and time before using them 🤖🤖 GpsGuard: range-check the GPS date and time for both NMEA and RAK12500 🤖🤖 Nov 28, 2026
@AlexandrTyshchenko

Copy link
Copy Markdown

Thanks for the ping, no objections. The issue is real: the guard only sees the epoch after DateTime is built, so an out-of-range month has already read past RTClib's table by then, and without GPS_GUARD nothing checks it at all.

Having the field check as a static helper in GpsGuard (as you did) keeps date plausibility in one place and works without GPS_GUARD, so I'm fine with this approach.

I don't have a RAK12500 either. I can test the NMEA path on my board (u-blox M10 over UART, GPS_GUARD on) once the rework is pushed.

@MarkRose

Copy link
Copy Markdown
Author

Already pushed. You saw the pushed code.

@fdlamotte

Copy link
Copy Markdown
Collaborator

I like this one much better ...

Thanks for considering my comments

For rak_12500, if someone can lend you one, it would be great ... I have no other option here than to import one and from rokland they don't come cheap (now they are eol and sadly it's too much for my current situation)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants