unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* minor mmap protection  issue
@ 2019-06-24 17:42 Greg Troxel
  0 siblings, 0 replies; only message in thread
From: Greg Troxel @ 2019-06-24 17:42 UTC (permalink / raw)
  To: guile-devel

pkgsrc has the following patch for 2.2.5.  At first glance it looks at
least headed in the right direction, but I'd appreciate someone more
familiar with the code looking and either making a corresponding fix or
explaining the issue more.

As I understand it, POSIX is a bit vague on this issue:

  https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html
  https://pubs.opengroup.org/onlinepubs/9699919799/functions/mprotect.html#

but these are interfaces that originated in 4.2BSD and 4.4BSD.  From
mprotect on NetBSD 8, one can't expand a segment to writable that was
not mapped writable at first.

(This situation, broadly, seems wrapped up with W^X protection rules
that don't play well with loading executable code form files.)

Perhaps an immediate mprotect to read only is in order after PROT_WRITE.

(I don't understand why files from which code is being loaded neeed
writable mappings, but that's a special case of not understanding the
loader. :-)




$NetBSD: patch-libguile_loader.c,v 1.2 2019/06/23 09:14:58 wiz Exp $

Use correct mmap permissions for later PROT_WRITE mprotect.

--- libguile/loader.c.orig	2018-01-08 16:21:04.790894906 +0000
+++ libguile/loader.c
@@ -484,7 +484,7 @@ map_file_contents (int fd, size_t len, i
   char *data;
 
 #ifdef HAVE_SYS_MMAN_H
-  data = mmap (NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
+  data = mmap (NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
   if (data == MAP_FAILED)
     SCM_SYSERROR;
   *is_read_only = 1;




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-24 17:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 17:42 minor mmap protection issue Greg Troxel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).