Trap SIGBUS to handle truncated shared memory segments

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@keithp.com>

v2: Use MAP_FIXED to simplify the recovery logic (Mark Kettenis)
v3: Also catch errors in ShmCreateSegment

Conflicts:
	include/dix-config.h.in
	include/xorg-config.h.in
This commit is contained in:
Keith Packard
2013-11-03 13:12:40 -08:00
parent 719e880d76
commit 41da295eb5
10 changed files with 275 additions and 2 deletions

View File

@@ -62,6 +62,10 @@ typedef struct _ShmFuncs {
#define SHM_FD_PASSING 1
#endif
#ifdef SHM_FD_PASSING
#include "busfault.h"
#endif
typedef struct _ShmDesc {
struct _ShmDesc *next;
int shmid;
@@ -71,6 +75,7 @@ typedef struct _ShmDesc {
unsigned long size;
#ifdef SHM_FD_PASSING
Bool is_fd;
struct busfault *busfault;
XID resource;
#endif
} ShmDescRec, *ShmDescPtr;