CVE-2026-59014 AI-generated analysis
platform/frameworks/native, libgui DisplayLuts / RenderEngine LutShader / SurfaceFlinger CompositionEngine OutputLayer
Adds structural and bounds validation (isValid/getMaxEndOffset/getElementsNeededPerChannel) to gui::DisplayLuts and rejects invalid LUTs at readFromParcel with BAD_VALUE. LutShader::lutShader now skips invalid LUTs, sizes its read-only mmap from the ashmem region and no longer aborts on mmap failure. OutputLayer::writeLutToHWC only forwards LUTs that pass isValid().
Root cause
gui::DisplayLuts (fd, offsets, lutProperties) was unparceled in readFromParcel without any consistency checks. In libs/renderengine/skia/filters/LutShader.cpp LutShader::lutShader, the old code only required fd.ok(). It then computed an int fullLength from the last entry only (offsets[last] + size, or size*size*size*3 with unchecked int multiplication) and mmap'd fullLength*sizeof(float) bytes of the supplied fd with PROT_READ|PROT_WRITE. It called LOG_ALWAYS_FATAL("mmap failed") on failure and copied ptr..ptr+fullLength into a std::vector. Nothing tied fullLength to the actual ashmem region size. Offsets could be negative, offsets.size() could differ from lutProperties.size() (lutProperties[i] was indexed by the offsets index), dimension and size were unchecked, and per-LUT lengths were derived from offset differences rather than the declared size. services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp OutputLayer::writeLutToHWC forwarded any non-null luts to the HWC. Crafted values could therefore make SurfaceFlinger read past the mapped region or abort.
How the fix works
- libs/gui/DisplayLuts.cpp DisplayLuts::Entry::getElementsNeededPerChannel (new): returns 0 for size <= 0 or for a dimension other than 1 or 3; for dimension 3 it computes size^3 with __builtin_mul_overflow and returns 0 on overflow.
- libs/gui/DisplayLuts.cpp DisplayLuts::getMaxEndOffset (new): for every entry, computes totalElementsNeeded (x3 for 3D, overflow-checked), rejects a negative offsets[i] and computes offsets[i]+totalElementsNeeded with __builtin_add_overflow. It returns the maximum end offset in floats, or 0 on any invalid entry.
- libs/gui/DisplayLuts.cpp DisplayLuts::isValid (new): requires fd.ok(), non-empty offsets and lutProperties of equal length, and an ashmem_get_size_region(fd) result > 0 that is a multiple of sizeof(float). It also requires getMaxEndOffset() != 0 and maxEndOffset <= the ashmem float count.
- libs/gui/DisplayLuts.cpp DisplayLuts::readFromParcel: after reading the fd, offsets and entries, calls isValid(). On failure it resets the fd, clears offsets and lutProperties and returns BAD_VALUE.
- libs/renderengine/skia/filters/LutShader.cpp LutShader::lutShader: returns the input unchanged if displayLuts is null or !isValid() (before the de-gamma step). bufferSize now comes from ashmem_get_size_region(fd), and the mmap is PROT_READ only. MAP_FAILED now logs and returns the input instead of calling LOG_ALWAYS_FATAL. Exactly getMaxEndOffset() floats are copied. The per-LUT length passed to generateLutShader is getElementsNeededPerChannel() (bailing out if 0) instead of the offset difference (divided by 3 for 3D).
- services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp OutputLayer::writeLutToHWC: builds the HWC Luts only when outputIndependentState.luts->isValid(); otherwise an empty Luts object is sent.
- libs/gui/include/gui/DisplayLuts.h declares getElementsNeededPerChannel, isValid and getMaxEndOffset. libs/gui/tests/DisplayLuts_test.cpp and tests/Android.bp add unit tests for valid and invalid sizes, negative offsets, out-of-bounds offsets and a parcel round trip.
Completeness
- Validation is enforced in DisplayLuts::readFromParcel. Both consumers changed in the diff (LutShader::lutShader and OutputLayer::writeLutToHWC) also re-check isValid() at use time.
- getMaxEndOffset now accounts for all entries (the old code looked only at the last one), and each arithmetic step uses overflow-checked builtins.
- isValid does not check that LUT ranges are non-overlapping or that offsets are ordered; each range is individually bounded by the ashmem size.
- isValid rejects an ashmem_get_size_region result <= 0 or one that is not a multiple of sizeof(float). The <sys/stat.h> include is added, but no fstat-based path appears in the diff.
- The Android 16 DisplayLuts header in the diff has no dump(). The Android 17 commit also converts DisplayLuts::dump() to use isValid()/getMaxEndOffset()/ashmem_get_size_region.
Behavior changes
- DisplayLuts::readFromParcel now returns BAD_VALUE and empties the object for any of these: a bad fd, empty or mismatched offsets/lutProperties, a dimension other than 1 or 3, size <= 0, size^3 overflow, a negative offset, an ashmem size that is not a positive multiple of sizeof(float), or a LUT end offset beyond the ashmem region.
- When mmap fails, LutShader::lutShader now returns the input shader instead of aborting. It maps the region PROT_READ instead of PROT_READ|PROT_WRITE, and invalid LUTs are skipped.
- The per-LUT length argument passed to generateLutShader is now derived from the declared size (size or size^3) rather than from the gap to the next offset.
- writeLutToHWC sends an empty Luts object to the HWC when the stored luts object is invalid, instead of forwarding it.
- New ALOGW diagnostics for each rejected condition.
Per major
- Android 14: Not affected per the bulletin. Only 4/8 lines of the patched region are present at android-security-14.0.0_r31; whether the DisplayLuts code exists there is not shown.
- Android 15: Not affected per the bulletin. Only 4/8 lines of the patched region are present at android-security-15.0.0_r19; whether the DisplayLuts code exists there is not shown.
- Android 16: Same fix: commit 489ee4289d21 in android-security-16.0.0_r10 (cherry-pick of two internal changes, Change-Id If00ecae8a641cf85dc257553dabff590d26a0f0a); 8/8 lines present.
- Android 17: Adapted fix: commit e3fa10f43245 in android-security-17.0.0_r3. It has the same DisplayLuts.cpp/.h/test changes, plus DisplayLuts::dump() rewritten to use isValid()/getMaxEndOffset() and the ashmem size. LutShader::lutShader is adapted to the 17 code (no de-gamma color space block, uses mEffect). OutputLayer::writeLutToHWC checks sourceLuts->isValid(), where sourceLuts may come from the layer luts or getState().generatedLuts. 7/8 lines present.
Unknowns
- The exact failure the PoC triggered (out-of-bounds read of the mapping, overflowed length, mismatched vector sizes, or the mmap LOG_ALWAYS_FATAL) is not shown; the commit only says crafted DisplayLuts can crash SurfaceFlinger.
- Whether the ashmem region size can change between isValid() and the later mmap in lutShader is not shown.
- How ashmem_get_size_region behaves for fds that are not ashmem regions is not shown.
- How the changed length argument affects sampling inside generateLutShader is not shown.
- Whether the Java-side DisplayLuts.valid() check can be bypassed is not shown.
- The contents of the two internal source changes merged into this cherry-pick are not shown separately.