Title: [187030] trunk/Source/WebKit2
- Revision
- 187030
- Author
- [email protected]
- Date
- 2015-07-20 13:06:27 -0700 (Mon, 20 Jul 2015)
Log Message
[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 Žan Doberšek.
* 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.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (187029 => 187030)
--- trunk/Source/WebKit2/ChangeLog 2015-07-20 19:50:54 UTC (rev 187029)
+++ trunk/Source/WebKit2/ChangeLog 2015-07-20 20:06:27 UTC (rev 187030)
@@ -1,3 +1,25 @@
+2015-07-20 Michael Catanzaro <[email protected]>
+
+ [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 Žan Doberšek.
+
+ * 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-20 Csaba Osztrogonác <[email protected]>
Fix the !ENABLE(VIDEO) build after r186396
Modified: trunk/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp (187029 => 187030)
--- trunk/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp 2015-07-20 19:50:54 UTC (rev 187029)
+++ trunk/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp 2015-07-20 20:06:27 UTC (rev 187030)
@@ -320,16 +320,11 @@
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];
Modified: trunk/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp (187029 => 187030)
--- trunk/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp 2015-07-20 19:50:54 UTC (rev 187029)
+++ trunk/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp 2015-07-20 20:06:27 UTC (rev 187030)
@@ -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 @@
case __NR_rt_sigaction:
return SigactionSyscall::createFromContext(mcontext);
default:
- CRASH();
+ reportUnexpectedSyscall(mcontext->gregs[REG_SYSCALL]);
+ ASSERT_NOT_REACHED();
}
return nullptr;
Modified: trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp (187029 => 187030)
--- trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp 2015-07-20 19:50:54 UTC (rev 187029)
+++ trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp 2015-07-20 20:06:27 UTC (rev 187030)
@@ -97,7 +97,13 @@
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,23 @@
#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";
+ }
+
+ ASSERT_NOT_REACHED();
+ return "unknown action";
+}
+
} // namespace WebKit
#endif // ENABLE(SECCOMP_FILTERS)
Modified: trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h (187029 => 187030)
--- trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h 2015-07-20 19:50:54 UTC (rev 187029)
+++ trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h 2015-07-20 20:06:27 UTC (rev 187030)
@@ -52,6 +52,8 @@
void addDefaultWebProcessPolicy(const WebProcessCreationParameters&);
+ static const char* permissionToString(Permission);
+
private:
typedef HashMap<String, int> PermissionMap;
PermissionMap m_filePermission;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes