LWN: Comments on "Suppressing SIGBUS signals" https://lwn.net/Articles/860419/ This is a special feed containing comments posted to the individual LWN article titled "Suppressing SIGBUS signals". en-us Wed, 15 Oct 2025 22:02:54 +0000 Wed, 15 Oct 2025 22:02:54 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Suppressing SIGBUS signals https://lwn.net/Articles/861995/ https://lwn.net/Articles/861995/ ssmith32 <div class="FormattedComment"> Yes, I imagine redundancy would be a better solution. Better to have the fly-by-wire fail over to a backup, then try to limp along in some weird state.<br> <p> Of course, time and again, cost-cutting works against that, and you have cars that share data buses between control systems &amp; the entertainment system :(<br> </div> Wed, 07 Jul 2021 06:48:18 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861838/ https://lwn.net/Articles/861838/ immibis <div class="FormattedComment"> I&#x27;m sure there are many ways to bring things down if you can arbitrarily truncate files I&#x27;m using.<br> </div> Mon, 05 Jul 2021 08:54:51 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861708/ https://lwn.net/Articles/861708/ daniels <div class="FormattedComment"> <font class="QuotedText">&gt; Create and open a file on tmpfs, in directory not accessible to anyone else. mmap() it. Pass the descriptor over SCM_RIGHTS datagram. And unlink() the damn thing, to keep the clutter down.</font><br> <p> That’s literally what we do, yeah.<br> </div> Fri, 02 Jul 2021 19:28:32 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861484/ https://lwn.net/Articles/861484/ ilammy <div class="FormattedComment"> After doing some research, this idea is implemented in some systems as a MAP_COPY flag for mmap() [1]. That&#x27;s basically the semantics of MAP_PRIVATE mapping, but with a “snapshot” guarantee that the data won&#x27;t change, making your copy genuinely private, but avoiding the actual copy if the data does not change.<br> <p> While thinking of how this could be implemented, I realized that it could be quite expensive, complicated, and full of “spooky action at a distance”. If some process grabs or released a MAP_COPY mapping of a file, then all existing processes must be made aware of it (e.g., by turning all mappings for everyone RO and catching page faults). Any change by the other process forces said process to expend some kernel time doing the copy of the page for the benefit of some other process, which is not particularly fair.<br> <p> Turns out, adding MAP_COPY into Linux was discussed several times [2][3], but it&#x27;s still considered a pretty stupid idea.<br> <p> [1]: <a href="https://www.gnu.org/software/hurd/glibc/mmap.html">https://www.gnu.org/software/hurd/glibc/mmap.html</a><br> [2]: <a href="https://yarchive.net/comp/linux/map_copy.html">https://yarchive.net/comp/linux/map_copy.html</a><br> [3]: <a href="https://www.spinics.net/lists/linux-mm/msg119339.html">https://www.spinics.net/lists/linux-mm/msg119339.html</a><br> </div> Thu, 01 Jul 2021 02:16:43 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861445/ https://lwn.net/Articles/861445/ mathstuf <div class="FormattedComment"> I&#x27;ve said this elsewhere, but &quot;safe&quot; is a lot like security: it depends on your environment (threat model in security). I don&#x27;t care much about cosmic rays flipping bits (in the &quot;I should consider this case&quot; sense) and count that as outside of the safety model of my code. NASA can&#x27;t work with such reckless abandon and have *far* higher concerns about such things. But languages don&#x27;t save you there: redundancy does.<br> <p> Aircraft have similarly high standards and I imagine the solution there is along the lines of rip out (or somehow poison) the `panic` function and let the linker tell you that you have a case that isn&#x27;t *explicitly* handled.<br> </div> Wed, 30 Jun 2021 18:03:24 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861444/ https://lwn.net/Articles/861444/ Wol <div class="FormattedComment"> <font class="QuotedText">&gt; A process that panic()s or crashes on invalid memory accesses is inherently safe, isn&#x27;t it?</font><br> <p> And if you&#x27;re in the aircraft where that software is controlling the plane&#x27;s fly-by-wire system ... ?<br> <p> Cheers,<br> Wol<br> </div> Wed, 30 Jun 2021 17:59:35 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861429/ https://lwn.net/Articles/861429/ miquels <div class="FormattedComment"> A process that panic()s or crashes on invalid memory accesses is inherently safe, isn&#x27;t it?<br> <p> The problem with Rust and mmap is that it just doesn&#x27;t work if you write from one thread or process and read from another - that&#x27;s instant UB (Undefined Behaviour) and that is _really_ unsafe.<br> <p> I think the only safe way to read from or write to mmap&#x27;ed memory in Rust is to use atomics - mmap it as AtomicU&lt;whatever&gt; and only read/write using the load/store operations on the atomic values.<br> </div> Wed, 30 Jun 2021 15:52:59 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861360/ https://lwn.net/Articles/861360/ hmh <div class="FormattedComment"> That looks like it would have been a much more generally useful (and expensive, complicated, etc) feature to implement than suppressing sigbus or zero-extending...<br> <p> Mmap snapshot (maybe with a read-only result if that would be much easier or cheaper to implement and still cover the use cases).<br> <p> But until someone offers to do that work...<br> </div> Wed, 30 Jun 2021 11:57:37 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861267/ https://lwn.net/Articles/861267/ matthias <div class="FormattedComment"> <font class="QuotedText">&gt; You appear to be conflating two very different issues here. It&#x27;s true the compositor has never really be able to tell if the client has been displaying garbage. However the source of SIGBUS is essentially a protocol error. The client has promised the compositor that there was buffer here, and instead there was a hand grande. SIGBUS always allowed the compositor to detect and handle such protocol violations. </font><br> <p> The client has promised that there is a buffer that does not change while the compositor is using it. Any change would be a protocol error. Only in the very special case that the change is truncate, this protocol error could be detected by the compositor. With the proposed change of semantics, this special case just looks like other cases where the client changes the buffer at the wrong time.<br> <p> <font class="QuotedText">&gt; [Finding out which program displays garbage] is probably not impossible, but it surely wouldn&#x27;t be easy.</font><br> <p> For debugging purposes there should be a possibility to ask the compositor to which program some window belongs. After all, you also want to debug cases where a program just opens a window with garbage in it. Probably a much more common case than a program calling truncate on the buffer.<br> </div> Tue, 29 Jun 2021 10:34:20 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861243/ https://lwn.net/Articles/861243/ dullfire <div class="FormattedComment"> I would not imagine &quot;mmap&quot; could ever be fully async-signal-safe (after all you are screwing with the page table). However for the every narrow case of replacing a no-longer valid mapping, it should be fine.<br> <p> Seeing as mmap is typically a thin wrapper around a syscall (AFAIK there is no currently known way for this to not be a kernel task) most of this must naturally be done in kernel, which negates most of the issues.<br> <p> However since you brought it up, I&#x27;m assuming you are implying being portable/standards conformant is important. So for that we would need a change of standards. But that&#x27;s probably more of a &#x27;paper&#x27; change (while it&#x27;s possible some implementations that are posix.1 2008 compliant implement mmap(2) in a way that would be unsafe for this proposed usage, I kind of doubt it).<br> <p> A linux-only change, that just papers over the issue seems like a poor solution.<br> <p> </div> Mon, 28 Jun 2021 18:54:55 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861232/ https://lwn.net/Articles/861232/ NYKevin <div class="FormattedComment"> <font class="QuotedText">&gt; As I said in my original post: I&#x27;m pretty sure the compositors SIGBUS handler could mmap over the faulting region, and then set a flag that the given client is miss behaving.</font><br> <p> signal-safety(7) does not list mmap as async-signal-safe, at least on my system. But that just means that POSIX doesn&#x27;t require it to be safe. I suppose it&#x27;s possible that Linux does implement an async-signal-safe mmap as an extension?<br> <p> (Unfortunately, we can&#x27;t just use the usual trick of &quot;set a flag and return, then do the real work from the main event loop&quot; because we need to fix the memory problem *before* we return from the SIGBUS handler, or else we&#x27;d need to pause the offending thread, call mmap from a different thread, etc.)<br> </div> Mon, 28 Jun 2021 17:29:41 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861199/ https://lwn.net/Articles/861199/ excors <div class="FormattedComment"> <font class="QuotedText">&gt; The compositor is just doing a memory lookup, at assembly level there is no such thing as a &quot;failed read&quot;. The kernel can generate a signal but it can&#x27;t fail the original instruction, the MOV has to return something.</font><br> <p> I don&#x27;t think that&#x27;s really true. At the assembly level, the outcome of the MOV instruction is that it either loads a value into the register *or* triggers an exception. E.g. if you look in the ARMv8-A Architecture Reference Manual, it explicitly defines the LDR instruction in terms of the &quot;AArch64.MemSingle&quot; operation which can call the &quot;AArch64.TakeException&quot; operation, which sets up the exception state then calls &quot;EndOfInstruction&quot; to stop any further processing of the LDR instruction, so it won&#x27;t write anything to the destination register.<br> <p> Once the exception is triggered, the kernel is free to do whatever it wants - update the page tables then jump back to the MOV instruction to retry it, manually update the register state then jump back to the instruction after the MOV, call a signal handler, etc. Anyone writing user-space assembly code has to be aware of that, e.g. there are often ABI rules about stack pointers that are specifically there to allow the kernel to interrupt your thread at any point and run a signal handler on its current stack. So that&#x27;s not something you can safely ignore when working at assembly level.<br> </div> Mon, 28 Jun 2021 14:53:35 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861200/ https://lwn.net/Articles/861200/ dullfire <div class="FormattedComment"> <font class="QuotedText">&gt; Isn&#x27;t the real problem here the use of signal? The compositor is just doing a memory lookup, at assembly level there is no such thing as a &quot;failed read&quot;. </font><br> <p> As I said in my original post: I&#x27;m pretty sure the compositors SIGBUS handler could mmap over the faulting region, and then set a flag that the given client is miss behaving.<br> <p> When the compositor returns from the signal handler, it would finish it&#x27;s turn function/call stack (using the newly mmaped region... possibly zero filled, possibly full of kitten pictures.), eventually get high enough to notice that that connection had been marked as bad, then either discard the processing it had done, or perhaps show one frame with a garbage window.<br> <p> That way you resume from the error AND get notification of the buggy/malicious client. And you can have meaningful error messages.<br> </div> Mon, 28 Jun 2021 14:52:16 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861171/ https://lwn.net/Articles/861171/ kleptog <div class="FormattedComment"> Isn&#x27;t the real problem here the use of signal? The compositor is just doing a memory lookup, at assembly level there is no such thing as a &quot;failed read&quot;. The kernel can generate a signal but it can&#x27;t fail the original instruction, the MOV has to return something. The compositor would have to do a siglongjmp() because otherwise it&#x27;s going to generate a SIGBUS for every single instruction accessing the missing pages. And siglongjmp() is pretty tricky at the best of times.<br> <p> I can understand that developers would prefer if the kernel would just return zeros and the compositor recheck the size of the file after the copy completes. It&#x27;s just less moving parts that way.<br> <p> Someone else here noted userfaultfd() is doing something similar, so maybe there&#x27;s an answer there. The compositor thread would be blocked and the handler could remap the pages to avoid the SIGBUS retriggerring.<br> </div> Mon, 28 Jun 2021 13:18:08 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861160/ https://lwn.net/Articles/861160/ dullfire <div class="FormattedComment"> <font class="QuotedText">&gt; This was always the case. If the client changes the contents of the buffer to garbage, the compositor will not notice and the window will display garbage. Nothing new here. The change is that the client truncating the buffer now will look exactly the same as the client clearing the buffer at an inappropriate time. </font><br> <p> You appear to be conflating two very different issues here. It&#x27;s true the compositor has never really be able to tell if the client has been displaying garbage. However the source of SIGBUS is essentially a protocol error. The client has promised the compositor that there was buffer here, and instead there was a hand grande. SIGBUS always allowed the compositor to detect and handle such protocol violations. The proposed changes remove that ability (for the case of compositors that use it, so I guess it being &quot;opt-in&quot; is better than being &quot;opt-out&quot;).<br> <p> <p> <font class="QuotedText">&gt; Probably the program whose window displays garbage. </font><br> <p> Except the compositor doesn&#x27;t know there&#x27;s even a problem, so it&#x27;s can&#x27;t say &quot;hey it&#x27;s connection XXX&quot;, or it registered with string &quot;YYY&quot;. Not all programs have server side decoration (and IIRC the wayland standard is client side decoration). So if the user wasn&#x27;t looking at that window, or doesn&#x27;t remember which one it is (or never new in the case of dialogs, and a few other things), then it becomes difficult to figure out. If the window is on a &quot;task list&quot; like WM UI element, that might help, but not all windows are placed there.<br> <p> It&#x27;s probably not impossible, but it surely wouldn&#x27;t be easy.<br> <p> <p> To sum it up (again): The approach here appears to be &quot;make it work &#x27;safely&#x27; by sweeping all the problems under the rug&quot;. I don&#x27;t think that&#x27;s a good long term solution.<br> </div> Mon, 28 Jun 2021 08:35:41 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861155/ https://lwn.net/Articles/861155/ ilammy I wonder if some sort of copy-on-write private file mappings could help with that by avoiding copying the entire range (since mapped files tend to be huge). Like, you map a file a get a snapshot of its contents. Your process writing to that memory copies a page just for you and never syncs that page with the actual file. If any other process touches the file in any way via non-cow mapping or normal file ops, then the original data is copied and <em>other</em> process cow-mappings are dissociated from the file. Mon, 28 Jun 2021 02:50:59 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861154/ https://lwn.net/Articles/861154/ viro <div class="FormattedComment"> Create and open a file on tmpfs, in directory not accessible to anyone else. mmap() it. Pass the descriptor over SCM_RIGHTS datagram. And unlink() the damn thing, to keep the clutter down. Or use O_TMPFILE, for that matter, since that&#x27;s no more Linux-specific than new mmap flags would be.<br> <p> Sure, somebody malicious and controlling a process with your credentials will be able to screw you over, but then they could attach gdb to your client and have their merry way with it.<br> </div> Mon, 28 Jun 2021 01:25:02 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861150/ https://lwn.net/Articles/861150/ izbyshev <div class="FormattedComment"> Yes (the man page says that behavior of MAP_PRIVATE is unspecified if the underlying file changes, but this is what happens on Linux in practice). The ftruncate()-based scenario is only somewhat interesting because it might seem like it only changes the file metadata, but in fact the data in the truncated tail also changes (as observed by mmap() users).<br> <p> To be clear, the same behavior within the last page of the file is already possible with current kernels: ftruncate() that doesn&#x27;t remove the last page completely will look like filling its remainder with zeros (though it&#x27;s also formally unspecified).<br> <p> So, overall, I don&#x27;t see how MAP_NOSIGBUS would help with unsafety of Rust&#x27;s &amp;[u8] referring to mmap()&#x27;ed range.<br> </div> Mon, 28 Jun 2021 00:07:45 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861141/ https://lwn.net/Articles/861141/ NYKevin <div class="FormattedComment"> <font class="QuotedText">&gt; Not every system is an overcommit system. Windows isn&#x27;t. Linux with vm.overcommit_memory=2 isn&#x27;t either.</font><br> <p> Yes, that&#x27;s why I included the footnote about the OOM killer being out of scope. It&#x27;s not part of Rust in the first place.<br> </div> Sun, 27 Jun 2021 21:26:51 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861133/ https://lwn.net/Articles/861133/ dancol <div class="FormattedComment"> It occurs to me that one way to address the original problem with SIGBUS is to wire up userfaultfd to the mapping somehow. Then the compositor could arrange for the zero substitution --- or any other policy --- on its own without hard-coding zero-fill policy into the kernel.<br> </div> Sun, 27 Jun 2021 20:11:37 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861114/ https://lwn.net/Articles/861114/ jayalane <div class="FormattedComment"> You can’t change signal handling semantics much at all without breaking a ton of old stuff. Pretty sure Linus would not approve. <br> </div> Sun, 27 Jun 2021 19:35:19 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861112/ https://lwn.net/Articles/861112/ NYKevin <div class="FormattedComment"> I don&#x27;t think it is semantically possible to avoid making a copy. The length of the mmap is equal to the length on disk, and because Linux went with the no-mandatory-file-locking model, that length can change at any time, regardless of whether you&#x27;re using Rust, C, or a magnetic needle and a steady hand. If you want to end up with a &quot;safe&quot; object, you need it to not get suddenly truncated/zero-filled while you&#x27;re halfway through processing it.<br> <p> Making a copy also resolves issues of the form &quot;What if someone decides to scribble all over the file without changing its length, while I&#x27;m halfway through processing it?&quot; More generally, this falls into the &quot;validate, then process&quot; model of doing things - you can&#x27;t validate something if it can change out from under you!<br> </div> Sun, 27 Jun 2021 17:17:33 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861108/ https://lwn.net/Articles/861108/ matthias <div class="FormattedComment"> <font class="QuotedText">&gt; Further more it would actually only make the intended us case situation worse. Now clients can behave badly, and the compositor won&#x27;t even be able to notice. No longs, no disconnected the miss behaving client, just users with &quot;ugly windows&quot;, </font><br> <p> This was always the case. If the client changes the contents of the buffer to garbage, the compositor will not notice and the window will display garbage. Nothing new here. The change is that the client truncating the buffer now will look exactly the same as the client clearing the buffer at an inappropriate time. <br> <p> <font class="QuotedText">&gt; and they may not even know what program it was. Sounds like a nightmare to debug.</font><br> <p> Probably the program whose window displays garbage. <br> <p> </div> Sun, 27 Jun 2021 14:46:46 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861107/ https://lwn.net/Articles/861107/ ocrete <div class="FormattedComment"> Isn&#x27;t the content of a memory range chaning silently always possible if another program is modifying the file?<br> </div> Sun, 27 Jun 2021 14:24:25 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861103/ https://lwn.net/Articles/861103/ anton I would have thought about System V shared memory stuff (shmget and friends), and I was wondering about that myself when I read the article. Not that I have experience with it, but it seems that it was made for this. I now see that there is also POSIX shared memory (see man shm_overview), but it supports ftrucate(), so that probably does not help. Sun, 27 Jun 2021 13:52:10 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861104/ https://lwn.net/Articles/861104/ dullfire <div class="FormattedComment"> Having now thought about it for a while, this seems like a pretty bad approach to me.<br> <p> It seems to be targeted at exactly one use case (as others have mentioned).<br> Further more it would actually only make the intended us case situation worse. Now clients can behave badly, and the compositor won&#x27;t even be able to notice. No longs, no disconnected the miss behaving client, just users with &quot;ugly windows&quot;, and they may not even know what program it was. Sounds like a nightmare to debug.<br> <p> Further more, for non RGB buffer layouts, I&#x27;m not even sure what that would end up looking like on the screen.<br> <p> Again having thought about it for a while, it seems a sane thing to do would be: handle the SIGBUS by noting where(address) it&#x27;s failing, and then mapping in a private page of all zero (or ones, or w/e) over the now invalid mapping. Then the compositor can log something like &quot;client XXXX has given malformed buffer&quot; or what ever. It can even take corrective action, like dropping the client connection (and thus implicitly destroying the bad display content), or maybe even popping up an error message for the user (depending on settings,use case ,etc).<br> <p> I don&#x27;t think papering over the problem (and then closing your eyes to it ever existing) is going to make better user experiences, or more stable software. However that seems to be the approach this patch series wants to take.<br> </div> Sun, 27 Jun 2021 13:49:56 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861101/ https://lwn.net/Articles/861101/ mpr22 <div class="FormattedComment"> <font class="QuotedText">&gt; Anyway, Rust wouldn&#x27;t be having this problem at all if it had just adopted exceptions for error handling.</font><br> <p> I dare say it would be having others, though.<br> </div> Sun, 27 Jun 2021 12:14:15 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861099/ https://lwn.net/Articles/861099/ eru <blockquote><i>responded with an implementation of MAP_NOSIGBUS, which differs from __MAP_NOFAULT in a number of ways</i></blockquote> <p> I wonder why? Would it not be useful if *ix -style systems implemented similar extensions similarly? That would help porting and also they would probably eventually get standardized. Sun, 27 Jun 2021 09:42:40 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861098/ https://lwn.net/Articles/861098/ randomguy3 I went and looked up the link: <blockquote> The reason is that there will always exist clients which are either old (and predate file sealing) or refuse to use Linux-only APIs (they don't use memfd and file sealing, instead they use e.g. shm_open). Requiring sealed memfds in compositors would break these clients. <p>I don't believe the situation is about to change. <p>Rather than requiring changes in all compositors *and* clients, can we maybe only require changes in compositors? For instance, OpenBSD has a __MAP_NOFAULT flag. When passed to mmap, it means that out-of-bound accesses will read as zeroes instead of triggering SIGBUS. Such a flag would be very helpful to unblock the annoying SIGBUS situation.</blockquote> Sun, 27 Jun 2021 08:13:23 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861096/ https://lwn.net/Articles/861096/ randomguy3 <div class="FormattedComment"> Are you referring to MAP_SHARED + MAP_ANONYMOUS memory? As I understand it, you can only share such memory with your child processes.<br> <p> Or perhaps you mean using mem_fd? That possibility was mentioned in the article, which also notes &quot;no compositor requires the use of sealed memfds because there are clients that are unwilling or unable to use them&quot;.<br> <p> I am interested in the reasons behind this &quot;unable or unwilling&quot;, though.<br> </div> Sun, 27 Jun 2021 08:09:59 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861093/ https://lwn.net/Articles/861093/ dancol <div class="FormattedComment"> <font class="QuotedText">&gt; why OOMing needs to crash, in a language with manual memory management. You could instead have fallible allocation and require the application to handle an OOM condition explicitly.</font><br> <p> Not every system is an overcommit system. Windows isn&#x27;t. Linux with vm.overcommit_memory=2 isn&#x27;t either. <br> <p> Anyway, Rust wouldn&#x27;t be having this problem at all if it had just adopted exceptions for error handling.<br> </div> Sun, 27 Jun 2021 05:57:39 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861092/ https://lwn.net/Articles/861092/ dancol <div class="FormattedComment"> Or the language could just do the right thing and install a signal handler and report the access failure as a language-specific exception or panic --- but the entire Linux ecosystem has been inexplicably reluctant to change or improve anything whatsoever relating to signals, so it&#x27;s very hard for a general-purpose library to use a signal handler in a way that doesn&#x27;t stomp over someone else&#x27;s desired use.<br> </div> Sun, 27 Jun 2021 05:51:16 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861091/ https://lwn.net/Articles/861091/ roc <div class="FormattedComment"> That&#x27;s a good point.<br> </div> Sun, 27 Jun 2021 04:14:28 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861090/ https://lwn.net/Articles/861090/ roc <div class="FormattedComment"> <font class="QuotedText">&gt; `&amp;[u8]` might be fine, but if I mmap&#x27;d something like `&amp;[RawSpriteData]`, I think I&#x27;d *prefer* to crash because all-zeros isn&#x27;t very useful to me.</font><br> <p> You can have a safe mmap function that returns &amp;[u8]. Then you could use something like <a href="https://docs.rs/safe-transmute/0.11.2/safe_transmute">https://docs.rs/safe-transmute/0.11.2/safe_transmute</a> to transmute to a different kind of reference if that&#x27;s safe.<br> <p> You&#x27;re right that in extremes, safety gets a bit fuzzy. It&#x27;s nice to be able to push the boundaries pretty far out though.<br> </div> Sun, 27 Jun 2021 04:12:43 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861087/ https://lwn.net/Articles/861087/ ju3Ceemi <div class="FormattedComment"> Why are they using a memory-baked file as shared memory ?<br> Why not use shared memory as shared memory ?<br> <p> </div> Sat, 26 Jun 2021 23:10:51 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861081/ https://lwn.net/Articles/861081/ mathstuf <div class="FormattedComment"> Agreed. It&#x27;s the same reason commit messages are so important for diffs: it helps to introduce others to what the change does as a whole, how it is used, and to (ideally) say why it is useful. Documentation is even more important because it should be what people look for first when trying to figure out how to do something. Commit messages are just harder to dig up via manpages…<br> </div> Sat, 26 Jun 2021 19:21:39 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861078/ https://lwn.net/Articles/861078/ izbyshev <div class="FormattedComment"> <font class="QuotedText">&gt; Rust safety only requires that &amp;[u8] reference a range of memory that doesn&#x27;t change and doesn&#x27;t cause a crash if you access it.</font><br> <p> Consider the following sequence of events:<br> 1. Program A maps the file with MAP_PRIVATE | MAP_NOSIGBUS.<br> 2. Program A accesses page P from that file.<br> 3. Program B truncates the file to zero.<br> 4. Page P is evicted from RAM due to memory pressure.<br> 5. Program A accesses page P again.<br> <p> How is the resulting page fault handled? If a zero-filled page is mapped, then the contents of the range of memory does change silently.<br> </div> Sat, 26 Jun 2021 18:02:39 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861073/ https://lwn.net/Articles/861073/ mathstuf <div class="FormattedComment"> I don&#x27;t know. `&amp;[u8]` might be fine, but if I mmap&#x27;d something like `&amp;[RawSpriteData]`, I think I&#x27;d *prefer* to crash because all-zeros isn&#x27;t very useful to me.<br> <p> <font class="QuotedText">&gt; I know, at compile time, that dereferencing a given pointer will never cause the program to crash, corrupt the heap, or otherwise misbehave.</font><br> <p> Rust (or any language for that matter) can only do so much. If, say, the hypervisor ends up fiddling with the VM&#x27;s page tables, programs can certainly crash no matter how &quot;safe&quot; the language or runtime is. If the RAM gets a bit twiddled by a cosmic ray, all bets are similarly off in most cases. These kinds of things are outside of a language&#x27;s control and are, IMO, purely in the realm of &quot;just how paranoid do you need to be?&quot; when coding any project in any language. JoeSchmo webapp? Users are probably trained to refresh on weird errors these days and such things are fine with systemd&#x27;s restart logic. Sending a rover to Mars? Random RAM flips are very relevant, better have redundant hardware.<br> <p> <font class="QuotedText">&gt; I know, at compile time, that my program will handle all error cases within a given subroutine. The subroutine is &quot;safe.&quot;</font><br> <p> Not sure how you plan to handle the &quot;power lost&quot; error condition, but I&#x27;d be interested :) .<br> </div> Sat, 26 Jun 2021 17:16:58 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861070/ https://lwn.net/Articles/861070/ Bigos <div class="FormattedComment"> What I meant is to fix all legitimate applications (doing a change in mesa might solve the majority of it) and then eventually require sealed memfds instead of supporting the mechanism that is, as you mentioned, prone to abuse.<br> <p> However, it seems the ship has already sailed and no one wants to change the protocol to accommodate this safer way of passing buffers around. Which is sad.<br> </div> Sat, 26 Jun 2021 14:45:11 +0000 Suppressing SIGBUS signals https://lwn.net/Articles/861068/ https://lwn.net/Articles/861068/ re:fi.64 <div class="FormattedComment"> Afaik this isn&#x27;t really a solvable issue for any protocol without just not supporting sending these at all, which would be a performance hit.<br> </div> Sat, 26 Jun 2021 14:08:44 +0000