unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Greg Troxel <gdt@lexort.com>
To: guile-devel@gnu.org
Subject: minor mmap protection  issue
Date: Mon, 24 Jun 2019 13:42:54 -0400	[thread overview]
Message-ID: <rmi1rzij2w1.fsf@s1.lexort.com> (raw)

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;




                 reply	other threads:[~2019-06-24 17:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=rmi1rzij2w1.fsf@s1.lexort.com \
    --to=gdt@lexort.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).