[Lldb-commits] [lldb] r215822 - Fix Linux to respect ASLR settings when launching processes to debug locally and remotely.
Todd Fiala
todd.fiala at gmail.com
Sat Aug 16 17:10:51 PDT 2014
Author: tfiala
Date: Sat Aug 16 19:10:50 2014
New Revision: 215822
URL: http://llvm.org/viewvc/llvm-project?rev=215822&view=rev
Log:
Fix Linux to respect ASLR settings when launching processes to debug locally and remotely.
See the following links for details:
http://llvm.org/bugs/show_bug.cgi?id=20658
See http://reviews.llvm.org/D4941
Modified:
lldb/trunk/lldb.xcodeproj/project.pbxproj
lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Sat Aug 16 19:10:50 2014
@@ -952,6 +952,12 @@
236124A31986B4E2004EFC37 /* Socket.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Socket.cpp; sourceTree = "<group>"; };
236124A61986B50E004EFC37 /* IoObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = IoObject.h; path = include/lldb/Host/IoObject.h; sourceTree = "<group>"; };
236124A71986B50E004EFC37 /* Socket.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Socket.h; path = include/lldb/Host/Socket.h; sourceTree = "<group>"; };
+ 23AB052D199FF639003B8084 /* FreeBSDThread.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FreeBSDThread.cpp; sourceTree = "<group>"; };
+ 23AB052E199FF639003B8084 /* FreeBSDThread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FreeBSDThread.h; sourceTree = "<group>"; };
+ 23AB052F199FF639003B8084 /* ProcessFreeBSD.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessFreeBSD.cpp; sourceTree = "<group>"; };
+ 23AB0530199FF639003B8084 /* ProcessFreeBSD.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ProcessFreeBSD.h; sourceTree = "<group>"; };
+ 23AB0531199FF639003B8084 /* ProcessMonitor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ProcessMonitor.cpp; sourceTree = "<group>"; };
+ 23AB0532199FF639003B8084 /* ProcessMonitor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ProcessMonitor.h; sourceTree = "<group>"; };
23DDF224196C3EE600BB8417 /* CommandOptionValidators.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandOptionValidators.cpp; path = source/Interpreter/CommandOptionValidators.cpp; sourceTree = "<group>"; };
23EDE3301926839700F6A132 /* NativeRegisterContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = NativeRegisterContext.cpp; path = source/Target/NativeRegisterContext.cpp; sourceTree = "<group>"; };
23EDE3311926843600F6A132 /* NativeRegisterContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NativeRegisterContext.h; path = include/lldb/Target/NativeRegisterContext.h; sourceTree = "<group>"; };
@@ -2282,6 +2288,19 @@
path = source/Host/linux;
sourceTree = "<group>";
};
+ 23AB0526199FF5D3003B8084 /* FreeBSD */ = {
+ isa = PBXGroup;
+ children = (
+ 23AB052E199FF639003B8084 /* FreeBSDThread.h */,
+ 23AB052D199FF639003B8084 /* FreeBSDThread.cpp */,
+ 23AB0530199FF639003B8084 /* ProcessFreeBSD.h */,
+ 23AB052F199FF639003B8084 /* ProcessFreeBSD.cpp */,
+ 23AB0532199FF639003B8084 /* ProcessMonitor.h */,
+ 23AB0531199FF639003B8084 /* ProcessMonitor.cpp */,
+ );
+ path = FreeBSD;
+ sourceTree = "<group>";
+ };
260C897110F57C5600BB2B04 /* Plugins */ = {
isa = PBXGroup;
children = (
@@ -2395,6 +2414,7 @@
isa = PBXGroup;
children = (
26BC179F18C7F4CB00D2196D /* elf-core */,
+ 23AB0526199FF5D3003B8084 /* FreeBSD */,
4CEE62F71145F1C70064CF93 /* GDB Remote */,
233B008B196106E90090E598 /* Linux */,
2642FBA713D003B400ED6808 /* MacOSX-Kernel */,
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Sat Aug 16 19:10:50 2014
@@ -807,6 +807,7 @@ ProcessMonitor::ProcessMonitor(ProcessPO
const char *stdout_path,
const char *stderr_path,
const char *working_dir,
+ const lldb_private::ProcessLaunchInfo & /* launch_info */,
lldb_private::Error &error)
: m_process(static_cast<ProcessFreeBSD *>(process)),
m_operation_thread(LLDB_INVALID_HOST_THREAD),
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.h Sat Aug 16 19:10:50 2014
@@ -55,6 +55,7 @@ public:
const char *stdout_path,
const char *stderr_path,
const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Error &error);
ProcessMonitor(ProcessPOSIX *process,
Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Sat Aug 16 19:10:50 2014
@@ -18,6 +18,7 @@
#include <stdint.h>
#include <unistd.h>
#include <linux/unistd.h>
+#include <sys/personality.h>
#include <sys/ptrace.h>
#include <sys/socket.h>
#include <sys/syscall.h>
@@ -92,6 +93,7 @@
#define ARCH_GET_GS 0x1004
#endif
+#define LLDB_PERSONALITY_GET_CURRENT_SETTINGS 0xffffffff
// Support hardware breakpoints in case it has not been defined
#ifndef TRAP_HWBKPT
@@ -993,7 +995,8 @@ NativeProcessLinux::LaunchArgs::LaunchAr
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
- const char *working_dir)
+ const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info)
: OperationArgs(monitor),
m_module(module),
m_argv(argv),
@@ -1001,7 +1004,10 @@ NativeProcessLinux::LaunchArgs::LaunchAr
m_stdin_path(stdin_path),
m_stdout_path(stdout_path),
m_stderr_path(stderr_path),
- m_working_dir(working_dir) { }
+ m_working_dir(working_dir),
+ m_launch_info(launch_info)
+{
+}
NativeProcessLinux::LaunchArgs::~LaunchArgs()
{ }
@@ -1084,6 +1090,7 @@ NativeProcessLinux::LaunchProcess (
stdout_path,
stderr_path,
working_dir,
+ launch_info,
error);
if (error.Fail ())
@@ -1182,6 +1189,7 @@ NativeProcessLinux::LaunchInferior (
const char *stdout_path,
const char *stderr_path,
const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Error &error)
{
if (module)
@@ -1193,7 +1201,7 @@ NativeProcessLinux::LaunchInferior (
new LaunchArgs(
this, module, argv, envp,
stdin_path, stdout_path, stderr_path,
- working_dir));
+ working_dir, launch_info));
sem_init(&m_operation_pending, 0, 0);
sem_init(&m_operation_done, 0, 0);
@@ -1351,6 +1359,10 @@ NativeProcessLinux::LaunchOpThread(void
bool
NativeProcessLinux::Launch(LaunchArgs *args)
{
+ assert (args && "null args");
+ if (!args)
+ return false;
+
NativeProcessLinux *monitor = args->m_monitor;
assert (monitor && "monitor is NULL");
if (!monitor)
@@ -1462,6 +1474,33 @@ NativeProcessLinux::Launch(LaunchArgs *a
if (0 != ::chdir(working_dir))
exit(eChdirFailed);
+ // Disable ASLR if requested.
+ if (args->m_launch_info.GetFlags ().Test (lldb::eLaunchFlagDisableASLR))
+ {
+ const int old_personality = personality (LLDB_PERSONALITY_GET_CURRENT_SETTINGS);
+ if (old_personality == -1)
+ {
+ if (log)
+ log->Printf ("NativeProcessLinux::%s retrieval of Linux personality () failed: %s. Cannot disable ASLR.", __FUNCTION__, strerror (errno));
+ }
+ else
+ {
+ const int new_personality = personality (ADDR_NO_RANDOMIZE | old_personality);
+ if (new_personality == -1)
+ {
+ if (log)
+ log->Printf ("NativeProcessLinux::%s setting of Linux personality () to disable ASLR failed, ignoring: %s", __FUNCTION__, strerror (errno));
+
+ }
+ else
+ {
+ if (log)
+ log->Printf ("NativeProcessLinux::%s disbling ASLR: SUCCESS", __FUNCTION__);
+
+ }
+ }
+ }
+
// Execute. We should never return.
execve(argv[0],
const_cast<char *const *>(argv),
Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h Sat Aug 16 19:10:50 2014
@@ -217,7 +217,8 @@ namespace lldb_private
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
- const char *working_dir);
+ const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info);
~LaunchArgs();
@@ -228,6 +229,7 @@ namespace lldb_private
const char *m_stdout_path; // Redirect stdout or NULL.
const char *m_stderr_path; // Redirect stderr or NULL.
const char *m_working_dir; // Working directory or NULL.
+ const lldb_private::ProcessLaunchInfo &m_launch_info;
};
struct AttachArgs : OperationArgs
@@ -256,6 +258,7 @@ namespace lldb_private
const char *stdout_path,
const char *stderr_path,
const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info,
Error &error);
/// Attaches to an existing process. Forms the
Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp Sat Aug 16 19:10:50 2014
@@ -15,6 +15,7 @@
#include <string.h>
#include <stdint.h>
#include <unistd.h>
+#include <sys/personality.h>
#include <sys/ptrace.h>
#include <sys/socket.h>
#include <sys/syscall.h>
@@ -60,6 +61,7 @@
#define ARCH_GET_GS 0x1004
#endif
+#define LLDB_PERSONALITY_GET_CURRENT_SETTINGS 0xffffffff
// Support hardware breakpoints in case it has not been defined
#ifndef TRAP_HWBKPT
@@ -967,7 +969,8 @@ ProcessMonitor::LaunchArgs::LaunchArgs(P
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
- const char *working_dir)
+ const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info)
: OperationArgs(monitor),
m_module(module),
m_argv(argv),
@@ -975,7 +978,10 @@ ProcessMonitor::LaunchArgs::LaunchArgs(P
m_stdin_path(stdin_path),
m_stdout_path(stdout_path),
m_stderr_path(stderr_path),
- m_working_dir(working_dir) { }
+ m_working_dir(working_dir),
+ m_launch_info(launch_info)
+{
+}
ProcessMonitor::LaunchArgs::~LaunchArgs()
{ }
@@ -1007,6 +1013,7 @@ ProcessMonitor::ProcessMonitor(ProcessPO
const char *stdout_path,
const char *stderr_path,
const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Error &error)
: m_process(static_cast<ProcessLinux *>(process)),
m_operation_thread(LLDB_INVALID_HOST_THREAD),
@@ -1017,7 +1024,7 @@ ProcessMonitor::ProcessMonitor(ProcessPO
{
std::unique_ptr<LaunchArgs> args(new LaunchArgs(this, module, argv, envp,
stdin_path, stdout_path, stderr_path,
- working_dir));
+ working_dir, launch_info));
sem_init(&m_operation_pending, 0, 0);
sem_init(&m_operation_done, 0, 0);
@@ -1145,6 +1152,10 @@ ProcessMonitor::LaunchOpThread(void *arg
bool
ProcessMonitor::Launch(LaunchArgs *args)
{
+ assert (args && "null args");
+ if (!args)
+ return false;
+
ProcessMonitor *monitor = args->m_monitor;
ProcessLinux &process = monitor->GetProcess();
const char **argv = args->m_argv;
@@ -1219,6 +1230,33 @@ ProcessMonitor::Launch(LaunchArgs *args)
if (0 != ::chdir(working_dir))
exit(eChdirFailed);
+ // Disable ASLR if requested.
+ if (args->m_launch_info.GetFlags ().Test (lldb::eLaunchFlagDisableASLR))
+ {
+ const int old_personality = personality (LLDB_PERSONALITY_GET_CURRENT_SETTINGS);
+ if (old_personality == -1)
+ {
+ if (log)
+ log->Printf ("ProcessMonitor::%s retrieval of Linux personality () failed: %s. Cannot disable ASLR.", __FUNCTION__, strerror (errno));
+ }
+ else
+ {
+ const int new_personality = personality (ADDR_NO_RANDOMIZE | old_personality);
+ if (new_personality == -1)
+ {
+ if (log)
+ log->Printf ("ProcessMonitor::%s setting of Linux personality () to disable ASLR failed, ignoring: %s", __FUNCTION__, strerror (errno));
+
+ }
+ else
+ {
+ if (log)
+ log->Printf ("ProcessMonitor::%s disbling ASLR: SUCCESS", __FUNCTION__);
+
+ }
+ }
+ }
+
// Execute. We should never return.
execve(argv[0],
const_cast<char *const *>(argv),
Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Sat Aug 16 19:10:50 2014
@@ -55,6 +55,7 @@ public:
const char *stdout_path,
const char *stderr_path,
const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Error &error);
ProcessMonitor(ProcessPOSIX *process,
@@ -233,7 +234,8 @@ private:
const char *stdin_path,
const char *stdout_path,
const char *stderr_path,
- const char *working_dir);
+ const char *working_dir,
+ const lldb_private::ProcessLaunchInfo &launch_info);
~LaunchArgs();
@@ -244,6 +246,7 @@ private:
const char *m_stdout_path; // Redirect stdout or NULL.
const char *m_stderr_path; // Redirect stderr or NULL.
const char *m_working_dir; // Working directory or NULL.
+ const lldb_private::ProcessLaunchInfo &m_launch_info;
};
void
Modified: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp?rev=215822&r1=215821&r2=215822&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp Sat Aug 16 19:10:50 2014
@@ -241,6 +241,7 @@ ProcessPOSIX::DoLaunch (Module *module,
stdout_path,
stderr_path,
working_dir,
+ launch_info,
error);
m_module = module;
More information about the lldb-commits
mailing list