mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
befdb09597
Linking glibc in fully static mode is mostly unsupported. While such binaries can easily be produced, conflicting symbols will often make them crash at runtime. This happens because glibc will always (try to) load some dynamically linked libraries, even when statically linked. This includes things like the resolver, unicode/locale handling and others. Internally at Google, this is not a concern due to the way glibc is being built there. But in order to make all of our tests run in the open-source version of this code, we need to change strategy a bit. As a rule of thumb, glibc can safely be linked statically if a program is resonably simple and does not use any networking of locale dependent facilities. Calling syscalls directly instead of the corresponding libc wrappers works as well, of course. This change adjusts linker flags and sandbox policies to be more compatible with regular Linux distributions. Tested: - `ctest -R '[A-Z].*'` (all SAPI/Sandbox2 tests) PiperOrigin-RevId: 429025901 Change-Id: I46b677d9eb61080a8fe868002a34a77de287bf2d
219 lines
5.2 KiB
Python
219 lines
5.2 KiB
Python
# Copyright 2019 Google LLC
|
|
#
|
|
# 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
|
|
#
|
|
# https://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.
|
|
|
|
# Description: test cases for sandbox2 unit tests.
|
|
#
|
|
# Some of the following cc_binary options avoid dynamic linking which uses a
|
|
# lot of syscalls (open, mmap, etc.):
|
|
# linkstatic = True Default for cc_binary
|
|
# features = ["fully_static_link"] Adds -static
|
|
#
|
|
# Note that linking fully static with an unmodified glibc is not generally
|
|
# considered safe, due to glibc relying heavily on loading shared objects at
|
|
# runtime.
|
|
# The rule of thumb when it is safe to do so is when the program either only
|
|
# uses plain syscalls (bypassing any libc altogether) or if it does not use
|
|
# any networking and none of the functionality from cstdio/stdio.h (due to
|
|
# auto-loading of locale-specific shared objecs).
|
|
|
|
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
|
|
|
|
package(default_visibility = [
|
|
"//sandboxed_api/sandbox2:__subpackages__",
|
|
])
|
|
|
|
licenses(["notice"])
|
|
|
|
cc_binary(
|
|
name = "abort",
|
|
testonly = True,
|
|
srcs = ["abort.cc"],
|
|
copts = sapi_platform_copts(),
|
|
deps = ["//sandboxed_api/util:raw_logging"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "add_policy_on_syscalls",
|
|
testonly = True,
|
|
srcs = ["add_policy_on_syscalls.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "buffer",
|
|
testonly = True,
|
|
srcs = ["buffer.cc"],
|
|
copts = sapi_platform_copts(),
|
|
deps = [
|
|
"//sandboxed_api/sandbox2:buffer",
|
|
"//sandboxed_api/sandbox2:comms",
|
|
"@com_google_absl//absl/strings:str_format",
|
|
],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "ipc",
|
|
testonly = True,
|
|
srcs = ["ipc.cc"],
|
|
copts = sapi_platform_copts(),
|
|
deps = [
|
|
"//sandboxed_api/sandbox2:client",
|
|
"//sandboxed_api/sandbox2:comms",
|
|
"//sandboxed_api/util:raw_logging",
|
|
"@com_google_absl//absl/strings",
|
|
],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "malloc_system",
|
|
testonly = True,
|
|
srcs = ["malloc.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "minimal_dynamic",
|
|
testonly = True,
|
|
srcs = ["minimal.cc"],
|
|
copts = sapi_platform_copts(),
|
|
)
|
|
|
|
cc_binary(
|
|
name = "minimal",
|
|
testonly = True,
|
|
srcs = ["minimal.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "personality",
|
|
testonly = True,
|
|
srcs = ["personality.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "pidcomms",
|
|
testonly = True,
|
|
srcs = ["pidcomms.cc"],
|
|
copts = sapi_platform_copts(),
|
|
deps = [
|
|
"//sandboxed_api/sandbox2:client",
|
|
"//sandboxed_api/sandbox2:comms",
|
|
"//sandboxed_api/util:raw_logging",
|
|
],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "policy",
|
|
testonly = True,
|
|
srcs = ["policy.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
deps = ["//sandboxed_api:config"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "print_fds",
|
|
testonly = True,
|
|
srcs = ["print_fds.cc"],
|
|
copts = sapi_platform_copts(),
|
|
)
|
|
|
|
cc_binary(
|
|
name = "sanitizer",
|
|
testonly = True,
|
|
srcs = ["sanitizer.cc"],
|
|
copts = sapi_platform_copts(),
|
|
)
|
|
|
|
cc_binary(
|
|
name = "close_fds",
|
|
testonly = True,
|
|
srcs = ["close_fds.cc"],
|
|
copts = sapi_platform_copts(),
|
|
deps = [
|
|
"//sandboxed_api/sandbox2:sanitizer",
|
|
"@com_google_absl//absl/container:flat_hash_set",
|
|
"@com_google_absl//absl/strings",
|
|
"@com_google_glog//:glog",
|
|
],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "sleep",
|
|
testonly = True,
|
|
srcs = ["sleep.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "symbolize",
|
|
testonly = True,
|
|
srcs = ["symbolize.cc"],
|
|
copts = sapi_platform_copts(),
|
|
deps = [
|
|
"//sandboxed_api/util:raw_logging",
|
|
"//sandboxed_api/util:temp_file",
|
|
"@com_google_absl//absl/base:core_headers",
|
|
"@com_google_absl//absl/strings",
|
|
],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "tsync",
|
|
testonly = True,
|
|
srcs = ["tsync.cc"],
|
|
copts = sapi_platform_copts(),
|
|
deps = [
|
|
"//sandboxed_api/sandbox2:client",
|
|
"//sandboxed_api/sandbox2:comms",
|
|
],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "starve",
|
|
testonly = True,
|
|
srcs = ["starve.cc"],
|
|
copts = sapi_platform_copts(),
|
|
)
|
|
|
|
cc_binary(
|
|
name = "hostname",
|
|
testonly = True,
|
|
srcs = ["hostname.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "limits",
|
|
testonly = True,
|
|
srcs = ["limits.cc"],
|
|
copts = sapi_platform_copts(),
|
|
)
|
|
|
|
cc_binary(
|
|
name = "namespace",
|
|
testonly = True,
|
|
srcs = ["namespace.cc"],
|
|
copts = sapi_platform_copts(),
|
|
features = ["fully_static_link"],
|
|
)
|