Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: sandbox/linux/seccomp/madvise.cc

Issue 3225010: Pull seccomp-sandbox in via DEPS rather than using an in-tree copy... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/linux/seccomp/linux_syscall_support.h ('k') | sandbox/linux/seccomp/maps.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "debug.h"
6 #include "sandbox_impl.h"
7
8 namespace playground {
9
10 long Sandbox::sandbox_madvise(void* start, size_t length, int advice) {
11 long long tm;
12 Debug::syscall(&tm, __NR_madvise, "Executing handler");
13 struct {
14 int sysnum;
15 long long cookie;
16 MAdvise madvise_req;
17 } __attribute__((packed)) request;
18 request.sysnum = __NR_madvise;
19 request.cookie = cookie();
20 request.madvise_req.start = start;
21 request.madvise_req.len = length;
22 request.madvise_req.advice = advice;
23
24 long rc;
25 SysCalls sys;
26 if (write(sys, processFdPub(), &request, sizeof(request)) !=
27 sizeof(request) ||
28 read(sys, threadFdPub(), &rc, sizeof(rc)) != sizeof(rc)) {
29 die("Failed to forward madvise() request [sandbox]");
30 }
31 Debug::elapsed(tm, __NR_madvise);
32 return rc;
33 }
34
35 bool Sandbox::process_madvise(int parentMapsFd, int sandboxFd, int threadFdPub,
36 int threadFd, SecureMem::Args* mem) {
37 // Read request
38 MAdvise madvise_req;
39 SysCalls sys;
40 if (read(sys, sandboxFd, &madvise_req, sizeof(madvise_req)) !=
41 sizeof(madvise_req)) {
42 die("Failed to read parameters for madvise() [process]");
43 }
44 int rc = -EINVAL;
45 switch (madvise_req.advice) {
46 case MADV_NORMAL:
47 case MADV_RANDOM:
48 case MADV_SEQUENTIAL:
49 case MADV_WILLNEED:
50 ok:
51 SecureMem::sendSystemCall(threadFdPub, false, -1, mem, __NR_madvise,
52 madvise_req.start, madvise_req.len,
53 madvise_req.advice);
54 return true;
55 default:
56 // All other flags to madvise() are potential dangerous (as opposed to
57 // merely affecting overall performance). Do not allow them on memory
58 // ranges that were part of the original mappings.
59 void *stop = reinterpret_cast<void *>(
60 (char *)madvise_req.start + madvise_req.len);
61 ProtectedMap::const_iterator iter = protectedMap_.lower_bound(
62 (void *)madvise_req.start);
63 if (iter != protectedMap_.begin()) {
64 --iter;
65 }
66 for (; iter != protectedMap_.end() && iter->first < stop; ++iter) {
67 if (madvise_req.start < reinterpret_cast<void *>(
68 reinterpret_cast<char *>(iter->first) + iter->second) &&
69 stop > iter->first) {
70 SecureMem::abandonSystemCall(threadFd, rc);
71 return false;
72 }
73 }
74
75 // Changing attributes on memory regions that were newly mapped inside of
76 // the sandbox is OK.
77 goto ok;
78 }
79 }
80
81 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp/linux_syscall_support.h ('k') | sandbox/linux/seccomp/maps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698