1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef CONTRIB_TURBOJPEG_TURBOJPEG_SAPI_H_ 16 #define CONTRIB_TURBOJPEG_TURBOJPEG_SAPI_H_ 17 18 #include <syscall.h> 19 20 #include "sandboxed_api/util/fileops.h" 21 #include "turbojpeg_sapi.sapi.h" // NOLINT(build/include) 22 class TurboJpegSapiSandbox : public turbojpeg_sapi::TurboJPEGSandbox { 23 public: ModifyPolicy(sandbox2::PolicyBuilder *)24 std::unique_ptr<sandbox2::Policy> ModifyPolicy( 25 sandbox2::PolicyBuilder*) override { 26 return sandbox2::PolicyBuilder() 27 .AllowSystemMalloc() 28 .AllowRead() 29 .AllowStat() 30 .AllowWrite() 31 .AllowExit() 32 .AllowSyscalls({ 33 __NR_futex, 34 __NR_close, 35 __NR_lseek, 36 __NR_getpid, 37 __NR_clock_gettime, 38 }) 39 .AllowLlvmSanitizers() 40 .BuildOrDie(); 41 } 42 }; 43 44 #endif // CONTRIB_TURBOJPEG_TURBOJPEG_SAPI_H_ 45