IPC: AddressSanitizer: heap-buffer-overflow through [@ raw_fTexImage2D] and [@ mozilla::dom::WebGLParent::RecvTexImage]
Categories
(Core :: Graphics: CanvasWebGL, defect, P2)
Tracking
()
People
(Reporter: decoder, Assigned: lsalzman, NeedInfo)
References
(Regression)
Details
(5 keywords, Whiteboard: [adv-main148+r][adv-esr115.33+r] [adv-esr140.8+r])
Attachments
(2 files, 1 external file, 6 obsolete files)
|
741 bytes,
text/html
|
Details | |
|
2.39 KB,
patch
|
Details | Diff | Splinter Review |
The attached patch+html file yield the following crash in the parent process:
==3707288==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x79ab5809b480 at pc 0x5f3829dd62d4 bp 0x789b04129ae0 sp 0x789b04129298
READ of size 32 at 0x79ab5809b480 thread T53
#0 0x5f3829dd62d3 in memcpy /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:115:5
#1 0x789affb649c5 (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.1.so+0x5649c5) (BuildId: c5a7590302648de4e5c602384799fe67c9da00c6)
#2 0x789affd593a3 (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.1.so+0x7593a3) (BuildId: c5a7590302648de4e5c602384799fe67c9da00c6)
#3 0x789b00456179 (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.1.so+0xe56179) (BuildId: c5a7590302648de4e5c602384799fe67c9da00c6)
#4 0x789aff77bbea (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.1.so+0x17bbea) (BuildId: c5a7590302648de4e5c602384799fe67c9da00c6)
#5 0x789aff77c6c9 (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.1.so+0x17c6c9) (BuildId: c5a7590302648de4e5c602384799fe67c9da00c6)
#6 0x789aff751ca7 (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.1.so+0x151ca7) (BuildId: c5a7590302648de4e5c602384799fe67c9da00c6)
#7 0x789aff7540b0 (/lib/x86_64-linux-gnu/libgallium-25.0.7-0ubuntu0.24.04.1.so+0x1540b0) (BuildId: c5a7590302648de4e5c602384799fe67c9da00c6)
#8 0x789b3eeb350a in raw_fTexImage2D /srv/repos/firefox/gfx/gl/GLContext.h:1716:5
#9 0x789b3eeb350a in mozilla::gl::GLContext::fTexImage2D(unsigned int, int, int, int, int, int, unsigned int, unsigned int, void const*) /srv/repos/firefox/gfx/gl/GLContext.cpp:2422:3
#10 0x789b436afa5a in mozilla::DoTexImage(mozilla::gl::GLContext*, StrongGLenum<TexImageTargetDetails>, int, mozilla::webgl::DriverUnpackInfo const*, int, int, int, void const*) /srv/repos/firefox/dom/canvas/WebGLTextureUpload.cpp:634:9
#11 0x789b4349bb1f in mozilla::webgl::DoTexOrSubImage(bool, mozilla::gl::GLContext*, StrongGLenum<TexImageTargetDetails>, int, mozilla::webgl::DriverUnpackInfo const*, int, int, int, int, int, int, void const*) /srv/repos/firefox/dom/canvas/TexUnpackBlob.cpp:500:12
#12 0x789b434a1e8b in mozilla::webgl::TexUnpackSurface::TexOrSubImage(bool, bool, mozilla::WebGLTexture*, int, mozilla::webgl::DriverUnpackInfo const*, int, int, int, mozilla::webgl::PackingInfo const&, unsigned int*) const /srv/repos/firefox/dom/canvas/TexUnpackBlob.cpp:1249:7
#13 0x789b436b3f4e in mozilla::WebGLTexture::TexImage(unsigned int, unsigned int, mozilla::avec3<unsigned int> const&, mozilla::webgl::PackingInfo const&, mozilla::webgl::TexUnpackBlobDesc const&) /srv/repos/firefox/dom/canvas/WebGLTextureUpload.cpp:1107:14
#14 0x789b435d281f in mozilla::WebGLContext::TexImage(unsigned int, unsigned int, mozilla::avec3<unsigned int>, mozilla::webgl::PackingInfo const&, mozilla::webgl::TexUnpackBlobDesc const&) const /srv/repos/firefox/dom/canvas/WebGLContextTextures.cpp:196:8
#15 0x789b436012b3 in TexImage /srv/repos/firefox/dom/canvas/HostWebGLContext.h:574:15
#16 0x789b436012b3 in mozilla::dom::WebGLParent::RecvTexImage(unsigned int, unsigned int, mozilla::avec3<unsigned int> const&, mozilla::webgl::PackingInfo const&, mozilla::webgl::TexUnpackBlobDesc&&) /srv/repos/firefox/dom/canvas/WebGLParent.cpp:108:10
#17 0x789b439ddc34 in mozilla::dom::PWebGLParent::OnMessageReceived(IPC::Message const&) /srv/repos/firefox/objdir-ff-asan/ipc/ipdl/PWebGLParent.cpp:465:79
#18 0x789b3ffd1943 in mozilla::gfx::PCanvasManagerParent::OnMessageReceived(IPC::Message const&) /srv/repos/firefox/objdir-ff-asan/ipc/ipdl/PCanvasManagerParent.cpp:261:32
#19 0x789b3e0270dd in mozilla::ipc::MessageChannel::DispatchAsyncMessage(mozilla::ipc::ActorLifecycleProxy*, IPC::Message const&) /srv/repos/firefox/ipc/glue/MessageChannel.cpp:1793:25
[...]
0x79ab5809b480 is located 0 bytes after 256-byte region [0x79ab5809b380,0x79ab5809b480)
allocated by thread T53 here:
#0 0x5f3829dd7429 in calloc /builds/worker/fetches/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:74:3
#1 0x789b434997f1 in calloc /srv/repos/firefox/dom/canvas/WebGLTypes.h:85:10
#2 0x789b434997f1 in mozilla::webgl::TexUnpackBlob::ConvertIfNeeded(mozilla::WebGLContext const*, unsigned int, unsigned int, mozilla::WebGLTexelFormat, unsigned char const*, long, mozilla::WebGLTexelFormat, long, unsigned char const**, mozilla::UniqueBuffer*) const /srv/repos/firefox/dom/canvas/TexUnpackBlo
b.cpp:467:39
#3 0x789b434a1c7f in mozilla::webgl::TexUnpackSurface::TexOrSubImage(bool, bool, mozilla::WebGLTexture*, int, mozilla::webgl::DriverUnpackInfo const*, int, int, int, mozilla::webgl::PackingInfo const&, unsigned int*) const /srv/repos/firefox/dom/canvas/TexUnpackBlob.cpp:1230:8
#4 0x789b436b3f4e in mozilla::WebGLTexture::TexImage(unsigned int, unsigned int, mozilla::avec3<unsigned int> const&, mozilla::webgl::PackingInfo const&, mozilla::webgl::TexUnpackBlobDesc const&) /srv/repos/firefox/dom/canvas/WebGLTextureUpload.cpp:1107:14
#5 0x789b435d281f in mozilla::WebGLContext::TexImage(unsigned int, unsigned int, mozilla::avec3<unsigned int>, mozilla::webgl::PackingInfo const&, mozilla::webgl::TexUnpackBlobDesc const&) const /srv/repos/firefox/dom/canvas/WebGLContextTextures.cpp:196:8
#6 0x789b436012b3 in TexImage /srv/repos/firefox/dom/canvas/HostWebGLContext.h:574:15
#7 0x789b436012b3 in mozilla::dom::WebGLParent::RecvTexImage(unsigned int, unsigned int, mozilla::avec3<unsigned int> const&, mozilla::webgl::PackingInfo const&, mozilla::webgl::TexUnpackBlobDesc&&) /srv/repos/firefox/dom/canvas/WebGLParent.cpp:108:10
#8 0x789b439ddc34 in mozilla::dom::PWebGLParent::OnMessageReceived(IPC::Message const&) /srv/repos/firefox/objdir-ff-asan/ipc/ipdl/PWebGLParent.cpp:465:79
#9 0x789b3ffd1943 in mozilla::gfx::PCanvasManagerParent::OnMessageReceived(IPC::Message const&) /srv/repos/firefox/objdir-ff-asan/ipc/ipdl/PCanvasManagerParent.cpp:261:32
#10 0x789b3e0270dd in mozilla::ipc::MessageChannel::DispatchAsyncMessage(mozilla::ipc::ActorLifecycleProxy*, IPC::Message const&) /srv/repos/firefox/ipc/glue/MessageChannel.cpp:1793:25
[...]
(the working copy is slightly outdated, on f5171bd6a83982663d6bb33e78fa89237a42a8ac)
The HTML file sets up the IPC actors and the patch simulates the compromised content process sending wrong data. The vulnerability was found by Claude and the test (patch and HTML file) were also created by Claude all automatically in the same session (during internal testing, not part of the Anthropic batch).
| Reporter | ||
Comment 1•10 months ago
|
||
| Reporter | ||
Comment 2•10 months ago
|
||
Note that while the read seems to happen in the driver, the memory seems to be allocated by us in mozilla::webgl::TexUnpackBlob::ConvertIfNeeded.
Updated•10 months ago
|
| Reporter | ||
Comment 3•10 months ago
|
||
● WebGL TexImage IPC Vulnerability Summary
Bug: Heap-buffer-overflow in parent process when processing TexImage IPC with malformed SurfaceDescriptorBuffer
Location: dom/canvas/TexUnpackBlob.cpp:1232 in TexUnpackSurface::TexOrSubImage()
Root Cause: Size mismatch between surface descriptor and texture upload parameters allows content to trigger parent heap overflow.
Attack Vector:
- Content sends TexImage IPC with SurfaceDescriptorBuffer containing:
- RGBDescriptor with small dimensions (8x8)
- desc.size with large dimensions (8x512)
- desc.structuredSrcSize matching large dimensions (8x512) - Parent validates buffer size against small RGBDescriptor (passes)
- Parent creates 8x8 surface wrapper around shmem
- ConvertIfNeeded allocates conversion buffer for 8 rows only
- glTexImage2D called with 512 rows, reads past allocated buffer → ASan crash
Key Files:
- WebGLParent.cpp:99 - IPC entry, no validation of desc fields
- TexUnpackBlob.cpp:685 - Validate() uses attacker-controlled structuredSrcSize
- TexUnpackBlob.cpp:1099 - Surface created from RGBDescriptor size, not desc.size
- TexUnpackBlob.cpp:1230 - ConvertIfNeeded limits conversion to surface rows
- TexUnpackBlob.cpp:1255 - DoTexOrSubImage uses desc.size for GL upload
Fix: Validate that desc.size matches the actual surface descriptor dimensions before texture upload.
(Summary generated by Claude, may contain inaccuracies but it would be great to know if this is helpful for debugging).
Comment 4•10 months ago
•
|
||
NeedInfo - Brad has been looking at that function recently I believe so let's see his assessment of how this buffer is sized incorrectly for the formats involved. Very possibly Lee would have the best idea on a quick fix as he's fixed several such issues recently.
I am inclined to categorize this as an OOBR data leak at best (i.e. reading beyond a buffer's end is likely to get contents we didn't allocate for this purpose), so it's not an attack vector by itself but could perhaps leak information that an exploit could read back to get some additional piece of information (in the worst case an IPC peer id, or data belonging to a different document).
Comment 5•10 months ago
|
||
I will try to fix this.
Comment 6•10 months ago
|
||
I think we've been marking these cross-process reads as sec-moderate sandbox escapes but I could be mistaken.
Comment 7•10 months ago
|
||
Eh I think I'm confused as I can't really find other cases of that.
Comment 8•10 months ago
|
||
sec-high makes sense to me because of the two kinds of data leak (IPC peer id exfil enabling a compromised content process mimic for sending crafted IPCs, different document data exfil), of course it can also simply crash due to page faults, but you only have to get lucky once.
| Reporter | ||
Comment 9•10 months ago
|
||
Fwiw, this is the fix proposed by Claude:
--- a/dom/canvas/TexUnpackBlob.cpp
+++ b/dom/canvas/TexUnpackBlob.cpp
@@ -1115,6 +1115,14 @@ bool TexUnpackSurface::TexOrSubImage(bool isSubImage, bool needsRespec,
return false;
}
surf = gfx::Factory::CreateWrappingDataSourceSurface(
shmem.get<uint8_t>(), stride, rgb.size(), rgb.format());
+
+ // Validate that the texture upload size matches the surface descriptor
+ // to prevent reading past the surface data during texture upload.
+ if (size.x != rgb.size().width || size.y != rgb.size().height) {
+ gfxCriticalError() << "TexUnpackSurface size mismatch: texture="
+ << size.x << "x" << size.y << " surface="
+ << rgb.size().width << "x" << rgb.size().height;
+ return false;
+ }
} else if (SDIsNullRemoteDecoder(sd)) {
Once we have our own fix, it would be great to know how accurate the description in comment 3 is and how close the proposed fix is to the actual fix. Thanks!
Comment 10•9 months ago
|
||
This ensures that later in TexUnpackSurface::TexOrSubImage, we stay
within the limits of the mapped data.
Comment 11•9 months ago
|
||
(In reply to Christian Holler (:decoder) from comment #9)
Once we have our own fix, it would be great to know how accurate the description in comment 3 is and how close the proposed fix is to the actual fix. Thanks!
Comment 3 is very helpful. The fix I put together puts similar logic into TexUnpackSurface::Validate, which is called earlier in the pipeline and feels more semantically appropriate.
Comment 12•9 months ago
|
||
feels more semantically appropriate.
I'd love to understand more about what you mean by "semantically appropriate"? What are you looking for/at when making that determination?
Comment 13•9 months ago
|
||
(In reply to evyatar from comment #12)
feels more semantically appropriate.
I'd love to understand more about what you mean by "semantically appropriate"? What are you looking for/at when making that determination?
Really that the method is called Validate(). Semantically it seems to guarantee that the unpack will succeed.
Upon reflection, I'll probably need to add something to TexUnpackSurface::TexOrSubImage simlar to, if not identical to what is proposed in comment 9. That will prevent any actual over-read from happening even if some behavior in Validate() fails to identify a dangerous case. Fixing that will also settle things for any future code analysis that doesn't know that Validate() will be called first.
| Assignee | ||
Comment 14•9 months ago
•
|
||
So it seems like the proposed fix by Claude is incorrect in that structuredSrcSize exists because you can use a source surface whose size is actually explicitly different the desired size of the destination texture. There are other fields that then tell how to map the different source size to the destination. So rather, there is more likely something going on with how those "other fields" are being passed in and used in this case that requires further investigation. Using Claude's proposed fix would actually break a lot of valid use-cases.
So while the Claude solution seems superficially correct, it only does it by disabling functionality that is necessary.
| Assignee | ||
Comment 15•9 months ago
|
||
| Assignee | ||
Comment 16•9 months ago
|
||
I've proposed a different fix wherein we merely constrain that the source surface is at least as big as the size of destination texture region.
This is to allow for the explicit WebGL2 behavior that if you upload a larger TexImageSource to the texture region, then it effectively uses a subrect window of the TexImageSource for upload, in combination with SKIP_PIXELS and SKIP_ROWS to control where that subrect is sourced from.
Updated•9 months ago
|
| Assignee | ||
Comment 18•9 months ago
|
||
Comment on attachment 9543787 [details]
(secure)
Security Approval Request
- How easily could an exploit be constructed based on the patch?: The check does seem suggestive to anyone reading that the surface's size and the destination size can be used in an exploit.
- Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: Unknown
- 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?: Bug 1750310
- Do you have backports for the affected branches?: Yes
- If not, how different, hard to create, and risky will they be?:
- How likely is this patch to cause regressions; how much testing does it need?: Unlikely
- Is the patch ready to land after security approval is given?: Yes
- Is Android affected?: Yes
| Assignee | ||
Updated•9 months ago
|
Updated•9 months ago
|
Comment 19•9 months ago
|
||
Comment on attachment 9543787 [details]
(secure)
sec-approval+
Updated•9 months ago
|
Comment 20•9 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined: Out of bound memory access in GPU/parent process.
- Code covered by automated testing: no
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: Just adds an extra sanity check.
- String changes made/needed: No
- Is Android affected?: yes
| Assignee | ||
Comment 21•9 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D282553
Comment 22•9 months ago
|
||
Comment 23•9 months ago
|
||
firefox-esr115 Uplift Approval Request
- User impact if declined: Out of bound memory access in GPU/parent process.
- Code covered by automated testing: no
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: Just adds an extra sanity check.
- String changes made/needed: No
- Is Android affected?: yes
| Assignee | ||
Comment 24•9 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D282553
Comment 25•9 months ago
|
||
firefox-esr140 Uplift Approval Request
- User impact if declined: Out of bound memory access in GPU/parent process.
- Code covered by automated testing: no
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: Just adds an extra sanity check.
- String changes made/needed: No
- Is Android affected?: yes
| Assignee | ||
Comment 26•9 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D282553
Comment 27•9 months ago
|
||
Comment 28•9 months ago
|
||
Backed out for causing build bustages @ TexUnpackBlob.cpp
| Assignee | ||
Comment 29•9 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D282553
Updated•9 months ago
|
Comment 30•9 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined: Boundary exploit
- Code covered by automated testing: no
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: Adds sanity check
- String changes made/needed: No
- Is Android affected?: yes
Comment 31•9 months ago
|
||
firefox-esr140 Uplift Approval Request
- User impact if declined: Boundary exploit
- Code covered by automated testing: no
- Fix verified in Nightly: yes
- Needs manual QE test: no
- Steps to reproduce for manual QE testing:
- Risk associated with taking this patch: low
- Explanation of risk level: Adds sanity check
- String changes made/needed: No
- Is Android affected?: yes
| Assignee | ||
Comment 32•9 months ago
|
||
Original Revision: https://phabricator.services.mozilla.com/D282553
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
Comment 33•9 months ago
|
||
Comment 34•9 months ago
|
||
Comment 35•9 months ago
|
||
dom/canvas/TexUnpackBlob.cpp:X:9: error: unknown type name 'IntSize'
Comment 36•9 months ago
|
||
Updated•9 months ago
|
Updated•9 months ago
|
| Assignee | ||
Comment 37•9 months ago
|
||
Comment on attachment 9543787 [details]
(secure)
Beta/Release Uplift Approval Request
- User impact if declined/Reason for urgency: Out of bounds memory access in GPU/parent process.
- Is this code covered by automated tests?: Unknown
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: None
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): Just adds a sanity check.
- String changes made/needed:
- Is Android affected?: Yes
ESR Uplift Approval Request
- If this is not a sec:{high,crit} bug, please state case for ESR consideration:
- User impact if declined:
- Fix Landed on Version: 149
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky):
Comment 38•9 months ago
|
||
Comment 39•9 months ago
|
||
Comment on attachment 9543787 [details]
(secure)
Approved for 148.0b15
Comment 40•9 months ago
|
||
| uplift | ||
Updated•9 months ago
|
Comment 41•9 months ago
|
||
Comment on attachment 9543787 [details]
(secure)
Approved for 140.8esr
Comment 42•9 months ago
|
||
| uplift | ||
Updated•9 months ago
|
Comment 43•9 months ago
|
||
Comment on attachment 9543787 [details]
(secure)
Approved for 115.33esr
Comment 44•9 months ago
|
||
| uplift | ||
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
Updated•9 months ago
|
Comment 46•8 months ago
|
||
2 months ago, dveditz placed a reminder on the bug using the whiteboard tag [reminder-test 2026-04-07] .
lsalzman, please refer to the original comment to better understand the reason for the reminder.
Updated•2 months ago
|
Description
•