Skip to content

Commit 4655f85

Browse files
committed
Don't run personality syscall at configure time; don't check it at all
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.
1 parent e2ea3a3 commit 4655f85

11 files changed

+22
-204
lines changed

gdb/ChangeLog

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2021-05-08 Pedro Alves <[email protected]>
2+
3+
* linux-nat.c (linux_nat_target::supports_disable_randomization):
4+
Remove references to HAVE_PERSONALITY.
5+
* nat/linux-personality.c: Remove references to HAVE_PERSONALITY.
6+
(maybe_disable_address_space_randomization)
7+
(~maybe_disable_address_space_randomizatio): Remove references to
8+
HAVE_PERSONALITY.
9+
* config.in, configure: Regenerate.
10+
111
2021-05-07 Andrew Burgess <[email protected]>
212

313
* cli/cli-cmds.c: Add 'gdbsupport/gdb_tilde_expand.h'

gdb/config.in

-7
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@
9696
/* define if the compiler supports basic C++11 syntax */
9797
#undef HAVE_CXX11
9898

99-
/* Define to 1 if you have the declaration of `ADDR_NO_RANDOMIZE', and to 0 if
100-
you don't. */
101-
#undef HAVE_DECL_ADDR_NO_RANDOMIZE
102-
10399
/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
104100
don't. */
105101
#undef HAVE_DECL_ASPRINTF
@@ -301,9 +297,6 @@
301297
/* Define to 1 if you have the <nlist.h> header file. */
302298
#undef HAVE_NLIST_H
303299

304-
/* Define if you support the personality syscall. */
305-
#undef HAVE_PERSONALITY
306-
307300
/* Define to 1 if you have the `pipe' function. */
308301
#undef HAVE_PIPE
309302

gdb/configure

-74
Original file line numberDiff line numberDiff line change
@@ -13819,80 +13819,6 @@ fi
1381913819
done
1382013820

1382113821

13822-
ac_fn_c_check_decl "$LINENO" "ADDR_NO_RANDOMIZE" "ac_cv_have_decl_ADDR_NO_RANDOMIZE" "#include <sys/personality.h>
13823-
"
13824-
if test "x$ac_cv_have_decl_ADDR_NO_RANDOMIZE" = xyes; then :
13825-
ac_have_decl=1
13826-
else
13827-
ac_have_decl=0
13828-
fi
13829-
13830-
cat >>confdefs.h <<_ACEOF
13831-
#define HAVE_DECL_ADDR_NO_RANDOMIZE $ac_have_decl
13832-
_ACEOF
13833-
13834-
13835-
if test "$cross_compiling" = yes; then :
13836-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13837-
/* end confdefs.h. */
13838-
#include <sys/personality.h>
13839-
int
13840-
main ()
13841-
{
13842-
13843-
# if !HAVE_DECL_ADDR_NO_RANDOMIZE
13844-
# define ADDR_NO_RANDOMIZE 0x0040000
13845-
# endif
13846-
/* Test the flag could be set and stays set. */
13847-
personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
13848-
if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
13849-
return 1
13850-
;
13851-
return 0;
13852-
}
13853-
_ACEOF
13854-
if ac_fn_c_try_link "$LINENO"; then :
13855-
have_personality=true
13856-
else
13857-
have_personality=false
13858-
fi
13859-
rm -f core conftest.err conftest.$ac_objext \
13860-
conftest$ac_exeext conftest.$ac_ext
13861-
else
13862-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13863-
/* end confdefs.h. */
13864-
#include <sys/personality.h>
13865-
int
13866-
main ()
13867-
{
13868-
13869-
# if !HAVE_DECL_ADDR_NO_RANDOMIZE
13870-
# define ADDR_NO_RANDOMIZE 0x0040000
13871-
# endif
13872-
/* Test the flag could be set and stays set. */
13873-
personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
13874-
if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
13875-
return 1
13876-
;
13877-
return 0;
13878-
}
13879-
_ACEOF
13880-
if ac_fn_c_try_run "$LINENO"; then :
13881-
have_personality=true
13882-
else
13883-
have_personality=false
13884-
fi
13885-
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
13886-
conftest.$ac_objext conftest.beam conftest.$ac_ext
13887-
fi
13888-
13889-
if $have_personality
13890-
then
13891-
13892-
$as_echo "#define HAVE_PERSONALITY 1" >>confdefs.h
13893-
13894-
fi
13895-
1389613822
ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
1389713823
if test "x$ac_cv_have_decl_strstr" = xyes; then :
1389813824
ac_have_decl=1

gdb/linux-nat.c

-4
Original file line numberDiff line numberDiff line change
@@ -4022,11 +4022,7 @@ linux_nat_target::supports_multi_process ()
40224022
bool
40234023
linux_nat_target::supports_disable_randomization ()
40244024
{
4025-
#ifdef HAVE_PERSONALITY
40264025
return true;
4027-
#else
4028-
return false;
4029-
#endif
40304026
}
40314027

40324028
/* SIGCHLD handler that serves two purposes: In non-stop/async mode,

gdb/nat/linux-personality.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
#include "gdbsupport/common-defs.h"
2121
#include "nat/linux-personality.h"
2222

23-
#ifdef HAVE_PERSONALITY
24-
# include <sys/personality.h>
25-
# if !HAVE_DECL_ADDR_NO_RANDOMIZE
26-
# define ADDR_NO_RANDOMIZE 0x0040000
27-
# endif /* ! HAVE_DECL_ADDR_NO_RANDOMIZE */
28-
#endif /* HAVE_PERSONALITY */
23+
#include <sys/personality.h>
2924

3025
/* See comment on nat/linux-personality.h. */
3126

@@ -34,7 +29,6 @@ maybe_disable_address_space_randomization (int disable_randomization)
3429
: m_personality_set (false),
3530
m_personality_orig (0)
3631
{
37-
#ifdef HAVE_PERSONALITY
3832
if (disable_randomization)
3933
{
4034
errno = 0;
@@ -49,14 +43,11 @@ maybe_disable_address_space_randomization (int disable_randomization)
4943
warning (_("Error disabling address space randomization: %s"),
5044
safe_strerror (errno));
5145
}
52-
#endif /* HAVE_PERSONALITY */
5346
}
5447

5548
maybe_disable_address_space_randomization::
5649
~maybe_disable_address_space_randomization ()
5750
{
58-
#ifdef HAVE_PERSONALITY
59-
6051
if (m_personality_set)
6152
{
6253
errno = 0;
@@ -65,5 +56,4 @@ maybe_disable_address_space_randomization::
6556
warning (_("Error restoring address space randomization: %s"),
6657
safe_strerror (errno));
6758
}
68-
#endif /* HAVE_PERSONALITY */
6959
}

gdbserver/ChangeLog

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2021-05-08 Pedro Alves <[email protected]>
2+
3+
* linux-low.cc:
4+
(linux_process_target::supports_disable_randomization): Remove
5+
reference to HAVE_PERSONALITY.
6+
* config.in, configure: Regenerate.
7+
18
2021-05-08 Pedro Alves <[email protected]>
29

310
* linux-low.cc: Don't include sys/personality.h or define

gdbserver/config.in

-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
/* define if the compiler supports basic C++11 syntax */
3232
#undef HAVE_CXX11
3333

34-
/* Define to 1 if you have the declaration of `ADDR_NO_RANDOMIZE', and to 0 if
35-
you don't. */
36-
#undef HAVE_DECL_ADDR_NO_RANDOMIZE
37-
3834
/* Define to 1 if you have the declaration of `asprintf', and to 0 if you
3935
don't. */
4036
#undef HAVE_DECL_ASPRINTF
@@ -182,9 +178,6 @@
182178
/* Define to 1 if you have the <netinet/tcp.h> header file. */
183179
#undef HAVE_NETINET_TCP_H
184180

185-
/* Define if you support the personality syscall. */
186-
#undef HAVE_PERSONALITY
187-
188181
/* Define to 1 if you have the `pipe' function. */
189182
#undef HAVE_PIPE
190183

gdbserver/configure

-74
Original file line numberDiff line numberDiff line change
@@ -7130,80 +7130,6 @@ fi
71307130
done
71317131

71327132

7133-
ac_fn_c_check_decl "$LINENO" "ADDR_NO_RANDOMIZE" "ac_cv_have_decl_ADDR_NO_RANDOMIZE" "#include <sys/personality.h>
7134-
"
7135-
if test "x$ac_cv_have_decl_ADDR_NO_RANDOMIZE" = xyes; then :
7136-
ac_have_decl=1
7137-
else
7138-
ac_have_decl=0
7139-
fi
7140-
7141-
cat >>confdefs.h <<_ACEOF
7142-
#define HAVE_DECL_ADDR_NO_RANDOMIZE $ac_have_decl
7143-
_ACEOF
7144-
7145-
7146-
if test "$cross_compiling" = yes; then :
7147-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7148-
/* end confdefs.h. */
7149-
#include <sys/personality.h>
7150-
int
7151-
main ()
7152-
{
7153-
7154-
# if !HAVE_DECL_ADDR_NO_RANDOMIZE
7155-
# define ADDR_NO_RANDOMIZE 0x0040000
7156-
# endif
7157-
/* Test the flag could be set and stays set. */
7158-
personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
7159-
if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
7160-
return 1
7161-
;
7162-
return 0;
7163-
}
7164-
_ACEOF
7165-
if ac_fn_c_try_link "$LINENO"; then :
7166-
have_personality=true
7167-
else
7168-
have_personality=false
7169-
fi
7170-
rm -f core conftest.err conftest.$ac_objext \
7171-
conftest$ac_exeext conftest.$ac_ext
7172-
else
7173-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
7174-
/* end confdefs.h. */
7175-
#include <sys/personality.h>
7176-
int
7177-
main ()
7178-
{
7179-
7180-
# if !HAVE_DECL_ADDR_NO_RANDOMIZE
7181-
# define ADDR_NO_RANDOMIZE 0x0040000
7182-
# endif
7183-
/* Test the flag could be set and stays set. */
7184-
personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
7185-
if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
7186-
return 1
7187-
;
7188-
return 0;
7189-
}
7190-
_ACEOF
7191-
if ac_fn_c_try_run "$LINENO"; then :
7192-
have_personality=true
7193-
else
7194-
have_personality=false
7195-
fi
7196-
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
7197-
conftest.$ac_objext conftest.beam conftest.$ac_ext
7198-
fi
7199-
7200-
if $have_personality
7201-
then
7202-
7203-
$as_echo "#define HAVE_PERSONALITY 1" >>confdefs.h
7204-
7205-
fi
7206-
72077133
ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
72087134
if test "x$ac_cv_have_decl_strstr" = xyes; then :
72097135
ac_have_decl=1

gdbserver/linux-low.cc

-4
Original file line numberDiff line numberDiff line change
@@ -6224,11 +6224,7 @@ linux_process_target::core_of_thread (ptid_t ptid)
62246224
bool
62256225
linux_process_target::supports_disable_randomization ()
62266226
{
6227-
#ifdef HAVE_PERSONALITY
62286227
return true;
6229-
#else
6230-
return false;
6231-
#endif
62326228
}
62336229

62346230
bool

gdbsupport/ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2021-05-08 Pedro Alves <[email protected]>
2+
3+
* common.m4 (personality test): Remove.
4+
15
2021-04-30 Tom Tromey <[email protected]>
26

37
* thread-pool.cc (thread_pool::post_task): Update.

gdbsupport/common.m4

-23
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,6 @@ AC_DEFUN([GDB_AC_COMMON], [
5555
ptrace64 sbrk setns sigaltstack sigprocmask \
5656
setpgid setpgrp getrusage getauxval])
5757
58-
dnl Check if we can disable the virtual address space randomization.
59-
dnl The functionality of setarch -R.
60-
AC_CHECK_DECLS([ADDR_NO_RANDOMIZE],,, [#include <sys/personality.h>])
61-
define([PERSONALITY_TEST], [AC_LANG_PROGRAM([#include <sys/personality.h>], [
62-
# if !HAVE_DECL_ADDR_NO_RANDOMIZE
63-
# define ADDR_NO_RANDOMIZE 0x0040000
64-
# endif
65-
/* Test the flag could be set and stays set. */
66-
personality (personality (0xffffffff) | ADDR_NO_RANDOMIZE);
67-
if (!(personality (personality (0xffffffff)) & ADDR_NO_RANDOMIZE))
68-
return 1])])
69-
AC_RUN_IFELSE([PERSONALITY_TEST],
70-
[have_personality=true],
71-
[have_personality=false],
72-
[AC_LINK_IFELSE([PERSONALITY_TEST],
73-
[have_personality=true],
74-
[have_personality=false])])
75-
if $have_personality
76-
then
77-
AC_DEFINE([HAVE_PERSONALITY], 1,
78-
[Define if you support the personality syscall.])
79-
fi
80-
8158
AC_CHECK_DECLS([strstr])
8259
8360
# ----------------------- #

0 commit comments

Comments
 (0)