Check that the PR_NO_NEW_PRIVILEGES flag is set.
| 74 | |
| 75 | // Check that the PR_NO_NEW_PRIVILEGES flag is set. |
| 76 | TEST_F(LinuxNNPIsolatorTest, ROOT_CheckNoNewPrivileges) |
| 77 | { |
| 78 | // This tests requires the NoNewPrivs field present in process |
| 79 | // status fields which requires Linux kernel version greater than |
| 80 | // or equal to 4.10. |
| 81 | Try<Version> version = mesos::kernelVersion(); |
| 82 | ASSERT_SOME(version); |
| 83 | if (version.get() < Version(4, 10, 0)) { |
| 84 | LOG(INFO) << "Linux kernel version greater than or equal to 4.10 required"; |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | AWAIT_READY(DockerArchive::create(GetRegistryPath(), "test_image")); |
| 89 | |
| 90 | slave::Flags flags = CreateSlaveFlags(); |
| 91 | |
| 92 | Fetcher fetcher(flags); |
| 93 | |
| 94 | Try<MesosContainerizer*> create = |
| 95 | MesosContainerizer::create(flags, true, &fetcher); |
| 96 | |
| 97 | ASSERT_SOME(create); |
| 98 | |
| 99 | Owned<Containerizer> containerizer(create.get()); |
| 100 | |
| 101 | ContainerID containerId; |
| 102 | containerId.set_value(id::UUID::random().toString()); |
| 103 | |
| 104 | // Test that the child process inherits the PR_NO_NEW_PRIVS flag. |
| 105 | // Using parameter expansion to parse the process status file |
| 106 | // due to minimal docker image. The child process should inherit |
| 107 | // the PR_NO_NEW_PRIVS flag. Parse the process status file and |
| 108 | // determine if "NoNewPrivs: 1" is found. |
| 109 | ExecutorInfo executor = createExecutorInfo( |
| 110 | "test_executor", |
| 111 | R"~( |
| 112 | #!/bin/bash |
| 113 | x=$(cat /proc/self/status); |
| 114 | y=${x##*NoNewPrivs:}; |
| 115 | read -a a <<< $y; |
| 116 | if [ ${a[0]} == "1" ]; then exit 0; else exit 1; fi |
| 117 | )~"); |
| 118 | |
| 119 | executor.mutable_container()->CopyFrom(createContainerInfo("test_image")); |
| 120 | |
| 121 | string directory = path::join(flags.work_dir, "sandbox"); |
| 122 | ASSERT_SOME(os::mkdir(directory)); |
| 123 | |
| 124 | Future<Containerizer::LaunchResult> launch = containerizer->launch( |
| 125 | containerId, |
| 126 | createContainerConfig(None(), executor, directory), |
| 127 | map<string, string>(), |
| 128 | None()); |
| 129 | |
| 130 | AWAIT_ASSERT_EQ(Containerizer::LaunchResult::SUCCESS, launch); |
| 131 | |
| 132 | Future<Option<ContainerTermination>> wait = containerizer->wait(containerId); |
| 133 |
nothing calls this directly
no test coverage detected