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

Adam Jackson ajax at nwnk.net
Fri Nov 8 09:54:21 PST 2013


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.

Reviewed-by: Adam Jackson <ajax at redhat.com>

- ajax



More information about the xorg-devel mailing list