[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

minor mmap protection issue

From: Greg Troxel
Subject: minor mmap protection issue
Date: Mon, 24 Jun 2019 13:42:54 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (berkeley-unix)

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:

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;
-  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)
   *is_read_only = 1;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]