Bug 104294 - Memory safety fixes
Summary: Memory safety fixes
Status: RESOLVED FIXED
Alias: None
Product: colord
Classification: Unclassified
Component: libcolord (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium major
Assignee: Richard Hughes
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-16 19:49 UTC by Jan Alexander Steffens (heftig)
Modified: 2018-09-18 12:17 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
[PATCH 1/2] Make cd_color_get_blackbody_rgb_full safer (2.02 KB, patch)
2017-12-16 19:51 UTC, Jan Alexander Steffens (heftig)
Details | Splinter Review
[PATCH 2/2] Avoid buffer overflow when reading profile_id (1.96 KB, patch)
2017-12-16 19:51 UTC, Jan Alexander Steffens (heftig)
Details | Splinter Review
[PATCH 2/2] Avoid buffer overflow when reading profile_id (2.30 KB, patch)
2017-12-16 20:02 UTC, Jan Alexander Steffens (heftig)
Details | Splinter Review
[PATCH] Make cd_color_get_blackbody_rgb_full safer (1.92 KB, patch)
2017-12-17 13:59 UTC, Jan Alexander Steffens (heftig)
Details | Splinter Review

Description Jan Alexander Steffens (heftig) 2017-12-16 19:49:32 UTC
I've made two fixes to memory safety in the process of tracking down a stack smashing error running the testsuite. Patches follow; one is an out-of-bounds read and the latter is an out-of-bounds write and responsible for the crash.
Comment 1 Jan Alexander Steffens (heftig) 2017-12-16 19:51:18 UTC
Created attachment 136224 [details] [review]
[PATCH 1/2] Make cd_color_get_blackbody_rgb_full safer

Validate arguments. If temp is divisible by 100, avoid interpolation
because it accesses beyond the data for temp == 10000.
Comment 2 Jan Alexander Steffens (heftig) 2017-12-16 19:51:57 UTC
Created attachment 136226 [details] [review]
[PATCH 2/2] Avoid buffer overflow when reading profile_id

The profile ID is 16 bytes, not 4 bytes. Use the union type specified by
the LCMS API.
Comment 3 Jan Alexander Steffens (heftig) 2017-12-16 20:02:01 UTC
Created attachment 136227 [details] [review]
[PATCH 2/2] Avoid buffer overflow when reading profile_id

Second version formatting the profile ID bytes individually to avoid endianness issues.
Comment 4 Richard Hughes 2017-12-17 13:25:25 UTC
I've rewrote the 2nd patch, to this:

commit 2c92e03775a15bcd304ef39e9a3220496fc9168a (HEAD -> master)
Author: Richard Hughes <richard@hughsie.com>
Date:   Sun Dec 17 13:17:27 2017 +0000

    Avoid buffer overflow when reading profile_id
    
    Based on a patch by Jan Alexander Steffens, many thanks.
    
    Fixes half of: https://bugs.freedesktop.org/show_bug.cgi?id=104294

:100644 100644 99fa27b... 5e9441a... M  lib/colord/cd-icc.c

-- this now matches the MD5 that the daemon exposes.

The first patch also now gives me:

../lib/colord/cd-color.c:1471:11: warning: function call has aggregate value [-Waggregate-return]

... which makes it fail CI.
Comment 5 Jan Alexander Steffens (heftig) 2017-12-17 13:43:51 UTC
Is -Waggregate-return really a useful warning?

But OK, I can rewrite the patch not to use div() again.
Comment 6 Jan Alexander Steffens (heftig) 2017-12-17 13:59:26 UTC
Created attachment 136239 [details] [review]
[PATCH] Make cd_color_get_blackbody_rgb_full safer

Use / and % instead of div().
Comment 7 Jan Alexander Steffens (heftig) 2018-09-18 12:17:34 UTC
commit ba4bdb6f0dadc8f2d51122bfdee9a0325302f171
Author:     Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
AuthorDate: 2017-12-16 04:18:01 +0100
Commit:     Richard Hughes <richard@hughsie.com>
CommitDate: 2018-03-27 10:26:33 +0100

    Make cd_color_get_blackbody_rgb_full safer
    
    Validate arguments:
      - temp == NaN would fail the bounds checks and could result in
        out-of-bounds reads.
      - result == NULL is an obvious error.
    
    Avoid calling cd_color_rgb_interpolate if the second point would be
    outside the data array. This only happens for temp == 10000, which makes
    the alpha 0, so one would think that the garbage read has no effect on
    the result. However, if the garbage happens to contain NaNs they would
    propagate to the output. Besides, asan and valgrind still complain.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.