Skip to content

Commit 6ed7e70

Browse files
Ilya Nikolaevskiymibrunin
authored andcommitted
[Backport] Security bug 1205059
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/chromium/src/+/3060058: [M90-LTS] Add locks and empty string checks to FakeV4L2Impl FakeV4L2Impl is crashed by fuzzer with some weird ASAN errors, which turned out to be a threading issue. (cherry picked from commit ac9dc1235e28f620d2fe0bfed096a3a7f69430b5) Bug: 1205059,1196302 Change-Id: Ieb3a917c9a4549b655862e69214774e183a70bc3 Commit-Queue: Ilya Nikolaevskiy <ilnik@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#883390} Reviewed-by: Ilya Nikolaevskiy <ilnik@chromium.org> Reviewed-by: Jana Grill <janagrill@google.com> Owners-Override: Jana Grill <janagrill@google.com> Commit-Queue: Zakhar Voit <voit@google.com> Cr-Commit-Position: refs/branch-heads/4430@{#1555} Cr-Branched-From: e5ce7dc4f7518237b3d9bb93cccca35d25216cbe-refs/heads/master@{#857950} Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
1 parent 2327f83 commit 6ed7e70

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

chromium/media/capture/video/linux/fake_v4l2_impl.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,16 @@ FakeV4L2Impl::~FakeV4L2Impl() = default;
380380

381381
void FakeV4L2Impl::AddDevice(const std::string& device_name,
382382
const FakeV4L2DeviceConfig& config) {
383+
base::AutoLock lock(lock_);
383384
device_configs_.emplace(device_name, config);
384385
}
385386

386387
int FakeV4L2Impl::open(const char* device_name, int flags) {
388+
if (!device_name)
389+
return kInvalidId;
390+
391+
base::AutoLock lock(lock_);
392+
387393
std::string device_name_as_string(device_name);
388394
auto device_configs_iter = device_configs_.find(device_name_as_string);
389395
if (device_configs_iter == device_configs_.end())
@@ -403,6 +409,7 @@ int FakeV4L2Impl::open(const char* device_name, int flags) {
403409
}
404410

405411
int FakeV4L2Impl::close(int fd) {
412+
base::AutoLock lock(lock_);
406413
auto device_iter = opened_devices_.find(fd);
407414
if (device_iter == opened_devices_.end())
408415
return kErrorReturnValue;
@@ -412,6 +419,7 @@ int FakeV4L2Impl::close(int fd) {
412419
}
413420

414421
int FakeV4L2Impl::ioctl(int fd, int request, void* argp) {
422+
base::AutoLock lock(lock_);
415423
auto device_iter = opened_devices_.find(fd);
416424
if (device_iter == opened_devices_.end())
417425
return EBADF;
@@ -518,6 +526,7 @@ void* FakeV4L2Impl::mmap(void* /*start*/,
518526
int flags,
519527
int fd,
520528
off_t offset) {
529+
base::AutoLock lock(lock_);
521530
if (flags & MAP_FIXED) {
522531
errno = EINVAL;
523532
return MAP_FAILED;
@@ -543,10 +552,12 @@ void* FakeV4L2Impl::mmap(void* /*start*/,
543552
}
544553

545554
int FakeV4L2Impl::munmap(void* start, size_t length) {
555+
base::AutoLock lock(lock_);
546556
return kSuccessReturnValue;
547557
}
548558

549559
int FakeV4L2Impl::poll(struct pollfd* ufds, unsigned int nfds, int timeout) {
560+
base::AutoLock lock(lock_);
550561
if (nfds != 1) {
551562
// We only support polling of a single device.
552563
errno = EINVAL;

chromium/media/capture/video/linux/fake_v4l2_impl.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/videodev2.h>
1212

13+
#include "base/synchronization/lock.h"
1314
#include "media/capture/capture_export.h"
1415
#include "media/capture/video/linux/v4l2_capture_device.h"
1516
#include "media/capture/video/video_capture_device_descriptor.h"
@@ -52,11 +53,13 @@ class CAPTURE_EXPORT FakeV4L2Impl : public V4L2CaptureDevice {
5253
private:
5354
class OpenedDevice;
5455

55-
int next_id_to_return_from_open_;
56-
std::map<std::string, FakeV4L2DeviceConfig> device_configs_;
57-
std::map<std::string, int> device_name_to_open_id_map_;
56+
base::Lock lock_;
57+
58+
int next_id_to_return_from_open_ GUARDED_BY(lock_);
59+
std::map<std::string, FakeV4L2DeviceConfig> device_configs_ GUARDED_BY(lock_);
60+
std::map<std::string, int> device_name_to_open_id_map_ GUARDED_BY(lock_);
5861
std::map<int /*value returned by open()*/, std::unique_ptr<OpenedDevice>>
59-
opened_devices_;
62+
opened_devices_ GUARDED_BY(lock_);
6063
};
6164

6265
} // namespace media

0 commit comments

Comments
 (0)