|
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 32-41
a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp_sec2
|
| 32 |
#include "OpenSyscall.h" |
33 |
#include "OpenSyscall.h" |
| 33 |
#include "SigactionSyscall.h" |
34 |
#include "SigactionSyscall.h" |
| 34 |
#include "SigprocmaskSyscall.h" |
35 |
#include "SigprocmaskSyscall.h" |
|
|
36 |
#include <limits> |
| 35 |
#include <seccomp.h> |
37 |
#include <seccomp.h> |
|
|
38 |
#include <string.h> |
| 39 |
#include <unistd.h> |
| 36 |
|
40 |
|
| 37 |
namespace WebKit { |
41 |
namespace WebKit { |
| 38 |
|
42 |
|
|
|
43 |
// The redundant "constexpr const" is to placate Clang's -Wwritable-strings. |
| 44 |
static constexpr const char* const message = "Blocked unexpected syscall: "; |
| 45 |
|
| 46 |
// Since "sprintf" is not signal-safe, reimplement %d here. Based on code from |
| 47 |
// http://outflux.net/teach-seccomp by Will Drewry and Kees Cook, released under |
| 48 |
// the Chromium BSD license. |
| 49 |
static void writeUnsignedInt(char* buf, unsigned val) |
| 50 |
{ |
| 51 |
int width = 0; |
| 52 |
unsigned tens; |
| 53 |
|
| 54 |
if (!val) { |
| 55 |
strcpy(buf, "0"); |
| 56 |
return; |
| 57 |
} |
| 58 |
for (tens = val; tens; tens /= 10) |
| 59 |
++width; |
| 60 |
buf[width] = '\0'; |
| 61 |
for (tens = val; tens; tens /= 10) |
| 62 |
buf[--width] = '0' + (tens % 10); |
| 63 |
} |
| 64 |
|
| 65 |
static void reportUnexpectedSyscall(int syscall) |
| 66 |
{ |
| 67 |
char buf[128]; |
| 68 |
#if defined(__has_builtin) && __has_builtin(__builtin_strlen) |
| 69 |
static_assert(__builtin_strlen(message) + std::numeric_limits<int>::digits10 + 1 < sizeof(buf), "Buffer too small"); |
| 70 |
#endif |
| 71 |
strcpy(buf, message); |
| 72 |
writeUnsignedInt(buf + strlen(buf), syscall); |
| 73 |
strcat(buf, "\n"); |
| 74 |
write(STDERR_FILENO, buf, strlen(buf)); |
| 75 |
} |
| 76 |
|
| 39 |
std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext) |
77 |
std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext) |
| 40 |
{ |
78 |
{ |
| 41 |
mcontext_t* mcontext = &ucontext->uc_mcontext; |
79 |
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_sec3
|
| 54 |
case __NR_rt_sigaction: |
92 |
case __NR_rt_sigaction: |
| 55 |
return SigactionSyscall::createFromContext(mcontext); |
93 |
return SigactionSyscall::createFromContext(mcontext); |
| 56 |
default: |
94 |
default: |
| 57 |
CRASH(); |
95 |
reportUnexpectedSyscall(mcontext->gregs[REG_SYSCALL]); |
|
|
96 |
ASSERT_NOT_REACHED(); |
| 58 |
} |
97 |
} |
| 59 |
|
98 |
|
| 60 |
return nullptr; |
99 |
return nullptr; |