CVE-2017-15126: Use After Free

Published Dec 8, 2017
·
Updated

A flaw was found in the Linux kernels handling of fork failure when dealing with event messages in the userfaultfd code. Failure to fork correctly can lead to a situation where a fork event will be removed from an already freed list of events with userfaultfdctxput(). The userfault events are part of the slab cache, and the secondary free could only free other event list objects as the free mechanism uses the underlying kmemcache implementation making generic use-after-free style attacks less effective.

While technically a use after free style flaw, at this time Red Hat Product security believes this flaw to be difficult to exploit but this may change in the future.

From the commit:

When reading the event from the uffd, we put it on a temporary forkevent list to detect if we can still access it after releasing and retaking the eventwqh.lock.

If fork aborts and removes the event from the forkevent all is fine as long as we're still in the userfault read context and forkevent head is still alive.

We've [forgotten] to put the event allocated in the fork kernel stack, back from forkevent list-head to the eventwqh head, before returning from userfaultfdctxread, because the forkevent head lifetime is limited to the userfaultfdctxread stack lifetime.

Forgetting to move the event back to its eventwqh place then results in removewaitqueue(&ctx->eventwqh, &ewq->wq); in userfaultfdeventwaitcompletion to remove it from a head that has been already freed from the reader stack.

This could only happen if resolveuserfaultfork failed (for example if there are no file descriptors available to allocate the fork uffd). If it succeeded it was put back correctly.

Furthermore, after finduserfaultevt receives a fork event, the forked userfault context in forknctx and uwq->msg.arg.reserved.reserved1 can be released by the fork thread as soon as the eventwqh.lock is released. Taking a reference on the forknctx before dropping the lock prevents an use after free in resolveuserfaultfork().

If the fork side aborted and it already released everything, we still try to succeed resolveuserfaultfork(), if possible. -- end ---

References:

https://marc.info/?t=150351212000001&r=1&w=2

An upstream patch:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=384632e67e0829deb8015ee6ad916b180049d252

Other sources

A use-after-free flaw was found in fs/userfaultfd.c in the Linux kernel before 4.13.6. The issue is related to the handling of fork failure when dealing with event messages. Failure to fork correctly can lead to a situation where a fork event will be removed from an already freed list of events with userfaultfdctxput().

— MITRE

Affected Software

2 affected components
Linux Linux kernel>=4.11<4.13.6
Linux Linux kernel=4.13.6

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade Linux kernel to a version that resolves this vulnerability.

    Fixed in 4.13.6

Event History

Dec 8, 2017
Data Sourced
via Red Hat·06:07 AM
DescriptionSeverityAffected Software
Jan 14, 2018
CVE Published
via MITRE·06:00 AM
Data Sourced
via MITRE·06:00 AM
DescriptionWeakness
Event
via NVD·06:29 AM

Frequently Asked Questions

1

What conditions are needed to trigger this flaw?

The issue involves a fork failure while processing userfaultfd event messages. Exploitation requires reaching the affected userfaultfd fork-event handling path and causing the fork to abort or fail.

2

How practical is exploitation?

Red Hat Product Security assessed the flaw as difficult to exploit at the time of disclosure. The secondary free is constrained to other event-list objects from the relevant slab cache, which makes generic use-after-free attack techniques less effective; this assessment could change with new research.

3

What happens when the vulnerable path is triggered?

A fork event can be removed from an event list after it has already been freed through userfaultfd_ctx_put(). This creates a use-after-free-style condition involving userfault event objects managed through the slab cache.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203