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

Side by Side Diff: sandbox/win/src/heap_helper.cc

Issue 2726733003: CSRSS lockdown: destroy CSRSS heap (Closed)
Patch Set: refactor heap code to heap_helper, add some explicit tests of these heap_helper functions Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2017 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 "sandbox/win/src/heap_helper.h"
6
7 #include <windows.h>
8
9 #include "base/memory/ref_counted.h"
10
11 namespace sandbox {
12
13 // These are undocumented, but readily found on the internet.
14 #define HEAP_CLASS_8 0x00008000 // CSR port heap
15 #define HEAP_CLASS_MASK 0x0000f000
16
17 // This structure is not documented, but we only care about the flags field.
18 struct _HEAP {
19 char reserved[0x70];
20 DWORD flags;
21 };
22
23 DWORD HeapFlags(HANDLE handle) {
24 _HEAP* heap = reinterpret_cast<_HEAP*>(handle);
Will Harris 2017/03/22 19:21:49 is there any validation that can be done here that
liamjm (20p) 2017/04/14 17:27:20 I've added nullptr checks. We could use ntdll!Rtl
25 return heap->flags;
26 }
27
28 HANDLE FindCsrPortHeap() {
29 DWORD number_of_heaps = ::GetProcessHeaps(0, NULL);
30 std::unique_ptr<HANDLE[]> all_heaps(new HANDLE[number_of_heaps]);
31 if (::GetProcessHeaps(number_of_heaps, all_heaps.get()) != number_of_heaps)
32 return nullptr;
33
34 // Let's search for the CSR port heap handle, which we identify purely based
Will Harris 2017/03/22 19:21:49 nit: in chromium convention is to avoid use of 'us
liamjm (20p) 2017/04/14 17:27:20 Done.
35 // on flags.
36 HANDLE csr_port_heap = nullptr;
37 for (size_t i = 0; i < number_of_heaps; ++i) {
38 HANDLE handle = all_heaps[i];
39 DWORD flags = HeapFlags(handle);
40 if ((flags & HEAP_CLASS_MASK) == HEAP_CLASS_8) {
41 if (nullptr != csr_port_heap) {
42 LOG(ERROR) << "Found multiple suitable CSR Port heaps";
43 return nullptr;
44 }
45 csr_port_heap = handle;
46 }
47 }
48 return csr_port_heap;
49 }
50
51 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698