chiark / gitweb /
bus: map sealed memfds as MAP_PRIVATE
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 18 Aug 2014 21:54:10 +0000 (23:54 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 18 Aug 2014 21:56:36 +0000 (23:56 +0200)
Mapping files as MAP_SHARED is handled by the kernel as 'writable'
mapping. Always! Even with PROT_READ. Reason for that is,
mprotect(PROT_WRITE) could change the mapping underneath and currently
there is no kernel infrastructure to add protection there. This might
change in the future, but until then, map sealed files as MAP_PRIVATE so
we don't get EPERM.

src/libsystemd/sd-bus/bus-message.c

index 3e60842172d2d7356e8eb952011d0d8bbcf9bcf4..c058b06f41b473dfbe43327ba987328f2a97fd13 100644 (file)
@@ -2840,7 +2840,7 @@ int bus_body_part_map(struct bus_body_part *part) {
         psz = PAGE_ALIGN(part->size);
 
         if (part->memfd >= 0)
         psz = PAGE_ALIGN(part->size);
 
         if (part->memfd >= 0)
-                p = mmap(NULL, psz, PROT_READ, MAP_SHARED, part->memfd, 0);
+                p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE, part->memfd, 0);
         else if (part->is_zero)
                 p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
         else
         else if (part->is_zero)
                 p = mmap(NULL, psz, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
         else