Skip to content

Linux+SITL: Fix risk of wrong prng return - #34257

Open
rsaxvc wants to merge 2 commits into
ArduPilot:masterfrom
rsaxvc:fixEarlyPrngReturn
Open

Linux+SITL: Fix risk of wrong prng return#34257
rsaxvc wants to merge 2 commits into
ArduPilot:masterfrom
rsaxvc:fixEarlyPrngReturn

Conversation

@rsaxvc

@rsaxvc rsaxvc commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Return false from get_random_vals() if it fails to fully populate the destination buffer.

Classification & Testing (check all that apply and add your own)

  • Checked by a human programmer
  • Non-functional change
  • No-binary change
  • Infrastructure change (e.g. unit tests, helper scripts)
  • Automated test(s) verify changes (e.g. unit test, autotest)
  • Tested manually, description below (e.g. SITL)
  • Tested on hardware
  • Logs attached
  • Logs available on request

Testing steps:

  1. instrumented existing implementation
  2. used existing implementation to read random numbers into a 1MB array in a loop with a no-op SIGINT handler while mashing control-C
  3. Confirmed signals can cause read() to return short reads(positive return code but less than specified size), but get_random_vals() returned true.
  4. Fixed it.
  5. Verified return code is now false under the above signal interruption.

Description

Fix a footgun in get_random_vals() when read() returns early due to a signal handler(as may happen during ArduPilot shutdown on SITL or Linux). Some systems will read blocks of 4096B at a time, though the manual states early returns may occur as small as 256B. I couldn't find any mainline ArduPilot code that read()s a large enough buffer to trigger this.

Treat an early return of read(/dev/urandom) as a failure.
Treat an early return of read(/dev/urandom) as a failure.
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.

1 participant