0

arc: Handle invalid dummy FD in ProtectedBufferManager

This CL makes ProtectedBufferManager::ImportDummyFd() handle an invalid
|dummy_fd| and ensures that all the call sites of that method handle a
nullptr return value.

Bug: b:195769334
Test: None
Change-Id: Ie487e8c6018c61d87c3cdd742713d25a5769674d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3397512
Reviewed-by: Chih-Yu Huang <akahuang@chromium.org>
Commit-Queue: Andres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#961207}
This commit is contained in:
Andres Calderon Jaramillo
2022-01-20 00:28:02 +00:00
committed by Chromium LUCI CQ
parent 59e1192bd7
commit fe69e025e9

@ -404,6 +404,8 @@ ProtectedBufferManager::GetProtectedSharedMemoryRegionFor(
base::ScopedFD dummy_fd) {
uint32_t id = 0;
auto pixmap = ImportDummyFd(std::move(dummy_fd), &id);
if (!pixmap)
return {};
base::AutoLock lock(buffer_map_lock_);
const auto& iter = buffer_map_.find(id);
@ -418,6 +420,8 @@ ProtectedBufferManager::GetProtectedNativePixmapHandleFor(
base::ScopedFD dummy_fd) {
uint32_t id = 0;
auto pixmap = ImportDummyFd(std::move(dummy_fd), &id);
if (!pixmap)
return gfx::NativePixmapHandle();
base::AutoLock lock(buffer_map_lock_);
const auto& iter = buffer_map_.find(id);
@ -451,6 +455,8 @@ ProtectedBufferManager::GetProtectedNativePixmapFor(
base::ScopedFD dummy_fd(HANDLE_EINTR(dup(handle.planes[0].fd.get())));
uint32_t id = 0;
auto pixmap = ImportDummyFd(std::move(dummy_fd), &id);
if (!pixmap)
return nullptr;
base::AutoLock lock(buffer_map_lock_);
const auto& iter = buffer_map_.find(id);
@ -477,6 +483,8 @@ scoped_refptr<gfx::NativePixmap> ProtectedBufferManager::ImportDummyFd(
uint32_t* id) const {
// 0 is an invalid handle id.
*id = 0;
if (!dummy_fd.is_valid())
return nullptr;
// Import dummy_fd to acquire its unique id.
// CreateNativePixmapFromHandle() takes ownership and will close the handle