Don't run personality syscall at configure time; don't check it at all
authorPedro Alves <pedro@palves.net>
Wed, 28 Apr 2021 22:05:15 +0000 (23:05 +0100)
committerPedro Alves <pedro@palves.net>
Sat, 8 May 2021 12:45:36 +0000 (13:45 +0100)
Currently, in order to tell whether support for disabling address
space randomization on Linux is available, GDB checks if the
personality syscall works, at configure time.  I.e., it does a run
test, instead of a compile/link test:

  AC_RUN_IFELSE([PERSONALITY_TEST],
[have_personality=true],
[have_personality=false],

This is a bit bogus, because the machine the build is done on may not
(and is when you consider distro gdbs) be the machine that eventually
runs gdb.  It would be better if this were a compile/link test
instead, and then at runtime, GDB coped with the personality syscall
failing.  Actually, GDB already copes.

One environment where this is problematic is building GDB in a Docker
container -- by default, Docker runs the container with seccomp, with
a profile that disables the personality syscall.  You can tell Docker
to use a less restricted seccomp profile, but I think we should just
fix it in GDB.

"man 2 personality" says:

       This system call first appeared in Linux 1.1.20 (and thus first
       in a stable kernel release with Linux 1.2.0); library support
       was added in glibc 2.3.

...

       ADDR_NO_RANDOMIZE (since Linux 2.6.12)
              With this flag set, disable address-space-layout randomization.

glibc 2.3 was released in 2002.
Linux 2.6.12 was released in 2005.

The original patch that added the configure checks was submitted in
2008.  The first version of the patch that was submitted to the list
called personality from common code:

 https://sourceware.org/pipermail/gdb-patches/2008-June/058204.html

and then was moved to Linux-specific code:

 https://sourceware.org/pipermail/gdb-patches/2008-June/058209.html

Since HAVE_PERSONALITY is only checked in Linux code, and
ADDR_NO_RANDOMIZE exists for over 15 years, I propose just completely
removing the configure checks.

If for some odd reason, some remotely modern system still needs a
configure check, then we can revert this commit but drop the
AC_RUN_IFELSE in favor of always doing the AC_LINK_IFELSE
cross-compile fallback.

gdb/ChangeLog:

* linux-nat.c (linux_nat_target::supports_disable_randomization):
Remove references to HAVE_PERSONALITY.
* nat/linux-personality.c: Remove references to HAVE_PERSONALITY.
(maybe_disable_address_space_randomization)
(~maybe_disable_address_space_randomizatio): Remove references to
HAVE_PERSONALITY.
* config.in, configure: Regenerate.

gdbserver/ChangeLog:

* linux-low.cc:
(linux_process_target::supports_disable_randomization): Remove
reference to HAVE_PERSONALITY.
* config.in, configure: Regenerate.

gdbsupport/ChangeLog:

* common.m4 (personality test): Remove.

gdb/ChangeLog
gdb/config.in
gdb/configure
gdb/linux-nat.c
gdb/nat/linux-personality.c
gdbserver/ChangeLog
gdbserver/config.in
gdbserver/configure
gdbserver/linux-low.cc
gdbsupport/ChangeLog
gdbsupport/common.m4

index 41fe042d184f68cdce39e841315b52bc1b8c3748..3061bb9168c81c8d03f57102a6ffbbe0c92deef6 100644 (file)
@@ -1,3 +1,13 @@
+2021-05-08  Pedro Alves  <pedro@palves.net>
+
+       * linux-nat.c (linux_nat_target::supports_disable_randomization):
+       Remove references to HAVE_PERSONALITY.
+       * nat/linux-personality.c: Remove references to HAVE_PERSONALITY.
+       (maybe_disable_address_space_randomization)
+       (~maybe_disable_address_space_randomizatio): Remove references to
+       HAVE_PERSONALITY.
+       * config.in, configure: Regenerate.
+
 2021-05-07  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * cli/cli-cmds.c: Add 'gdbsupport/gdb_tilde_expand.h'
index 5d10377b73633b2ebf3afc7777ae0a6b2b53c112..99c924f9ba066ab224258410db40c1249cc0e050 100644 (file)
 /* define if the compiler supports basic C++11 syntax */
 #undef HAVE_CXX11
 
-/* Define to 1 if you have the declaration of `ADDR_NO_RANDOMIZE', and to 0 if
-   you don't. */
-#undef HAVE_DECL_ADDR_NO_RANDOMIZE
-
 /* Define to 1 if you have the declaration of `asprintf', and to 0 if you
    don't. */
 #undef HAVE_DECL_ASPRINTF
 /* Define to 1 if you have the <nlist.h> header file. */
 #undef HAVE_NLIST_H
 
-/* Define if you support the personality syscall. */
-#undef HAVE_PERSONALITY
-
 /* Define to 1 if you have the `pipe' function. */
 #undef HAVE_PIPE
 
index b47de77bf64c1dace6b6e15a2b4f249fb3206d4d..cdc112e10dc06199ee456c906fc9d16b090efd88 100755 (executable)
 done
 
 
-      ac_fn_c_check_decl "$LINENO" "ADDR_NO_RANDOMIZE" "ac_cv_have_decl_ADDR_NO_RANDOMIZE" "#include <sys/personality.h>
-"
-if test "x$ac_cv_have_decl_ADDR_NO_RANDOMIZE" = xyes; then :
-  ac_have_decl=1
-else
-  ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_ADDR_NO_RANDOMIZE $ac_have_decl
-_ACEOF
-
-
-  if test "$cross_compiling" = yes; then :
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/personality.h>
-int
-main ()
-{
-
-  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
-  #       define ADDR_NO_RANDOMIZE 0x0040000
-  #      endif
-        /* Test the flag could be set and stays set.  */
-        personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
-        if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
-            return 1
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  have_personality=true
-else
-  have_personality=false
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/personality.h>
-int
-main ()
-{
-
-  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
-  #       define ADDR_NO_RANDOMIZE 0x0040000
-  #      endif
-        /* Test the flag could be set and stays set.  */
-        personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
-        if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
-            return 1
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  have_personality=true
-else
-  have_personality=false
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
-
-  if $have_personality
-  then
-
-$as_echo "#define HAVE_PERSONALITY 1" >>confdefs.h
-
-  fi
-
   ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
 if test "x$ac_cv_have_decl_strstr" = xyes; then :
   ac_have_decl=1
index c45e335a762191e589d649b142bfe8555f4dc576..e595c71c3d33028e5a5c7dc2b8d5bc3ac6d51017 100644 (file)
@@ -4022,11 +4022,7 @@ linux_nat_target::supports_multi_process ()
 bool
 linux_nat_target::supports_disable_randomization ()
 {
-#ifdef HAVE_PERSONALITY
   return true;
-#else
-  return false;
-#endif
 }
 
 /* SIGCHLD handler that serves two purposes: In non-stop/async mode,
index 87d1921862602fe1d7230369ff8e9a3c7991ddcc..9ce345bc6de2a8c4a8fff4e1615f773bc8c51cad 100644 (file)
 #include "gdbsupport/common-defs.h"
 #include "nat/linux-personality.h"
 
-#ifdef HAVE_PERSONALITY
-# include <sys/personality.h>
-# if !HAVE_DECL_ADDR_NO_RANDOMIZE
-#  define ADDR_NO_RANDOMIZE 0x0040000
-# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
-#endif /* HAVE_PERSONALITY */
+#include <sys/personality.h>
 
 /* See comment on nat/linux-personality.h.  */
 
@@ -34,7 +29,6 @@ maybe_disable_address_space_randomization (int disable_randomization)
   : m_personality_set (false),
     m_personality_orig (0)
 {
-#ifdef HAVE_PERSONALITY
   if (disable_randomization)
     {
       errno = 0;
@@ -49,14 +43,11 @@ maybe_disable_address_space_randomization (int disable_randomization)
        warning (_("Error disabling address space randomization: %s"),
                 safe_strerror (errno));
     }
-#endif /* HAVE_PERSONALITY */
 }
 
 maybe_disable_address_space_randomization::
 ~maybe_disable_address_space_randomization ()
 {
-#ifdef HAVE_PERSONALITY
-
   if (m_personality_set)
     {
       errno = 0;
@@ -65,5 +56,4 @@ maybe_disable_address_space_randomization::
        warning (_("Error restoring address space randomization: %s"),
                 safe_strerror (errno));
     }
-#endif /* HAVE_PERSONALITY */
 }
index 1047697b0edaf430f0f1e046b3848bf98b63b432..6483d65700cd3b4ac1ad06177dea24e0e76558fa 100644 (file)
@@ -1,3 +1,10 @@
+2021-05-08  Pedro Alves  <pedro@palves.net>
+
+       * linux-low.cc:
+       (linux_process_target::supports_disable_randomization): Remove
+       reference to HAVE_PERSONALITY.
+       * config.in, configure: Regenerate.
+
 2021-05-08  Pedro Alves  <pedro@palves.net>
 
        * linux-low.cc: Don't include sys/personality.h or define
index 99391b4acff6f794b7888663490b21af437efe7e..611bfd7aa768551c7ae6e9127bdab868e9d24f68 100644 (file)
 /* define if the compiler supports basic C++11 syntax */
 #undef HAVE_CXX11
 
-/* Define to 1 if you have the declaration of `ADDR_NO_RANDOMIZE', and to 0 if
-   you don't. */
-#undef HAVE_DECL_ADDR_NO_RANDOMIZE
-
 /* Define to 1 if you have the declaration of `asprintf', and to 0 if you
    don't. */
 #undef HAVE_DECL_ASPRINTF
 /* Define to 1 if you have the <netinet/tcp.h> header file. */
 #undef HAVE_NETINET_TCP_H
 
-/* Define if you support the personality syscall. */
-#undef HAVE_PERSONALITY
-
 /* Define to 1 if you have the `pipe' function. */
 #undef HAVE_PIPE
 
index 032b4ae65bbc49c8ba10d8bfc947c35602b5db40..aab72c0b8c51b52173c5c9a9a717879f99b94ae8 100755 (executable)
@@ -7130,80 +7130,6 @@ fi
 done
 
 
-      ac_fn_c_check_decl "$LINENO" "ADDR_NO_RANDOMIZE" "ac_cv_have_decl_ADDR_NO_RANDOMIZE" "#include <sys/personality.h>
-"
-if test "x$ac_cv_have_decl_ADDR_NO_RANDOMIZE" = xyes; then :
-  ac_have_decl=1
-else
-  ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_ADDR_NO_RANDOMIZE $ac_have_decl
-_ACEOF
-
-
-  if test "$cross_compiling" = yes; then :
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/personality.h>
-int
-main ()
-{
-
-  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
-  #       define ADDR_NO_RANDOMIZE 0x0040000
-  #      endif
-        /* Test the flag could be set and stays set.  */
-        personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
-        if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
-            return 1
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-  have_personality=true
-else
-  have_personality=false
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-#include <sys/personality.h>
-int
-main ()
-{
-
-  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
-  #       define ADDR_NO_RANDOMIZE 0x0040000
-  #      endif
-        /* Test the flag could be set and stays set.  */
-        personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
-        if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
-            return 1
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  have_personality=true
-else
-  have_personality=false
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
-
-  if $have_personality
-  then
-
-$as_echo "#define HAVE_PERSONALITY 1" >>confdefs.h
-
-  fi
-
   ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
 if test "x$ac_cv_have_decl_strstr" = xyes; then :
   ac_have_decl=1
index ca3d25943df74e40d7db7d86492fb6d06b578a4a..9debe894eeb2b95dbf5b7f86b4f9188920a68a01 100644 (file)
@@ -6224,11 +6224,7 @@ linux_process_target::core_of_thread (ptid_t ptid)
 bool
 linux_process_target::supports_disable_randomization ()
 {
-#ifdef HAVE_PERSONALITY
   return true;
-#else
-  return false;
-#endif
 }
 
 bool
index 72802c66c56d83a8776148020debf4d9c29dda62..8b9077ce5337513783654e27bbd823f54a295ef1 100644 (file)
@@ -1,3 +1,7 @@
+2021-05-08  Pedro Alves  <pedro@palves.net>
+
+       * common.m4 (personality test): Remove.
+
 2021-04-30  Tom Tromey  <tromey@adacore.com>
 
        * thread-pool.cc (thread_pool::post_task): Update.
index 3ed95dabc858fc6d7cafa46289411eaea4f8343c..2e709dbbdbb3882b355d3d2e8f1b9fc486052da1 100644 (file)
@@ -55,29 +55,6 @@ AC_DEFUN([GDB_AC_COMMON], [
                  ptrace64 sbrk setns sigaltstack sigprocmask \
                  setpgid setpgrp getrusage getauxval])
 
-  dnl Check if we can disable the virtual address space randomization.
-  dnl The functionality of setarch -R.
-  AC_CHECK_DECLS([ADDR_NO_RANDOMIZE],,, [#include <sys/personality.h>])
-  define([PERSONALITY_TEST], [AC_LANG_PROGRAM([#include <sys/personality.h>], [
-  #      if !HAVE_DECL_ADDR_NO_RANDOMIZE
-  #       define ADDR_NO_RANDOMIZE 0x0040000
-  #      endif
-        /* Test the flag could be set and stays set.  */
-        personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
-        if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
-            return 1])])
-  AC_RUN_IFELSE([PERSONALITY_TEST],
-               [have_personality=true],
-               [have_personality=false],
-               [AC_LINK_IFELSE([PERSONALITY_TEST],
-                               [have_personality=true],
-                               [have_personality=false])])
-  if $have_personality
-  then
-      AC_DEFINE([HAVE_PERSONALITY], 1,
-               [Define if you support the personality syscall.])
-  fi
-
   AC_CHECK_DECLS([strstr])
 
   # ----------------------- #
This page took 0.047506 seconds and 4 git commands to generate.