Apport follows symbolic links in path components when creating core dump file

Bug #1839414 reported by Alex Murray
262
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Apport
New
High
Unassigned
apport (Ubuntu)
New
High
Unassigned

Bug Description

Author: Sander Bos, <https://www.sbosnet.nl/>

Date: 2019-07-30

In data/apport, Apport (implicitly) protects against symbolic link
following for to be created core dump files, but not sufficiently:

    181 core_path = os.path.join(cwd, 'core')
    ...
    186 core_file = os.open(core_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)

When Apport opens (creates, actually) the core dump file in the
second line, symbolic link following is (implicitly) prevented due to
the combination of "os.O_CREAT" and "os.O_EXCL". However, this only
applies to the final path component of "core_path" (the core dump file
name of "core"), _not_ for the earlier path components (taken from
"cwd"). For those path components, no such prevention is explicitly
applied either. Thus, symbolic links in path components before "core"
are followed. Combined with a different issue of "cwd" being replaced
after reading out the current working directory but before using the "cwd"
variable's value, users may be able to replace any path component of the
"cwd" file system entry with a symbolic link pointing to an arbitrary
location on the file system.

This can for example be used to place core dumps in arbitrary (but
user-writable) directories different than the actual current working
directory of the crashed process, or even (user-writable) directories
outside the root directory in case of a chroot()ed crashed process or
outside of a container / sandbox in case of a containerized / sandboxed
process (because Apport is ran from the host's root file system, not
within such environment).

Proposed fix: make Apport not follow symbolic links in non-last path
components when writing core dump files.

CVE References

Changed in apport (Ubuntu):
importance: Undecided → High
Changed in apport:
importance: Undecided → High
Revision history for this message
Seth Arnold (seth-arnold) wrote :

Do we want to mitigate this one?

The usual approach is to break paths apart into components, use O_PATH and openat(2) to walk each component individually, checking fstat(2) to make sure that the owner and permissions are correct on each (for whatever 'correct' may mean), etc.

The alternative is to make sure that apport is running with the appropriate user permissions (again, for whatever definition of 'appropriate') so that the final component, the filename, is only written into a directory that the user can legitimately write into anyway.

Quite a lot of programs never bother with the complicated O_PATH version.

If apport is writing these files as an incorrect user that ought to be addressed and may also address this at the same time.

Thanks

Revision history for this message
Alex Murray (alexmurray) wrote :

A CRD has been confirmed for this issue - Tuesday next week - 2019/10/29 (this is mitigated by the same fix as for bug #1839413)

Revision history for this message
Alex Murray (alexmurray) wrote :

Seth can we please assign a separate CVE for this?

Revision history for this message
Seth Arnold (seth-arnold) wrote :

Alex, I believe CVE-2019-11482 assigned for bug #1839413 covers this issue too -- the flaw is that cwd is being used in a way that allows for race conditions. This is two routes to exploit one underlying flaw.

Am I wrong?

Thanks

Revision history for this message
Alex Murray (alexmurray) wrote :

Ok on further thought I agree - the primary bug is that cwd was racy (and hence could also be exploited via symlinks as a result) - closing this as a duplicate of bug #1839413.

Alex Murray (alexmurray)
information type: Private Security → Public Security
tags: added: id-5d640f669cd10e562c3038cf
To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.