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
runtime: Use MAP_FIXED flag to ensure buffer halves are contiguous #6854
Conversation
Looking at the man page, I wonder if
Is a little worrying in the case of a race. But ... there is some text later on in the man page that says |
|
@marcusmueller @mormj This fix seem simple enough, but the code predates 3.7, isn't tested by CI, so another opinion would be good. |
Out of curiosity, I had a look back and the original pspectra / GNU Radio 0.9 code used the |
From https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html:
This makes me wonder whether the explicit |
The spec goes on to say some worrying things about
|
GNU Radio's test suite can be executed using the three non-Windows circular buffer implementations like so:
All tests pass on this branch, and they continue to do so if I remove the |
Also, remove the munmap calls, since mmap with the MAP_FIXED flag automatically unmaps overlapping regions. Finally, remove a contiguity check which becomes unnecessary thanks to MAP_FIXED. Signed-off-by: Clayton Smith <argilo@gmail.com>
I've removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, MAP_FIXED is the right thing to do here. Still wondering why it wasn't there in the first place. Not quite sure we even need the MAP_SHARED
, but that's a story for a different day.
that's some serious history digging there :) |
@argilo When you're ready, I'll put this on |
It was removed in 2005, but that broke NetBSD: https://lists.gnu.org/archive/html/discuss-gnuradio/2005-10/msg00074.html After some discussion on the mailing list, it was eventually added back: https://lists.gnu.org/archive/html/discuss-gnuradio/2005-10/msg00109.html Whether NetBSD still requires |
In gqrx-sdr/gqrx#1275 (comment), I asked @martymac to take this for a spin on FreeBSD, so we may as well wait a day or two to see how that goes. |
I took this for a spin myself on FreeBSD (by applying the patch to the GNU Radio 3.8.4.0 port), and both stand-alone GNU Radio flow graphs and Gqrx now run without issue, even with ASLR enabled. |
Good, then let's merge this to I've noticed that the
|
Thanks a lot for your investigations, Clayton and Jeff! Sorry for lagging (ENOTIME at the moment). I'll test the patch and tell you how it goes (but it seems it now goes well on FreeBSD :)). |
It appears NetBSD has had |
Then you're probably the first person to test the tmp method in years. And it still worked ... they don't make code like they used to 😄 |
Well, it did better than the |
Hello, I can confirm that Gqrx works perfectly well (even with ASLR) with your patch! Thanks again for your help! |
This patch is a backport of ca44241 from upstream: runtime: Use MAP_FIXED flag to ensure buffer halves are contiguous It fixes SIGSEGV observed with GNU Radio buffers consumers such as comms/gqrx. Discussed here: gqrx-sdr/gqrx#1275 gnuradio/gnuradio#6854 PR: 272543 Reported by: trasz Obtained from: GNU Radio team (GH pull request: 6854) MFH: 2023Q3
This patch is a backport of ca44241 from upstream: runtime: Use MAP_FIXED flag to ensure buffer halves are contiguous It fixes SIGSEGV observed with GNU Radio buffers consumers such as comms/gqrx. Discussed here: gqrx-sdr/gqrx#1275 gnuradio/gnuradio#6854 PR: 272543 Reported by: trasz Obtained from: GNU Radio team (GH pull request: 6854) MFH: 2023Q3 (cherry picked from commit 35f7383)
Description
It was recently reported that Gqrx crashes on FreeBSD:
gqrx-sdr/gqrx#1275
After some digging, I found that the crash occurs because
vmcircbuf_mmap_shm_open::vmcircbuf_mmap_shm_open
allocates a discontiguous double-mapped buffer. This happens because themmap
system call is free to ignore the suppliedaddr
argument (which is only a suggestion) and choose its own address for the mapping.This can be fixed by using the
MAP_FIXED
flag, which tellsmmap
that theaddr
argument must be used as-is.The
vmcircbuf_mmap_tmpfile
implementation has an explicit contiguity check (which simply throws an exception if the returned buffer is discontiguous). With the addition of theMAP_FIXED
flag, I don't think this check is necessary.Related Issue
Which blocks/areas does this affect?
Circular Buffers
Testing Done
To test the
mmap
-based circular buffer implementations, run the following:echo -n gr::vmcircbuf_mmap_shm_open_factory > ~/.gnuradio/prefs/vmcircbuf_default_factory
OR
echo -n gr::vmcircbuf_mmap_tmpfile_factory > ~/.gnuradio/prefs/vmcircbuf_default_factory
Before this change,
gr::vmcircbuf_mmap_shm_open_factory
works fine on Linux, butgr::vmcircbuf_mmap_tmpfile_factory
fails immediately with the following error:After the change, Gqrx runs fine with both implementations.
Checklist
I have updated the documentation where necessary.I have added tests to cover my changes,and all previous tests pass.