Skip to content

Commit 7a4fd50

Browse files
Guido Urdanetamibrunin
authored andcommitted
[Backport] Security bug 382135228
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/chromium/src/+/6096837: Replace raw pointers with scoped_refptr VCM used VideoCaptureController raw pointers in a number of places, including as a field in VCM::CaptureDeviceStartRequest. This CL replaces the field and some other usages with a scoped_refptr to prevent dangling pointers. (cherry picked from commit 3524ce528548d1d743a6aa6e339ecb5a186c22bc) Bug: 382135228 Change-Id: I1bd5f95bdf57631227034beb8bb076f258606378 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6088073 Commit-Queue: Guido Urdaneta <guidou@chromium.org> Reviewed-by: Dale Curtis <dalecurtis@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1396301} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6096837 Auto-Submit: Dale Curtis <dalecurtis@chromium.org> Commit-Queue: Dale Curtis <dalecurtis@chromium.org> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Cr-Commit-Position: refs/branch-heads/6723@{#2725} Cr-Branched-From: 985f2961df230630f9cbd75bd6fe463009855a11-refs/heads/main@{#1356013} Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/615321 Reviewed-by: Anu Aliyas <anu.aliyas@qt.io>
1 parent ce8700d commit 7a4fd50

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

chromium/content/browser/renderer_host/media/video_capture_manager.cc

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "base/location.h"
1616
#include "base/logging.h"
1717
#include "base/memory/raw_ptr.h"
18+
#include "base/memory/scoped_refptr.h"
1819
#include "base/metrics/histogram_functions.h"
1920
#include "base/observer_list.h"
2021
#include "base/ranges/algorithm.h"
@@ -62,12 +63,14 @@ namespace content {
6263
class VideoCaptureManager::CaptureDeviceStartRequest {
6364
public:
6465
CaptureDeviceStartRequest(
65-
VideoCaptureController* controller,
66+
scoped_refptr<VideoCaptureController> controller,
6667
const media::VideoCaptureSessionId& session_id,
6768
const media::VideoCaptureParams& params,
6869
mojo::PendingRemote<video_effects::mojom::VideoEffectsProcessor>
6970
video_effects_processor);
70-
VideoCaptureController* controller() const { return controller_; }
71+
scoped_refptr<VideoCaptureController> controller() const {
72+
return controller_;
73+
}
7174
const base::UnguessableToken& session_id() const { return session_id_; }
7275
media::VideoCaptureParams params() const { return params_; }
7376

@@ -77,20 +80,20 @@ class VideoCaptureManager::CaptureDeviceStartRequest {
7780
}
7881

7982
private:
80-
const raw_ptr<VideoCaptureController> controller_;
83+
const scoped_refptr<VideoCaptureController> controller_;
8184
const base::UnguessableToken session_id_;
8285
const media::VideoCaptureParams params_;
8386
mojo::PendingRemote<video_effects::mojom::VideoEffectsProcessor>
8487
video_effects_processor_;
8588
};
8689

8790
VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest(
88-
VideoCaptureController* controller,
91+
scoped_refptr<VideoCaptureController> controller,
8992
const media::VideoCaptureSessionId& session_id,
9093
const media::VideoCaptureParams& params,
9194
mojo::PendingRemote<video_effects::mojom::VideoEffectsProcessor>
9295
video_effects_processor)
93-
: controller_(controller),
96+
: controller_(std::move(controller)),
9497
session_id_(session_id),
9598
params_(params),
9699
video_effects_processor_(std::move(video_effects_processor)) {}
@@ -265,14 +268,15 @@ void VideoCaptureManager::ApplySubCaptureTarget(
265268

266269
void VideoCaptureManager::QueueStartDevice(
267270
const media::VideoCaptureSessionId& session_id,
268-
VideoCaptureController* controller,
271+
scoped_refptr<VideoCaptureController> controller,
269272
const media::VideoCaptureParams& params,
270273
mojo::PendingRemote<video_effects::mojom::VideoEffectsProcessor>
271274
video_effects_processor) {
272275
DCHECK_CURRENTLY_ON(BrowserThread::IO);
273276
DCHECK(lock_time_.is_null());
274-
device_start_request_queue_.push_back(CaptureDeviceStartRequest(
275-
controller, session_id, params, std::move(video_effects_processor)));
277+
device_start_request_queue_.push_back(
278+
CaptureDeviceStartRequest(std::move(controller), session_id, params,
279+
std::move(video_effects_processor)));
276280
if (device_start_request_queue_.size() == 1)
277281
ProcessDeviceStartRequestQueue();
278282
}
@@ -318,7 +322,8 @@ void VideoCaptureManager::ProcessDeviceStartRequestQueue() {
318322
if (request == device_start_request_queue_.end())
319323
return;
320324

321-
VideoCaptureController* const controller = request->controller();
325+
scoped_refptr<VideoCaptureController> const controller =
326+
request->controller();
322327

323328
EmitLogMessage("VideoCaptureManager::ProcessDeviceStartRequestQueue", 3);
324329
// The unit test VideoCaptureManagerTest.OpenNotExisting requires us to fail
@@ -336,7 +341,7 @@ void VideoCaptureManager::ProcessDeviceStartRequestQueue() {
336341
GetDeviceInfoById(controller->device_id());
337342
if (!device_info) {
338343
OnDeviceLaunchFailed(
339-
controller,
344+
controller.get(),
340345
media::VideoCaptureError::
341346
kVideoCaptureManagerProcessDeviceStartQueueDeviceInfoNotFound);
342347
return;
@@ -357,7 +362,7 @@ void VideoCaptureManager::ProcessDeviceStartRequestQueue() {
357362
base::BindOnce([](scoped_refptr<VideoCaptureManager>,
358363
scoped_refptr<VideoCaptureController>) {},
359364
scoped_refptr<VideoCaptureManager>(this),
360-
GetControllerSharedRef(controller)),
365+
std::move(controller)),
361366
request->TakeVideoEffectsProcessor());
362367
}
363368

@@ -459,7 +464,7 @@ void VideoCaptureManager::ConnectClient(
459464
EmitLogMessage(string_stream.str(), 1);
460465
}
461466

462-
VideoCaptureController* controller =
467+
scoped_refptr<VideoCaptureController> controller =
463468
GetOrCreateController(session_id, params);
464469
if (!controller) {
465470
std::move(done_cb).Run(nullptr);
@@ -949,7 +954,8 @@ media::VideoCaptureDeviceInfo* VideoCaptureManager::GetDeviceInfoById(
949954
return nullptr;
950955
}
951956

952-
VideoCaptureController* VideoCaptureManager::GetOrCreateController(
957+
scoped_refptr<VideoCaptureController>
958+
VideoCaptureManager::GetOrCreateController(
953959
const media::VideoCaptureSessionId& capture_session_id,
954960
const media::VideoCaptureParams& params) {
955961
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -971,10 +977,12 @@ VideoCaptureController* VideoCaptureManager::GetOrCreateController(
971977
return existing_device;
972978
}
973979

974-
VideoCaptureController* new_controller = new VideoCaptureController(
975-
device_info.id, device_info.type, params,
976-
video_capture_provider_->CreateDeviceLauncher(), emit_log_message_cb_);
977-
controllers_.emplace_back(new_controller);
980+
scoped_refptr<VideoCaptureController> new_controller =
981+
base::MakeRefCounted<VideoCaptureController>(
982+
device_info.id, device_info.type, params,
983+
video_capture_provider_->CreateDeviceLauncher(),
984+
emit_log_message_cb_);
985+
controllers_.push_back(new_controller);
978986
return new_controller;
979987
}
980988

chromium/content/browser/renderer_host/media/video_capture_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class CONTENT_EXPORT VideoCaptureManager
308308
// Finds a VideoCaptureController for the indicated |capture_session_id|,
309309
// creating a fresh one if necessary. Returns nullptr if said
310310
// |capture_session_id| is invalid.
311-
VideoCaptureController* GetOrCreateController(
311+
scoped_refptr<VideoCaptureController> GetOrCreateController(
312312
const media::VideoCaptureSessionId& capture_session_id,
313313
const media::VideoCaptureParams& params);
314314

@@ -320,7 +320,7 @@ class CONTENT_EXPORT VideoCaptureManager
320320
// another request pending start.
321321
void QueueStartDevice(
322322
const media::VideoCaptureSessionId& session_id,
323-
VideoCaptureController* controller,
323+
scoped_refptr<VideoCaptureController> controller,
324324
const media::VideoCaptureParams& params,
325325
mojo::PendingRemote<video_effects::mojom::VideoEffectsProcessor>
326326
video_effects_processor);

0 commit comments

Comments
 (0)