Don’t use DYLD_INSERT_LIBRARIES with a system executable.

OS X 10.11 introduces System Integrity Protection. One facet of that
forbids code injection into system executables. A Crashpad test checks
that information can be recovered from dyld in early-launch crashes by
requesting dyld load a nonexistent library with DYLD_INSERT_LIBRARIES.
The executable was meaningless but a system-provided executable,
/usr/bin/true, was used for convenience.

This test hung on OS X 10.11 because DYLD_INSERT_LIBRARIES was ignored
for the system executable, and no crash occurred. The test waited for a
crash that would never come.

A custom no-op executable, crashpad_snapshot_test_no_op, is provided as
an executable that does work with DYLD_INSERT_LIBRARIES.

BUG=crashpad:41
TEST=crashpad_snapshot_test MachOImageAnnotationsReader.CrashDyld
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1276553005 .
This commit is contained in:
Mark Mentovai 2015-08-05 18:24:53 -04:00
parent cd1f8fa3d2
commit 5e8e72f91c
3 changed files with 50 additions and 3 deletions

View File

@ -26,6 +26,7 @@
#include <vector>
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "client/crashpad_info.h"
#include "client/simple_string_dictionary.h"
#include "gtest/gtest.h"
@ -33,6 +34,7 @@
#include "test/errors.h"
#include "test/mac/mach_errors.h"
#include "test/mac/mach_multiprocess.h"
#include "test/paths.h"
#include "util/file/file_io.h"
#include "util/mac/mac_util.h"
#include "util/mach/exc_server_variants.h"
@ -45,6 +47,11 @@ namespace crashpad {
namespace test {
namespace {
//! \return The path to the crashpad_snapshot_test_no_op executable.
base::FilePath NoOpExecutable() {
return base::FilePath(Paths::Executable().value() + "_no_op");
}
class TestMachOImageAnnotationsReader final
: public MachMultiprocess,
public UniversalMachExcServer::Interface {
@ -304,9 +311,14 @@ class TestMachOImageAnnotationsReader final
// The actual executable doesnt matter very much, because dyld wont
// ever launch it. It just needs to be an executable that uses dyld as
// its LC_LOAD_DYLINKER (all normal executables do). /usr/bin/true is on
// every system, so use it.
ASSERT_EQ(0, execl("/usr/bin/true", "true", nullptr))
// its LC_LOAD_DYLINKER (all normal executables do). A custom no-op
// executable is provided because DYLD_INSERT_LIBRARIES does not work
// with system executables on OS X 10.11 due to System Integrity
// Protection.
base::FilePath no_op_executable = NoOpExecutable();
ASSERT_EQ(0, execl(no_op_executable.value().c_str(),
no_op_executable.BaseName().value().c_str(),
nullptr))
<< ErrnoMessage("execl");
break;
}

View File

@ -0,0 +1,19 @@
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdlib.h>
int main(int argc, char* argv[]) {
return EXIT_SUCCESS;
}

View File

@ -80,6 +80,9 @@
],
'conditions': [
['OS=="mac"', {
'dependencies': [
'crashpad_snapshot_test_no_op',
],
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/OpenCL.framework',
@ -103,4 +106,17 @@
],
},
],
'conditions': [
['OS=="mac"', {
'targets': [
{
'target_name': 'crashpad_snapshot_test_no_op',
'type': 'executable',
'sources': [
'mac/mach_o_image_annotations_reader_test_no_op.cc',
],
},
],
}],
],
}