fontconfig/src
Tobias Stoeckmann 7a4a5bd789 Properly validate offsets in cache files.
The cache files are insufficiently validated. Even though the magic
number at the beginning of the file as well as time stamps are checked,
it is not verified if contained offsets are in legal ranges or are
even pointers.

The lack of validation allows an attacker to trigger arbitrary free()
calls, which in turn allows double free attacks and therefore arbitrary
code execution. Due to the conversion from offsets into pointers through
macros, this even allows to circumvent ASLR protections.

This attack vector allows privilege escalation when used with setuid
binaries like fbterm. A user can create ~/.fonts or any other
system-defined user-private font directory, run fc-cache and adjust
cache files in ~/.cache/fontconfig. The execution of setuid binaries will
scan these files and therefore are prone to attacks.

If it's not about code execution, an endless loop can be created by
letting linked lists become circular linked lists.

This patch verifies that:

- The file is not larger than the maximum addressable space, which
  basically only affects 32 bit systems. This allows out of boundary
  access into unallocated memory.
- Offsets are always positive or zero
- Offsets do not point outside file boundaries
- No pointers are allowed in cache files, every "pointer or offset"
  field must be an offset or NULL
- Iterating linked lists must not take longer than the amount of elements
  specified. A violation of this rule can break a possible endless loop.

If one or more of these points are violated, the cache is recreated.
This is current behaviour.

Even though this patch fixes many issues, the use of mmap() shall be
forbidden in setuid binaries. It is impossible to guarantee with these
checks that a malicious user does not change cache files after
verification. This should be handled in a different patch.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-05 14:35:05 +09:00
..
Makefile.am Linearly interpolate weight values 2014-07-25 18:07:59 -04:00
fcarch.c Fix assertion on 32bit arch 2015-10-16 17:24:22 +09:00
fcarch.h Minor 2013-08-21 14:27:16 -04:00
fcatomic.c Bug 95477 - FcAtomicLock fails when SELinux denies link() syscall with EACCES 2016-05-19 11:11:46 +09:00
fcatomic.h Update mingw32 MemoryBarrier from HarfBuzz 2014-07-11 12:20:24 -04:00
fcblanks.c Fix an infinite loop in FcBlanksIsMember() 2015-03-09 12:20:22 +09:00
fccache.c Properly validate offsets in cache files. 2016-08-05 14:35:05 +09:00
fccfg.c Optimizations in FcStrSet 2016-01-12 10:42:40 +09:00
fccharset.c Bug 90867 - Memory Leak during error case in fccharset 2015-06-24 15:46:45 +09:00
fccompat.c Export recently added API 2014-07-26 16:17:02 -04:00
fcdbg.c Fix a crash when no objects are available after filtering 2015-06-09 11:15:06 +09:00
fcdefault.c remomve unnecessary code 2015-11-18 14:44:17 +09:00
fcdeprecate.h Export FcConfig{G,S}etRescanInverval from .so, mark as deprecated. 2007-11-04 12:20:45 -08:00
fcdir.c Revert "Workaround another race condition issue" 2016-04-06 14:39:15 +09:00
fcformat.c Don't crash in FcPatternFormat() with NULL pattern 2013-01-01 20:20:31 -06:00
fcfreetype.c Remove unused code 2016-06-15 20:10:31 +09:00
fcfs.c Improve the performance issue on rescanning directories 2013-12-20 11:57:16 +09:00
fcftint.h Remove all training whitespaces 2010-04-12 12:19:05 -04:00
fcinit.c Fix memory leaks after FcFini() 2015-05-22 16:53:34 +09:00
fcint.h Revert "Workaround another race condition issue" 2016-04-06 14:39:15 +09:00
fclang.c Allow the modification on FcTypeVoid with FcTypeLangSet and FcTypeCharSet 2014-05-13 21:22:17 +09:00
fclist.c Fix pointer cast warning on win32 2015-02-24 15:25:16 +09:00
fcmatch.c Add one more debugging option to see transformation on font-matching 2015-06-08 17:39:25 +09:00
fcmatrix.c Remove memory accounting and reporting 2012-12-29 23:12:07 -05:00
fcmutex.h Fix build and warnings on win32 2013-01-02 17:35:56 -06:00
fcname.c Simplify FcRange 2015-05-27 14:18:28 -07:00
fcobjs.c Revert the previous change 2015-05-25 21:41:05 +09:00
fcobjs.h Add su[pport for symbol fonts 2015-05-18 15:26:03 -07:00
fcobjshash.gperf.h Add missing license headers 2014-01-17 13:05:25 +09:00
fcpat.c Add one more debugging option to see transformation on font-matching 2015-06-08 17:39:25 +09:00
fcrange.c Simplify FcRange 2015-05-27 14:18:28 -07:00
fcserialize.c Fix more warnings 2012-12-29 22:56:14 -05:00
fcstat.c Fix the array allocation 2015-03-03 11:30:12 +09:00
fcstr.c Optimizations in FcStrSet 2016-01-12 10:42:40 +09:00
fcweight.c Bug 96676 - Check range of FcWeightFromOpenType argument 2016-07-08 14:18:35 +09:00
fcwindows.h More mingw32 MemoryBarrier() fixup 2014-07-19 16:33:49 -04:00
fcxml.c Bug 95481 - Build fails on Android due to broken lconv struct 2016-05-27 11:16:09 +09:00
ftglue.c Fix more warnings 2012-12-29 22:56:14 -05:00
ftglue.h Remove unused ftglue code 2009-06-28 14:14:46 -04:00
makealias Bug 48020 - Fix for src/makealias on Solaris 10 2012-03-29 15:43:38 +09:00