WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-142980-20150719181116.patch (text/plain), 6.76 KB, created by
Michael Catanzaro
on 2015-07-19 16:12:29 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Michael Catanzaro
Created:
2015-07-19 16:12:29 PDT
Size:
6.76 KB
patch
obsolete
>Subversion Revision: 187015 >diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog >index 6c506a0938feb4325f1f587d499bf564cc00c25f..7b0d59a502fccfaa8f8058b798720cbc19c43ebe 100644 >--- a/Source/WebKit2/ChangeLog >+++ b/Source/WebKit2/ChangeLog >@@ -1,5 +1,27 @@ > 2015-07-19 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. >+ >+ 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-07-19 Michael Catanzaro <mcatanzaro@igalia.com> >+ > Unreviewed, placate -Wmismatched-tags after r187011 > > It's basically bug #146990 again. Oops. >diff --git a/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp b/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp >index 591f089a7b11366f6b5b71ad73dac8e9491eb3a8..162049d14b4bab9070f570b5f8a7836f63eee35d 100644 >--- a/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp >+++ b/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp >@@ -320,16 +320,11 @@ 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); >+ } > > while (true) { > char buffer[messageMaxSize]; >diff --git a/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp b/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp >index 0d4afd0dd22309d90ebefa3ee67b46138334a5e7..de97d31714fb87e2a6d4690f351adb816ea3370f 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 >@@ -32,10 +33,47 @@ > #include "OpenSyscall.h" > #include "SigactionSyscall.h" > #include "SigprocmaskSyscall.h" >+#include <limits> > #include <seccomp.h> >+#include <string.h> >+#include <unistd.h> > > namespace WebKit { > >+// The redundant "constexpr const" is to placate Clang's -Wwritable-strings. >+static constexpr const char* const message = "Blocked unexpected syscall: "; >+ >+// Since "sprintf" is not signal-safe, reimplement %d here. Based on code from >+// http://outflux.net/teach-seccomp by Will Drewry and Kees Cook, released under >+// the Chromium BSD license. >+static void writeUnsignedInt(char* buf, unsigned val) >+{ >+ int width = 0; >+ unsigned tens; >+ >+ if (!val) { >+ 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]; >+#if defined(__has_builtin) && __has_builtin(__builtin_strlen) >+ static_assert(__builtin_strlen(message) + std::numeric_limits<int>::digits10 + 1 < sizeof(buf), "Buffer too small"); >+#endif >+ strcpy(buf, message); >+ writeUnsignedInt(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 +92,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 1ef946cb5f9175fb3bc8de4bd67346bb4ff203d7..1a102d70cc6beca61338b0389db77e4c131ecf61 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) || 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 54a6e91362308f398a262cc4a3c374d7a05e76ba..b2680dc9ab08811428e8d968d0852e757311f792 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