IPC AddressSanitizer: heap-buffer-overflow [@ nsImageToPixbuf::SourceSurfaceToPixbuf] through [@ nsBaseDragSession::InvokeDragSession]
Categories
(Core :: DOM: Copy & Paste and Drag & Drop, defect, P2)
Tracking
()
People
(Reporter: decoder, Assigned: edgar)
References
Details
(4 keywords, Whiteboard: [adv-main149+r][adv-ESR140.9+r][adv-ESR115.34+r])
Attachments
(2 files, 4 external files, 1 obsolete file)
|
331 bytes,
text/html
|
Details | |
|
2.45 KB,
patch
|
Details | Diff | Splinter Review |
Bug: Heap-buffer-overflow in nsImageToPixbuf::SourceSurfaceToPixbuf via InvokeDragSession with A8 format
Vulnerable code: widget/gtk/nsImageToPixbuf.cpp:90-91
uint32_t* srcPixel =
reinterpret_cast<uint32_t*>((srcData + row * srcStride + 4 * col));
This always reads 4 bytes per pixel (4 * col) regardless of the surface format. Only B8G8R8A8 and B8G8R8X8 are handled; the format check is a MOZ_ASSERT (no-op in this build).
Attack: A compromised content process sends InvokeDragSession with SurfaceFormat::A8 (1 byte per pixel). The parent creates a valid A8 surface. When the drag gesture fires (triggered via SynthesizeNativeMouseMove), the GTK drag code calls SourceSurfaceToPixbuf which reads 4x beyond each row, causing a heap-buffer-overflow.
[EXPLOIT] Sending malicious InvokeDragSession with A8 format
[EXPLOIT] SendInvokeDragSession returned: 1
[EXPLOIT] Sending SynthesizeNativeMouseMove
[EXPLOIT] SendSynthesizeNativeMouseMove returned: 1
=================================================================
==3973721==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x75978dc79aac at pc 0x73c77ea7dbdc bp 0x7ffd0a343550 sp 0x7ffd0a343548
READ of size 4 at 0x75978dc79aac thread T0
#0 0x73c77ea7dbdb in nsImageToPixbuf::SourceSurfaceToPixbuf(mozilla::gfx::SourceSurface*, int, int) widget/gtk/nsImageToPixbuf.cpp
#1 0x73c77ea7c8e9 in nsDragSession::SetDragIcon(_GdkDragContext*) widget/gtk/nsDragService.cpp:2520:38
#2 0x77c78e350cf6 in g_cclosure_marshal_VOID__OBJECTv (/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x13cf6) (BuildId: 8b1bcc30936d97f670e5b57b4ca68d127d4ba1c0)
#3 0x77c78e3726bc (/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x356bc) (BuildId: 8b1bcc30936d97f670e5b57b4ca68d127d4ba1c0)
#4 0x77c78e372a97 in g_signal_emit_by_name (/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x35a97) (BuildId: 8b1bcc30936d97f670e5b57b4ca68d127d4ba1c0)
#5 0x73c788d9ca7e (/lib/x86_64-linux-gnu/libgtk-3.so.0+0x39ca7e) (BuildId: e3bf6367082e76a6e85218c0a84a5a0e29af05b1)
#6 0x73c788d9cec9 in gtk_drag_begin_with_coordinates (/lib/x86_64-linux-gnu/libgtk-3.so.0+0x39cec9) (BuildId: e3bf6367082e76a6e85218c0a84a5a0e29af05b1)
#7 0x73c77ea63b97 in nsDragSession::InvokeDragSessionImpl(nsIWidget*, nsIArray*, mozilla::Maybe<mozilla::gfx::IntRegionTyped<mozilla::CSSPixel>> const&, unsigned int) widget/gtk/nsDragService.cpp:837:29
#8 0x73c77e74ae88 in nsBaseDragSession::InvokeDragSession(nsIWidget*, nsINode*, nsIPrincipal*, nsIPolicyContainer*, nsICookieJarSettings*, nsIArray*, unsigned int, nsIContentPolicy::nsContentPolicyType) widget/nsBaseDragService.cpp:432:7
#9 0x73c77ea63663 in nsDragSession::InvokeDragSession(nsIWidget*, nsINode*, nsIPrincipal*, nsIPolicyContainer*, nsICookieJarSettings*, nsIArray*, unsigned int, nsIContentPolicy::nsContentPolicyType) widget/gtk/nsDragService.cpp:759:29
#10 0x73c77e74d6a2 in nsBaseDragSession::InitWithRemoteImage(nsIWidget*, nsINode*, nsIPrincipal*, nsIPolicyContainer*, nsICookieJarSettings*, nsIArray*, unsigned int, mozilla::dom::RemoteDragStartData*, mozilla::dom::DragEvent*, mozilla::dom::DataTransfer*, bool) widget/nsBaseDragService.c
pp:578:17
#11 0x73c77e74cff9 in nsBaseDragService::InvokeDragSessionWithRemoteImage(nsINode*, nsIPrincipal*, nsIPolicyContainer*, nsICookieJarSettings*, nsIArray*, unsigned int, mozilla::dom::RemoteDragStartData*, mozilla::dom::DragEvent*, mozilla::dom::DataTransfer*) widget/nsBaseDragService.cpp:55
1:19
#12 0x73c77a273818 in mozilla::EventStateManager::DoDefaultDragStart(nsPresContext*, mozilla::WidgetDragEvent*, mozilla::dom::DataTransfer*, bool, nsIContent*, mozilla::dom::Selection*, mozilla::dom::RemoteDragStartData*, nsIPrincipal*, nsIPolicyContainer*, nsICookieJarSettings*) dom/event
s/EventStateManager.cpp
#13 0x73c77a25e6b0 in mozilla::EventStateManager::GenerateDragGesture(nsPresContext*, mozilla::WidgetInputEvent*) dom/events/EventStateManager.cpp:2876:26
#14 0x73c77a25c3bf in mozilla::EventStateManager::PreHandleEvent(nsPresContext*, mozilla::WidgetEvent*, nsIFrame*, nsIContent*, nsEventStatus*, nsIContent*) dom/events/EventStateManager.cpp:1193:9
#15 0x73c77f1530b1 in mozilla::PresShell::EventHandler::DispatchEvent(mozilla::EventStateManager*, mozilla::WidgetEvent*, bool, nsEventStatus*, nsIContent*) layout/base/PresShell.cpp:9096:39
#16 0x73c77f14a255 in mozilla::PresShell::EventHandler::HandleEventWithCurrentEventInfo(mozilla::WidgetEvent*, nsEventStatus*, bool, nsIContent*) layout/base/PresShell.cpp:9063:17
#17 0x73c77f1515e1 in mozilla::PresShell::EventHandler::HandleEventWithTarget(mozilla::WidgetEvent*, nsIFrame*, nsIContent*, nsEventStatus*, bool, nsIContent**, nsIContent*) layout/base/PresShell.cpp:8970:17
#18 0x73c77a3c6857 in HandleEventWithTarget objdir-ff-asan/dist/include/mozilla/PresShell.h:700:25
#19 0x73c77a3c6857 in mozilla::PointerEventHandler::DispatchPointerFromMouseOrTouch(mozilla::PresShell*, nsIFrame*, nsIContent*, mozilla::dom::Element*, mozilla::WidgetGUIEvent*, bool, nsEventStatus*, nsIContent**) dom/events/PointerEventHandler.cpp:1323:12
#20 0x73c77f14d43a in mozilla::PresShell::EventHandler::DispatchPrecedingPointerEvent(AutoWeakFrame&, mozilla::WidgetGUIEvent*, mozilla::dom::Element*, bool, mozilla::PresShell::EventHandler::EventTargetData*, nsEventStatus*) layout/base/PresShell.cpp:7980:3
#21 0x73c77f1495b7 in mozilla::PresShell::EventHandler::HandleEventUsingCoordinates(AutoWeakFrame&, mozilla::WidgetGUIEvent*, nsEventStatus*, bool) layout/base/PresShell.cpp:7602:8
#22 0x73c77f147c0e in mozilla::PresShell::EventHandler::HandleEvent(AutoWeakFrame&, mozilla::WidgetGUIEvent*, bool, nsEventStatus*) layout/base/PresShell.cpp:7484:12
#23 0x73c77f13dbf5 in mozilla::PresShell::HandleEvent(nsIFrame*, mozilla::WidgetGUIEvent*, bool, nsEventStatus*) layout/base/PresShell.cpp:7304:23
#24 0x73c77f187f09 in mozilla::PresShellWidgetListener::HandleEvent(mozilla::WidgetGUIEvent*) layout/base/PresShellWidgetListener.cpp:245:11
#25 0x73c77e760b4c in nsIWidget::ProcessUntransformedAPZEvent(mozilla::WidgetInputEvent*, mozilla::layers::APZEventResult const&) widget/nsIWidget.cpp:1118:26
#26 0x73c77e762e11 in nsIWidget::DispatchInputEvent(mozilla::WidgetInputEvent*) widget/nsIWidget.cpp:1320:31
#27 0x73c77e933046 in nsWindow::OnMotionNotifyEvent(_GdkEventMotion*) widget/gtk/nsWindow.cpp:4599:3
#28 0x73c77e94b130 in motion_notify_event_cb(_GtkWidget*, _GdkEventMotion*) widget/gtk/nsWindow.cpp:8211:11
[...]
#42 0x73c78c60aa62 in g_main_context_iteration (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x5ca62) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75)
#43 0x73c77ea48e2d in nsAppShell::ProcessNextNativeEvent(bool) widget/gtk/nsAppShell.cpp:577:26
0x75978dc79aaf is located 0 bytes after 2095-byte region [0x75978dc79280,0x75978dc79aaf)
allocated by thread T0 here:
#0 0x5cfb26581304 in malloc /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:67:3
#1 0x73c774fe072a in Realloc gfx/2d/Tools.h:131:40
#2 0x73c774fe072a in mozilla::gfx::SourceSurfaceAlignedRawData::Init(mozilla::gfx::IntSizeTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::SurfaceFormat, bool, unsigned char, int) gfx/2d/SourceSurfaceRawData.cpp:89:12
#3 0x73c774ef3b5d in mozilla::gfx::Factory::CreateDataSourceSurface(mozilla::gfx::IntSizeTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::SurfaceFormat, bool) gfx/2d/Factory.cpp:915:16
#4 0x73c774ef2f41 in mozilla::gfx::CreateDataSourceSurfaceFromData(mozilla::gfx::IntSizeTyped<mozilla::gfx::UnknownUnits> const&, mozilla::gfx::SurfaceFormat, unsigned char const*, int) gfx/2d/DataSurfaceHelpers.cpp:42:7
#5 0x73c77d7ed8fb in mozilla::dom::BrowserParent::RecvInvokeDragSession(nsTArray<mozilla::dom::IPCTransferableData>&&, unsigned int const&, mozilla::Maybe<mozilla::ipc::BigBuffer>&&, unsigned int const&, mozilla::gfx::SurfaceFormat const&, mozilla::gfx::IntRectTyped<mozilla::LayoutDevicePixel> const&, nsIPri
ncipal*, nsIPolicyContainer*, mozilla::net::CookieJarSettingsArgs const&, mozilla::dom::MaybeDiscarded<mozilla::dom::WindowContext> const&, mozilla::dom::MaybeDiscarded<mozilla::dom::WindowContext> const&) dom/ipc/BrowserParent.cpp:3945:39
#6 0x73c77d985da2 in mozilla::dom::PBrowserParent::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PBrowserParent.cpp:6857:81
#7 0x73c77db30c4e in mozilla::dom::PContentParent::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PContentParent.cpp:6596:32
#8 0x73c77422765d in mozilla::ipc::MessageChannel::DispatchAsyncMessage(mozilla::ipc::ActorLifecycleProxy*, IPC::Message const&) ipc/glue/MessageChannel.cpp:1793:25
[...]
Testcase requires applying the patch to simulate the compromised content process, then loading the HTML testcase. All testcase parts and analysis done by Claude autonomously with my instructions to audit PBrowser.
| Reporter | ||
Comment 1•9 months ago
|
||
| Reporter | ||
Comment 2•9 months ago
|
||
What fix would you propose for this?
● The parent should validate the format in RecvInvokeDragSession before creating the surface. Only B8G8R8A8 and B8G8R8X8 are supported downstream by SourceSurfaceToPixbuf, so reject anything else:
// In BrowserParent::RecvInvokeDragSession, before CreateDataSourceSurfaceFromData:
if (aFormat != gfx::SurfaceFormat::B8G8R8A8 &&
aFormat != gfx::SurfaceFormat::B8G8R8X8) {
// Skip visualization for unsupported formats
aVisualDnDData.reset();
}
This is the right place to fix it because:
- It's at the IPC trust boundary where untrusted content data enters the parent
- SourceSurfaceToPixbuf is a general utility that reasonably assumes it gets standard BGRA/BGRX surfaces (its only other callers pass image-decoded surfaces)
- The normal content process only ever sends B8G8R8A8 surfaces (from DrawDrag rendering), so this rejects only malicious input
Comment 3•9 months ago
|
||
If we really only ever actually send one format, why should we ever send one at all? If we only send two, it could be a boolean.
| Assignee | ||
Updated•9 months ago
|
| Assignee | ||
Comment 4•9 months ago
|
||
If the compositing WM is used, we use nsDragSession::SetAlphaPixmap() to draw drag icon, which draw the source surface into B8G8R8A8 format, so I can not reproduce this on my Ubuntu. I also checked other platforms, they all convert the source surface into B8G8R8A8 format, e.g.
- macOS: https://searchfox.org/firefox-main/rev/d6dfd9f8cd9717b03750cded8980ef61678fbc8b/widget/cocoa/nsDragService.mm#115-132
- Windows: https://searchfox.org/firefox-main/rev/52e25e8bf7d712501f99b8ba77718ea0edc42bd7/widget/windows/nsDragService.cpp#88-110
- Android: https://searchfox.org/firefox-main/rev/d6dfd9f8cd9717b03750cded8980ef61678fbc8b/widget/android/AndroidWidgetUtils.cpp#29-43
So I think this is a non-compositing WM only issue on Linux.
| Assignee | ||
Comment 5•9 months ago
|
||
And since other platforms and Linux with compositing WM handle other SurfaceFormats, I think we should just do the same for nsImageToPixbuf::SourceSurfaceToPixbuf for consistency.
| Assignee | ||
Comment 6•9 months ago
|
||
It currently only supports the B8G8R8A8 and B8G8R8X8 formats.
| Assignee | ||
Comment 7•9 months ago
|
||
Comment on attachment 9544246 [details]
(secure)
Security Approval Request
- How easily could an exploit be constructed based on the patch?: Only malicious child process could be sending unexpected format.
- Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: No
- Which branches (beta, release, and/or ESR) are affected by this flaw, and do the release status flags reflect this affected/unaffected state correctly?: All
- If not all supported branches, which bug introduced the flaw?: None
- Do you have backports for the affected branches?: Yes
- If not, how different, hard to create, and risky will they be?: Patch should just be applied clearer.
- How likely is this patch to cause regressions; how much testing does it need?: Should not be able to cause regression, only malicious child process could be sending unexpected format.
- Is the patch ready to land after security approval is given?: Yes
- Is Android affected?: No
Comment 8•9 months ago
|
||
Setting branch statuses based on the above answers. Please correct if I've misinterpreted it.
It's RC week so sec-approvals are on hold; will check back after the merge.
Comment 9•9 months ago
|
||
Should probably land this at the same time as bug 2018090 since I found it while reviewing this and it's on the same path (but earlier).
Comment 10•8 months ago
|
||
Comment on attachment 9544246 [details]
(secure)
sec-approval+ to land and request uplifts
Comment 11•8 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined: sec-high bug
- Code covered by automated testing: no
- Fix verified in Nightly: no
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: None
- Risk associated with taking this patch: low
- Explanation of risk level: This only handles additional surface formats, which are unlikely to be used in normal use cases.
- String changes made/needed: None
- Is Android affected?: no
| Assignee | ||
Comment 12•8 months ago
|
||
It currently only supports the B8G8R8A8 and B8G8R8X8 formats.
Original Revision: https://phabricator.services.mozilla.com/D282813
Comment 13•8 months ago
|
||
firefox-esr115 Uplift Approval Request
- User impact if declined: sec-high bug
- Code covered by automated testing: no
- Fix verified in Nightly: no
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: None
- Risk associated with taking this patch: low
- Explanation of risk level: This only handles additional surface formats, which are unlikely to be used in normal use cases.
- String changes made/needed: None
- Is Android affected?: no
| Assignee | ||
Comment 14•8 months ago
|
||
It currently only supports the B8G8R8A8 and B8G8R8X8 formats.
Original Revision: https://phabricator.services.mozilla.com/D282813
Comment 15•8 months ago
|
||
Comment 16•8 months ago
|
||
firefox-esr140 Uplift Approval Request
- User impact if declined: sec-high bug
- Code covered by automated testing: no
- Fix verified in Nightly: no
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: None
- Risk associated with taking this patch: low
- Explanation of risk level: This only handles additional surface formats, which are unlikely to be used in normal use cases.
- String changes made/needed: None
- Is Android affected?: no
| Assignee | ||
Comment 17•8 months ago
|
||
It currently only supports the B8G8R8A8 and B8G8R8X8 formats.
Original Revision: https://phabricator.services.mozilla.com/D282813
| Assignee | ||
Comment 18•8 months ago
|
||
It currently only supports the B8G8R8A8 and B8G8R8X8 formats.
Original Revision: https://phabricator.services.mozilla.com/D282813
Updated•8 months ago
|
Comment 19•8 months ago
|
||
firefox-release Uplift Approval Request
- User impact if declined: sec-high bug
- Code covered by automated testing: no
- Fix verified in Nightly: no
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: None
- Risk associated with taking this patch: low
- Explanation of risk level: This only handles additional surface formats, which are unlikely to be used in normal use cases.
- String changes made/needed: None
- Is Android affected?: no
Comment 20•8 months ago
|
||
Comment 21•8 months ago
|
||
widget/gtk/nsImageToPixbuf.cpp:X:19: error: use of undeclared identifier 'Factory'; did you mean 'mozilla::gfx::Factory'?
followed by more similar failures.
Updated•8 months ago
|
Comment 22•8 months ago
|
||
Comment on attachment 9548110 [details]
(secure)
Rejecting release uplift request.
This is not a suitable candidate for a dot release since ESR is affected.
Updated•8 months ago
|
Comment 23•8 months ago
|
||
Comment 24•8 months ago
|
||
Updated•8 months ago
|
Updated•8 months ago
|
Comment 25•8 months ago
|
||
| uplift | ||
| Assignee | ||
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
Comment 26•8 months ago
|
||
| uplift | ||
Updated•8 months ago
|
Updated•8 months ago
|
Comment 27•8 months ago
|
||
| uplift | ||
Updated•8 months ago
|
Updated•8 months ago
|
Comment 28•2 months ago
|
||
A automated clustering tool detected that Bug 2065955 and Bug 2064287 are related and may have an interconnected fix.
Updated•2 months ago
|
Description
•