|
Lines 1-5
a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp_sec1
|
| 1 |
/* |
1 |
/* |
| 2 |
* Copyright (C) 2013 Intel Corporation. All rights reserved. |
2 |
* Copyright (C) 2013 Intel Corporation. All rights reserved. |
|
|
3 |
* Copyright (C) 2015 Igalia S.L. |
| 3 |
* |
4 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
6 |
* modification, are permitted provided that the following conditions |
|
Lines 23-28
a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp_sec2
|
| 23 |
* THE POSSIBILITY OF SUCH DAMAGE. |
24 |
* THE POSSIBILITY OF SUCH DAMAGE. |
| 24 |
*/ |
25 |
*/ |
| 25 |
|
26 |
|
|
|
27 |
/* |
| 28 |
* Safe printing based on code from http://outflux.net/teach-seccomp |
| 29 |
* |
| 30 |
* Copyright (c) 2012 The Chromium OS Authors <chromium-os-dev@chromium.org> |
| 31 |
* Authors: |
| 32 |
* Will Drewry <wad@chromium.org> |
| 33 |
* Kees Cook <keescook@chromium.org> |
| 34 |
* |
| 35 |
* Redistribution and use in source and binary forms, with or without |
| 36 |
* modification, are permitted provided that the following conditions are |
| 37 |
* met: |
| 38 |
* |
| 39 |
* * Redistributions of source code must retain the above copyright |
| 40 |
* notice, this list of conditions and the following disclaimer. |
| 41 |
* * Redistributions in binary form must reproduce the above |
| 42 |
* copyright notice, this list of conditions and the following disclaimer |
| 43 |
* in the documentation and/or other materials provided with the |
| 44 |
* distribution. |
| 45 |
* * Neither the name of Google Inc. nor the names of its |
| 46 |
* contributors may be used to endorse or promote products derived from |
| 47 |
* this software without specific prior written permission. |
| 48 |
* |
| 49 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 50 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 51 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 52 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 53 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 54 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 55 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 56 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 57 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 58 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 59 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 60 |
*/ |
| 61 |
|
| 26 |
#include "config.h" |
62 |
#include "config.h" |
| 27 |
#include "Syscall.h" |
63 |
#include "Syscall.h" |
| 28 |
|
64 |
|
|
Lines 32-41
a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp_sec3
|
| 32 |
#include "OpenSyscall.h" |
68 |
#include "OpenSyscall.h" |
| 33 |
#include "SigactionSyscall.h" |
69 |
#include "SigactionSyscall.h" |
| 34 |
#include "SigprocmaskSyscall.h" |
70 |
#include "SigprocmaskSyscall.h" |
|
|
71 |
#include <limits> |
| 35 |
#include <seccomp.h> |
72 |
#include <seccomp.h> |
|
|
73 |
#include <string.h> |
| 74 |
#include <unistd.h> |
| 36 |
|
75 |
|
| 37 |
namespace WebKit { |
76 |
namespace WebKit { |
| 38 |
|
77 |
|
|
|
78 |
static const char* const message = "Blocked unexpected syscall: "; |
| 79 |
|
| 80 |
// Since "sprintf" is not signal-safe, reimplement %d here. |
| 81 |
static void writeUnsignedInt(char* buf, unsigned val) |
| 82 |
{ |
| 83 |
int width = 0; |
| 84 |
unsigned tens; |
| 85 |
|
| 86 |
if (!val) { |
| 87 |
strcpy(buf, "0"); |
| 88 |
return; |
| 89 |
} |
| 90 |
for (tens = val; tens; tens /= 10) |
| 91 |
++width; |
| 92 |
buf[width] = '\0'; |
| 93 |
for (tens = val; tens; tens /= 10) |
| 94 |
buf[--width] = '0' + (tens % 10); |
| 95 |
} |
| 96 |
|
| 97 |
static void reportUnexpectedSyscall(int syscall) |
| 98 |
{ |
| 99 |
char buf[128]; |
| 100 |
static_assert(strlen(message) + std::numeric_limits<int>::digits10 + 1 < sizeof(buf), "Buffer too small"); |
| 101 |
strcpy(buf, message); |
| 102 |
writeUnsignedInt(buf + strlen(buf), syscall); |
| 103 |
strcat(buf, "\n"); |
| 104 |
write(STDERR_FILENO, buf, strlen(buf)); |
| 105 |
} |
| 106 |
|
| 39 |
std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext) |
107 |
std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext) |
| 40 |
{ |
108 |
{ |
| 41 |
mcontext_t* mcontext = &ucontext->uc_mcontext; |
109 |
mcontext_t* mcontext = &ucontext->uc_mcontext; |
|
Lines 54-60
std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext)
a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp_sec4
|
| 54 |
case __NR_rt_sigaction: |
122 |
case __NR_rt_sigaction: |
| 55 |
return SigactionSyscall::createFromContext(mcontext); |
123 |
return SigactionSyscall::createFromContext(mcontext); |
| 56 |
default: |
124 |
default: |
| 57 |
CRASH(); |
125 |
reportUnexpectedSyscall(mcontext->gregs[REG_SYSCALL]); |
|
|
126 |
ASSERT_NOT_REACHED(); |
| 58 |
} |
127 |
} |
| 59 |
|
128 |
|
| 60 |
return nullptr; |
129 |
return nullptr; |