[PATCH 5/7] Trap SIGBUS to handle truncated shared memory segments

Mark Kettenis mark.kettenis at xs4all.nl
Fri Nov 8 14:02:55 PST 2013


> From: Adam Jackson <ajax at nwnk.net>
> Date: Fri, 08 Nov 2013 12:54:21 -0500
> 
> On Thu, 2013-11-07 at 12:15 -0800, Keith Packard wrote:
> > If a client passes a section of memory via file descriptor and then
> > subsequently truncates that file, the underlying pages will be freed
> > and the addresses invalidated. Subsequent accesses to the page will
> > fail with a SIGBUS error.
> > 
> > Trap that SIGBUS, figure out which segment was causing the error and
> > then allocate new pages to fill in for that region. Mark the offending
> > shared segment as invalid and free the resource ID so that the client
> > will be able to tell when subsequently attempting to use the segment.
> > 
> > Signed-off-by: Keith Packard <keithp at keithp.com>
> > 
> > v2: Use MAP_FIXED to simplify the recovery logic (Mark Kettenis)
> > v3: Also catch errors in ShmCreateSegment
> 
> I'm not totally convinced that you'd always get SIGBUS instead of
> SIGSEGV?  Or anyway I don't feel like looking up the relevant specs atm.
> But you'd crash in any case so this can't be worse.

You'll get SIGSEGV on OpenBSD and the Solaris mmap(2) man page says
you'll get either SIGBUS or SIGSEGV.

Adding the code to handle SIGSEGV is on my list of things to do.
Wouldn't mind if somebody beats me to it though.


More information about the xorg-devel mailing list