Commit Graph

985 Commits

Author SHA1 Message Date
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
Akira TAGOH 99645ff9ee Bug 96676 - Check range of FcWeightFromOpenType argument
Fix a crash issue when FcWeightFromOpenType() gets a number more than it expects.
2016-07-08 14:18:35 +09:00
Akira TAGOH add5f7329f Remove unused code 2016-06-15 20:10:31 +09:00
Erik de Castro Lopo ea26c5e9f8 Fix a couple of minor memory leaks
These fixes are needed for the test suite to pass when compiled
with Address Sanitizer.
2016-05-30 10:30:10 +09:00
Akira TAGOH 7441dbec03 Bug 95481 - Build fails on Android due to broken lconv struct 2016-05-27 11:16:09 +09:00
Petr Filipsky d15c46d75e Fix memory leak in FcDirCacheLock 2016-05-23 11:09:22 +09:00
Akira TAGOH 9ab7633f2f Bug 95477 - FcAtomicLock fails when SELinux denies link() syscall with EACCES
This is an issue on Android M, which denies non-root users access to link().

Patch from Rodger Combs
2016-05-19 11:11:46 +09:00
Akira TAGOH d179cbc253 Revert "Workaround another race condition issue"
This reverts commit f44bfad235.
2016-04-06 14:39:15 +09:00
Behdad Esfahbod d05d083e9f [GX] Improve weight mapping
Align the 'wght' axis default value to OS/2 weight value and
adjust accordingly.  This makes both default=1.0 and default=400
models to work.
2016-03-08 17:20:55 -08:00
Behdad Esfahbod d709220d74 Improve OpenType to Fontconfig weight mapping 2016-03-08 17:20:28 -08:00
Behdad Esfahbod 27d61f1ddc [GX] Enumerate all named-instances in TrueType GX fonts 2016-03-08 13:39:05 -08:00
Behdad Esfahbod 00c8408c6a [GX] Support instance weight, width, and style name 2016-03-08 13:39:05 -08:00
Behdad Esfahbod 28f62d1bb8 Call FcFreeTypeQueryFace() from fcdir.c, instead of FcFreeTypeQuery()
Need for upcoming work.  No functional change expected.
2016-03-08 13:39:05 -08:00
Patrick Haller d570a841a2 Optimizations in FcStrSet
Applied optimizations:
- skip duplicate check in FcStrSetAppend for values originating from readdir()
- grow FcStrSet in 64-element bulks for local FcStrSets (FcConfig layout unaltered)

Starting gedit is measured to

                        Unoptimized     Optimized
user[s]                         0,806         0,579
sys[s]                          0,062         0,062
Total Instr Fetch Cost: 1.658.683.750   895.069.820
Cachegrind D Refs:        513.917.619   312.000.436
Cachegrind Dl Misses:       8.605.632     4.954.639
2016-01-12 10:42:40 +09:00
Akira TAGOH 1d87fab8b1 remomve unnecessary code 2015-11-18 14:44:17 +09:00
Akira TAGOH d162a4a83d Fix assertion on 32bit arch 2015-10-16 17:24:22 +09:00
Akira TAGOH bd96984e4b Use int64_t instead of long long 2015-10-15 15:51:50 +09:00
Akira TAGOH 7ccde89758 Fix build issue on MinGW 2015-10-13 13:06:54 +09:00
Akira TAGOH a44cc450b5 Use long long to see the same size between LP64 and LLP64 2015-10-13 13:04:33 +09:00
Akira TAGOH ad9f588050 Fix the broken cache more.
Take a look at the nano second in the mtime to figure out
if the cache needs to be updated if available.
and do the mutex lock between scanning and writing a cache
to avoid the conflict.

Also we don't need to scan directories again after writing
caches. so getting rid of the related code as well.

https://bugs.freedesktop.org/show_bug.cgi?id=69845

and for reference:

https://bugzilla.redhat.com/show_bug.cgi?id=1236034
2015-08-14 17:19:29 +09:00
Behdad Esfahbod 46ec6a52d4 Revert changes made to FcConfigAppFontAddDir() recently
In 32ac7c75e8 the behavior of
FcConfigAppFontAddFile/Dir() were changed to return false
if not fonts were found.  While this is welldefined and useful
for AddFile(), it's quite problematic for AddDir().  For example,
if the directory is empty, is that a failure or success?  Worse,
the false value from AddDir() was being propagated all the way
to FcInit() returning false now.  This only happened upon memory
allocation failure before, and some clients assert that FcInit()
is successful.

With this change, AddDir() is reverted back to what it was.
AddFont() change (which was actually in fcdir.c) from the original
commit is left in.
2015-06-26 17:02:13 -07:00
Akira TAGOH a8096dfa59 Bug 90867 - Memory Leak during error case in fccharset
https://bugs.freedesktop.org/show_bug.cgi?id=90867
2015-06-24 15:46:45 +09:00
Akira TAGOH 6f929ff37c Fix a memory leak in FcFreeTypeQueryFace 2015-06-17 16:34:29 +09:00
Akira TAGOH 46b2c62faa Add a warning for blank in fonts.conf
and remove the unnecessary code for parsing blanks
2015-06-17 16:29:08 +09:00
Akira TAGOH 33fd436a3e Don't return FcFalse even when no fonts dirs is configured 2015-06-17 16:15:35 +09:00
Akira TAGOH f6d61c9bee mark as private at this moment 2015-06-12 11:30:01 +09:00
Akira TAGOH dbda117142 No need to be public 2015-06-09 11:15:25 +09:00
Akira TAGOH 359ada2b4c Fix a crash when no objects are available after filtering 2015-06-09 11:15:06 +09:00
Akira TAGOH 10a57edd07 Add one more debugging option to see transformation on font-matching
just setting FC_MATCH=3 shows a lot of information and hard to keep on track for informamtion
which is really necessary to see. to use this more effectively, added FC_DBG_MATCH_FILTER to
see for what one really want to see. it takes a comma-separated-list of object names.
If you want to see family name only, try like this:

FC_DBG_MATCH_FILTER=family FC_DEBUG=4096 fc-match

debugging output will be filtered out and see family only in the result.
2015-06-08 17:39:25 +09:00
Behdad Esfahbod ee2d1da2d2 Reduce number of places that cache version is specified to 1 2015-05-27 14:36:35 -07:00
Behdad Esfahbod 5bad26ccb6 Simplify FcRange 2015-05-27 14:18:28 -07:00
Behdad Esfahbod 13a5ae9fb9 Fix compiler warnings 2015-05-27 14:12:49 -07:00
Behdad Esfahbod 346073d9dc Don't set FC_SIZE for bitmap fonts
They get FC_PIXELSIZE set, which is later converted to FC_SIZE using
FC_DPI.
2015-05-27 14:12:49 -07:00
Behdad Esfahbod eba6f109de Accept Integer for FC_SIZE
There are more places to fix I'm sure...

https://bugs.freedesktop.org/show_bug.cgi?id=80873
2015-05-27 14:12:49 -07:00
Behdad Esfahbod cb2f096e15 Add bitmap-only font size as Double, not Range
The whole size setting part still smells to me.
2015-05-27 14:12:49 -07:00
Behdad Esfahbod 51756aab18 Only set FC_SIZE for scalable fonts if OS/2 version 5 is present
Part of https://bugs.freedesktop.org/show_bug.cgi?id=80873
2015-05-27 14:12:49 -07:00
Behdad Esfahbod d09ba38589 Write ranges using a [start finish) format
To show closed and open ends.
2015-05-27 14:12:49 -07:00
Akira TAGOH 4c9101f704 Revert the previous change
and just abort if the object id is overflowed.
2015-05-25 21:41:05 +09:00
Akira TAGOH 09edd84cf8 Detect the overflow for the object ID
Continue to increase the object id even after FcFini()
and detect the overflow. that would be rather easier than
reset the object id with the complicated mutex and atomic
functions.

This situation would be quite unlikely to happen though
2015-05-22 20:51:21 +09:00
Akira TAGOH f053231186 Fix a crash
segfault happens when the config needs to be migrated to XDG's
and no definition for include with prefix="xdg"
2015-05-22 20:46:54 +09:00
Akira TAGOH 249306fbd7 Fix a typo 2015-05-22 20:45:05 +09:00
Akira TAGOH fa6c6b53c5 Fix memory leaks after FcFini()
Reported by Jia Wang

https://bugs.freedesktop.org/show_bug.cgi?id=83770
2015-05-22 16:53:34 +09:00
Behdad Esfahbod bcfe167e3d Add su[pport for symbol fonts
Adds FC_SYMBOL.

This affects fonts having a cmap with platform 3 encoding 0.
We now map their glyphs from the PUA area to the Latin1 area.

See thread "Webdings and other MS symbol fonts don't display"
on the mailing list.

Test before/after with:
$ pango-view --markup --text='<span fallback="false">&#xd7;&#xf0d7;</span>' --font=Wingdings
2015-05-18 15:26:03 -07:00
Akira TAGOH ead7275e05 Bug 90148 - Don't warn if cachedir isn't specified
only warn when FONTCONFIG_FILE or FONTCONFIG_PATH is set.

Bug 90148 - Don't warn if cachedir isn't specified
2015-05-18 14:03:50 +09:00
Akira TAGOH 3a4136778c Drop unmaintained code
Use four-byte code for foundry as is instead.

https://bugs.freedesktop.org/show_bug.cgi?id=88679
2015-04-22 16:29:25 +09:00
Руслан Ижбулатов f6e6a8a22b W32: Support cache paths relative to the root directory
Paths starting with '/' don't make sense on W32 as-is,
prepend the installation root directory to them.

This allows the cache to be contained within a particular
fontconfig installation (as long as the default
--with-cache-dir= is overriden at configure time).
2015-04-09 15:19:17 +09:00
Akira TAGOH 7bc07cf6c2 Fix SIGFPE 2015-03-30 15:18:44 +09:00
Akira TAGOH e92c92ff22 Fix unknown attribute in Win32 2015-03-25 12:10:48 +09:00
Akira TAGOH c965c9f677 Bug 89617 - FcConfigAppFontAddFile() returns false on any font file
Prior to the change of 32ac7c75e8
FcConfigAppFontAddFile() always returned FcTrue no matter what
fonts was added. after that, it always returned FcFalse because
adding a font doesn't add any subdirs with FcFileScanConfig().
so changing that to simply ignore it.

Also fixing it to return FcFalse if non-fonts was added, i.e.
FcFreeTypeQuery() fails.

https://bugs.freedesktop.org/show_bug.cgi?id=89617
2015-03-23 13:31:57 +09:00
Akira TAGOH 7301f2f028 Remove the dead code 2015-03-23 13:18:49 +09:00