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

Side by Side Diff: ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.cc

Issue 2302053003: ozone: Validate the memory buffer used. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" 5 #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/mman.h> 9 #include <sys/mman.h>
10 #include <xf86drm.h> 10 #include <xf86drm.h>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 DCHECK_GE(dmabuf_fd, 0); 62 DCHECK_GE(dmabuf_fd, 0);
63 return base::WrapUnique( 63 return base::WrapUnique(
64 new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride)); 64 new ClientNativePixmapDmaBuf(dmabuf_fd, size, stride));
65 } 65 }
66 66
67 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd, 67 ClientNativePixmapDmaBuf::ClientNativePixmapDmaBuf(int dmabuf_fd,
68 const gfx::Size& size, 68 const gfx::Size& size,
69 int stride) 69 int stride)
70 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) { 70 : dmabuf_fd_(dmabuf_fd), size_(size), stride_(stride) {
71 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf"); 71 TRACE_EVENT0("drm", "ClientNativePixmapDmaBuf");
72 size_t map_size = stride_ * size_.height(); 72 base::CheckedNumeric<size_t> map_size = stride_;
73 data_ = mmap(nullptr, map_size, (PROT_READ | PROT_WRITE), MAP_SHARED, 73 map_size *= size_.height();
74 dmabuf_fd, 0); 74 data_ = mmap(nullptr, map_size.ValueOrDie(), (PROT_READ | PROT_WRITE),
rjkroege 2016/09/01 20:45:05 Won't this will kill the caller if the value is in
sadrul 2016/09/02 03:00:19 As discussed offline, I have changed this code to
75 MAP_SHARED, dmabuf_fd, 0);
75 if (data_ == MAP_FAILED) { 76 if (data_ == MAP_FAILED) {
76 PLOG(ERROR) << "Failed mmap()."; 77 PLOG(ERROR) << "Failed mmap().";
77 base::TerminateBecauseOutOfMemory(map_size); 78 base::TerminateBecauseOutOfMemory(map_size.ValueOrDie());
78 } 79 }
79 } 80 }
80 81
81 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() { 82 ClientNativePixmapDmaBuf::~ClientNativePixmapDmaBuf() {
82 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf"); 83 TRACE_EVENT0("drm", "~ClientNativePixmapDmaBuf");
83 size_t size = stride_ * size_.height(); 84 size_t size = stride_ * size_.height();
84 int ret = munmap(data_, size); 85 int ret = munmap(data_, size);
85 DCHECK(!ret); 86 DCHECK(!ret);
86 } 87 }
87 88
88 void* ClientNativePixmapDmaBuf::Map() { 89 void* ClientNativePixmapDmaBuf::Map() {
89 TRACE_EVENT0("drm", "DmaBuf:Map"); 90 TRACE_EVENT0("drm", "DmaBuf:Map");
90 PrimeSyncStart(dmabuf_fd_.get()); 91 PrimeSyncStart(dmabuf_fd_.get());
91 return data_; 92 return data_;
92 } 93 }
93 94
94 void ClientNativePixmapDmaBuf::Unmap() { 95 void ClientNativePixmapDmaBuf::Unmap() {
95 TRACE_EVENT0("drm", "DmaBuf:Unmap"); 96 TRACE_EVENT0("drm", "DmaBuf:Unmap");
96 PrimeSyncEnd(dmabuf_fd_.get()); 97 PrimeSyncEnd(dmabuf_fd_.get());
97 } 98 }
98 99
99 void ClientNativePixmapDmaBuf::GetStride(int* stride) const { 100 void ClientNativePixmapDmaBuf::GetStride(int* stride) const {
100 *stride = stride_; 101 *stride = stride_;
101 } 102 }
102 103
103 } // namespace ui 104 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698