I was pointed out to me that in Linux kernel 5.8 there is
a change to default memory settings: before readable memory
was executable by default, in 5.8 it is no longer executable
without explicit setting.

Attached patch to 'c_core.c' should restore previous
behaviour.  We should probably explicitely set executable
permissions on all memory that we want to execute, but this
would require a bit more work.  And without kernel 5.8
I would be unable to test such patch.

To test you need to apply patch to 'c_core.c', recompile
C routines and relink (there is no change to Pop11 code,
only to C file).  Of course full rebuild will do.

-- 
                              Waldek Hebisch
--- ../trunk/pop/extern/lib/c_core.c	2020-02-07 18:23:46.000000000 +0000
+++ pop/extern/lib/c_core.c	2021-05-06 23:31:15.365927914 +0000
@@ -2154,9 +2154,10 @@
              || (minor_version > 6)))
         || major_version >= 3) {
         int pers = personality(0xffffffffUL);
-        /* 0x40000 aka. ADDR_NO_RANDOMIZE */
-        if (!(pers & 0x40000)) {
-            int retval = personality(pers | 0x40000);
+        /* 0x40000 aka. ADDR_NO_RANDOMIZE, 0x0400000 is READ_IMPLIES_EXEC */
+        if (!(pers & 0x40000) || !(pers & 0x0400000)) {
+            int want_pers = pers | 0x40000 | 0x0400000;
+            int retval = personality(want_pers);
             /* Allegedly some Linux kernels (the reported case was
                "hardened Linux 2.6.7") won't set the new personality,
                but nor will they return -1 for an error. So as a
@@ -2165,7 +2166,7 @@
             /* ... and don't re-execute if either the setting resulted
                in an error or if the value didn't change. Otherwise
                this might result in an infinite loop. */
-            if (retval != -1 && newpers != pers) {
+            if (retval != -1 && newpers == want_pers) {
                 /* Use /proc/self/exe instead of trying to figure out
                    the executable path from PATH and argv[0], since
                    that's unreliable. We follow the symlink instead of

Reply via email to