Changeset 187030 in webkit


Ignore:
Timestamp:
Jul 20, 2015 1:06:27 PM (9 years ago)
Author:
Michael Catanzaro
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.
Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r187029 r187030  
     12015-07-20  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [Seccomp] Should be easier to debug blocked syscalls
     4        https://bugs.webkit.org/show_bug.cgi?id=142980
     5
     6        These should be printed even when not running in debug mode. There is no
     7        value in hiding errors from release build users.
     8
     9        Reviewed by Žan Doberšek.
     10
     11        * Shared/linux/SeccompFilters/SeccompBroker.cpp:
     12        (WebKit::SeccompBroker::runLoop): Don't close stderr et. al. in release builds.
     13        * Shared/linux/SeccompFilters/Syscall.cpp:
     14        (WebKit::write_uint): Added.
     15        (WebKit::reportUnexpectedSyscall): Added.
     16        (WebKit::Syscall::createFromContext): Call reportUnexpectedSyscall. Also, no need to crash
     17        here in release builds.
     18        * Shared/linux/SeccompFilters/SyscallPolicy.cpp:
     19        (WebKit::SyscallPolicy::hasPermissionForPath): Print a warning when access is denied.
     20        (WebKit::SyscallPolicy::permissionToString): Added.
     21        * Shared/linux/SeccompFilters/SyscallPolicy.h: Add permissionToString.
     22
    1232015-07-20  Csaba Osztrogonác  <ossy@webkit.org>
    224
  • trunk/Source/WebKit2/Shared/linux/SeccompFilters/SeccompBroker.cpp

    r186839 r187030  
    321321NO_RETURN void SeccompBroker::runLoop(int socket)
    322322{
    323 #ifndef NDEBUG
    324     int i = STDERR_FILENO + 1;
    325 #else
    326     int i = 0;
    327 #endif
    328     // Close all inherited file descriptors other
    329     // than the socket to the sandboxed process.
    330     for (; i < FD_SETSIZE; ++i)
     323    // Close unnecessary inherited file descriptors.
     324    for (int i = STDERR_FILENO + 1; i < FD_SETSIZE; ++i) {
    331325        if (i != socket)
    332326            close(i);
     327    }
    333328
    334329    while (true) {
  • trunk/Source/WebKit2/Shared/linux/SeccompFilters/Syscall.cpp

    r161156 r187030  
    11/*
    22 * Copyright (C) 2013 Intel Corporation. All rights reserved.
     3 * Copyright (C) 2015 Igalia S.L.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334#include "SigactionSyscall.h"
    3435#include "SigprocmaskSyscall.h"
     36#include <limits>
    3537#include <seccomp.h>
     38#include <string.h>
     39#include <unistd.h>
    3640
    3741namespace WebKit {
     42
     43// The redundant "constexpr const" is to placate Clang's -Wwritable-strings.
     44static 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.
     49static 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
     65static 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}
    3876
    3977std::unique_ptr<Syscall> Syscall::createFromContext(ucontext_t* ucontext)
     
    5593        return SigactionSyscall::createFromContext(mcontext);
    5694    default:
    57         CRASH();
     95        reportUnexpectedSyscall(mcontext->gregs[REG_SYSCALL]);
     96        ASSERT_NOT_REACHED();
    5897    }
    5998
  • trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.cpp

    r186810 r187030  
    9898    free(canonicalPath);
    9999
    100     return (permission & policy->value) == permission;
     100    if ((permission & policy->value) == permission)
     101        return true;
     102
     103    // Don't warn if the file doesn't exist at all.
     104    if (!access(path, F_OK) || errno != ENOENT)
     105        fprintf(stderr, "Blocked impermissible %s access to %s\n", SyscallPolicy::permissionToString(permission), path);
     106    return false;
    101107}
    102108
     
    257263}
    258264
     265const char* SyscallPolicy::permissionToString(Permission permission)
     266{
     267    switch (permission) {
     268    case Read:
     269        return "read";
     270    case Write:
     271        return "write";
     272    case ReadAndWrite:
     273        return "read/write";
     274    case NotAllowed:
     275        return "disallowed";
     276    }
     277
     278    ASSERT_NOT_REACHED();
     279    return "unknown action";
     280}
     281
    259282} // namespace WebKit
    260283
  • trunk/Source/WebKit2/Shared/linux/SeccompFilters/SyscallPolicy.h

    r186893 r187030  
    5353    void addDefaultWebProcessPolicy(const WebProcessCreationParameters&);
    5454
     55    static const char* permissionToString(Permission);
     56
    5557private:
    5658    typedef HashMap<String, int> PermissionMap;
Note: See TracChangeset for help on using the changeset viewer.