platform_hardware_interfaces/minijail/HardwareMinijail.cpp
Jeff Vander Stoep ed95043d64 configstore: sandbox with seccomp filter
Configstore HAL is accessible to third party apps and thus requires
a tight sandbox that reflects the limited system access this HAL
needs.

We use two primary mechanisms to sandbox configstore, selinux and
seccomp, with the goal of restricting its access to userspace and
the kernel. The addition of a seccomp filter is primarily aimed
at reducing the kernel's attack surface that is reachable by
configstore HAL.

Seccomp filters are architecture dependent, so filters need to be
added for each architecture. This change adds a seccomp filter for
arm64 and issues a non-fatal runtime warning for other architectures
which still require a seccomp filter.

Bug: 36453956
Test: boot Marlin and Angler. Verify that configstore is not aborting
    due to seccomp violations.
Test: "cat proc/<configstore pid>/status | grep seccomp " returns:
    seccomp: 2
    Which indicates that configstore is using seccomp-bpf.

Change-Id: Iab014ff357b7329085a5e18a92f51838d2c72371
2017-07-12 12:58:01 -07:00

45 lines
1.4 KiB
C++

//
// Copyright (C) 2017 The Android Open Source Project
//
// 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 <android-base/logging.h>
#include <libminijail.h>
#include <hwminijail/HardwareMinijail.h>
namespace android {
namespace hardware {
void SetupMinijail(const std::string& seccomp_policy_path) {
if (access(seccomp_policy_path.c_str(), R_OK) == -1) {
LOG(WARNING) << "Could not find seccomp policy file at: " << seccomp_policy_path;
return;
}
struct minijail* jail = minijail_new();
if (jail == NULL) {
LOG(FATAL) << "Failed to create minijail.";
}
minijail_no_new_privs(jail);
minijail_log_seccomp_filter_failures(jail);
minijail_use_seccomp_filter(jail);
minijail_parse_seccomp_filters(jail, seccomp_policy_path.c_str());
minijail_enter(jail);
minijail_destroy(jail);
}
} // namespace hardware
} // namespace android