WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
[Linux] Seccomp Filters: Make it easier to debug blocked syscalls
bug-142980-20150323155353.patch (text/plain), 8.27 KB, created by
Michael Catanzaro
on 2015-03-23 13:54:30 PDT
(
hide
)
Description:
[Linux] Seccomp Filters: Make it easier to debug blocked syscalls
Filename:
MIME Type:
Creator:
Michael Catanzaro
Created:
2015-03-23 13:54:30 PDT
Size:
8.27 KB
patch
obsolete
>Subversion Revision: 181825 >diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog >index b0cac22e3e0ce409ab73e71056f185f220a36a71..471ac892e51b5ee0c86ba8446880aea313eb13f9 100644 >--- a/Source/WebKit2/ChangeLog >+++ b/Source/WebKit2/ChangeLog >@@ -1,3 +1,26 @@ >+2015-03-23 Michael Catanzaro <mcatanzaro@igalia.com> >+ >+ [Seccomp] Should be easier to debug blocked syscalls >+ https://bugs.webkit.org/show_bug.cgi?id=142980 >+ >+ These should be printed even when not running in debug mode. There is no >+ value in hiding errors from release build users. Also, I don't have the >+ patience to use a debug build for development. >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * Shared/linux/SeccompFilters/SeccompBroker.cpp: >+ (WebKit::SeccompBroker::runLoop): Don't close stderr et. al. in release builds. >+ * Shared/linux/SeccompFilters/Syscall.cpp: >+ (WebKit::write_uint): Added. >+ (WebKit::reportUnexpectedSyscall): Added. >+ (WebKit::Syscall::createFromContext): Call reportUnexpectedSyscall. Also, no need to crash >+ here in release builds. >+ * Shared/linux/SeccompFilters/SyscallPolicy.cpp: >+ (WebKit::SyscallPolicy::hasPermissionForPath): Print a warning when access is denied. >+ (WebKit::SyscallPolicy::permissionToString): Added. >+ * Shared/linux/SeccompFilters/SyscallPolicy.h: Add permissionToString. >+ > 2015-01-04 Michael Catanzaro <mcatanzaro@igalia.com> > > [GTK] Add seccomp filters support >diff --git a/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp b/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp >index 1ca63ffdb7fa75c5b987d87b9d446b0e3cc859f3..234e3827fa89bcd7b80b19b2feb085380d2296b1 100644 >--- a/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp >+++ b/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp >@@ -320,14 +320,8 @@ void SeccompBroker::initialize() > > NO_RETURN void SeccompBroker::runLoop(int socket) > { >-#ifndef NDEBUG >- int i = STDERR_FILENO + 1; >-#else >- int i = 0; >-#endif >- // Close all inherited file descriptors other >- // than the socket to the sandboxed process. >- for (; i < FD_SETSIZE; ++i) >+ // Close unnecessary inherited file descriptors. >+ for (int i = STDERR_FILENO + 1; i < FD_SETSIZE; ++i) > if (i != socket) > close(i); > >diff --git a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp b/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp >index 0d4afd0dd22309d90ebefa3ee67b46138334a5e7..ca08bbfcfd43e0f899e16e15b7f359e5b29ab831 100644 >--- a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp >+++ b/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp >@@ -1,5 +1,6 @@ > /* > * Copyright (C) 2013 Intel Corporation. All rights reserved. >+ * Copyright (C) 2015 Igalia S.L. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -23,6 +24,41 @@ > * THE POSSIBILITY OF SUCH DAMAGE. > */ > >+/* >+ * Safe printing based on code from http://outflux.net/teach-seccomp >+ * >+ * Copyright (c) 2012 The Chromium OS Authors <chromium-os-dev@chromium.org> >+ * Authors: >+ * Will Drewry <wad@chromium.org> >+ * Kees Cook <keescook@chromium.org> >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions are >+ * met: >+ * >+ * * Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * * Redistributions in binary form must reproduce the above >+ * copyright notice, this list of conditions and the following disclaimer >+ * in the documentation and/or other materials provided with the >+ * distribution. >+ * * Neither the name of Google Inc. nor the names of its >+ * contributors may be used to endorse or promote products derived from >+ * this software without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ > #include "config.h" > #include "Syscall.h" > >@@ -32,10 +68,42 @@ > #include "OpenSyscall.h" > #include "SigactionSyscall.h" > #include "SigprocmaskSyscall.h" >+#include <limits> > #include <seccomp.h> >+#include <string.h> >+#include <unistd.h> > > namespace WebKit { > >+static const char* const msg_needed = "Blocked unexpected syscall: "; >+ >+// Since "sprintf" is not signal-safe, reimplement %d here. >+static void write_uint(char* buf, unsigned val) >+{ >+ int width = 0; >+ unsigned tens; >+ >+ if (val == 0) { >+ strcpy(buf, "0"); >+ return; >+ } >+ for (tens = val; tens; tens /= 10) >+ ++width; >+ buf[width] = '\0'; >+ for (tens = val; tens; tens /= 10) >+ buf[--width] = '0' + (tens % 10); >+} >+ >+static void reportUnexpectedSyscall(int syscall) >+{ >+ char buf[128]; >+ static_assert(strlen(msg_needed) + std::numeric_limits<int>::digits10 + 1 < sizeof(buf), "Buffer too small"); >+ strcpy(buf, msg_needed); >+ write_uint(buf + strlen(buf), syscall); >+ strcat(buf, "\n"); >+ write(STDERR_FILENO, buf, strlen(buf)); >+} >+ > std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext) > { > mcontext_t* mcontext = &ucontext->uc_mcontext; >@@ -54,7 +122,8 @@ std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext) > case __NR_rt_sigaction: > return SigactionSyscall::createFromContext(mcontext); > default: >- CRASH(); >+ reportUnexpectedSyscall(mcontext->gregs[REG_SYSCALL]); >+ ASSERT_NOT_REACHED(); > } > > return nullptr; >diff --git a/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp b/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp >index 2d315d785bc0923a348571365f9ee439a021bee5..86d12995eca66af063f13f870e1fc57a5ad61275 100644 >--- a/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp >+++ b/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp >@@ -97,7 +97,13 @@ bool SyscallPolicy::hasPermissionForPath(const char* path, Permission permission > free(basePath); > free(canonicalPath); > >- return (permission & policy->value) == permission; >+ if ((permission & policy->value) == permission) >+ return true; >+ >+ // Don't warn if the file doesn't exist at all. >+ if (access(path, F_OK) == 0 || errno != ENOENT) >+ fprintf(stderr, "Blocked impermissible %s access to %s\n", SyscallPolicy::permissionToString(permission), path); >+ return false; > } > > void SyscallPolicy::addFilePermission(const String& path, Permission permission) >@@ -256,6 +262,21 @@ void SyscallPolicy::addDefaultWebProcessPolicy(const WebProcessCreationParameter > #endif > } > >+const char* SyscallPolicy::permissionToString(Permission permission) >+{ >+ switch (permission) { >+ case Read: >+ return "read"; >+ case Write: >+ return "write"; >+ case ReadAndWrite: >+ return "read/write"; >+ case NotAllowed: >+ return "disallowed"; >+ } >+ CRASH(); >+} >+ > } // namespace WebKit > > #endif // ENABLE(SECCOMP_FILTERS) >diff --git a/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h b/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h >index cae0e45d2f8c2e77d058acbc1c7359869c622f3c..4b3886e6e90a9fc901799bf7bd6e58c54aea8f26 100644 >--- a/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h >+++ b/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h >@@ -52,6 +52,8 @@ public: > > void addDefaultWebProcessPolicy(const WebProcessCreationParameters&); > >+ static const char* permissionToString(Permission); >+ > private: > typedef HashMap<String, int> PermissionMap; > PermissionMap m_filePermission;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 142980
:
249264
|
249265
|
249274
|
257067
|
257114