Bug 2052312 (CVE-2022-1998) - CVE-2022-1998 kernel: fanotify misuses fd_install() which could lead to use-after-free
Summary: CVE-2022-1998 kernel: fanotify misuses fd_install() which could lead to use-a...
Alias: CVE-2022-1998
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
Depends On: 2054336 2054337 2100329 2100470
Blocks: 2047918
TreeView+ depends on / blocked
Reported: 2022-02-09 00:39 UTC by Todd Cullum
Modified: 2023-05-12 20:04 UTC (History)
51 users (show)

Fixed In Version: Linux kernel 5.17-rc3
Doc Type: If docs needed, set a value
Doc Text:
A use-after-free flaw was found in the Linux kernel’s File System notify functionality in the way a user triggers the copy_info_records_to_user() function call to fail in copy_event_to_user(). This flaw allows a local user to crash or potentially escalate their privileges on the system.
Clone Of:
Last Closed: 2022-12-05 10:36:35 UTC

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2022:7933 0 None None None 2022-11-15 09:44:30 UTC
Red Hat Product Errata RHSA-2022:8267 0 None None None 2022-11-15 10:47:04 UTC

Description Todd Cullum 2022-02-09 00:39:37 UTC
In kernel's fanotify, if the copy_info_records_to_user() call in copy_event_to_user() fails,
it'll erroneously call put_unused_fd(fd) + fput(f) on a file that was
already populated by fd_install(). The erroneous code path, however, is
only reachable by privileged users, as one needs to pass the
"!FAN_GROUP_FLAG(group, FANOTIFY_UNPRIV)" test which won't if one isn't
already capable(CAP_SYS_ADMIN), i.e. has the CAP_SYS_ADMIN capability in
the _init_ user namespace, which basically means root.

The bug was introduced by commit f644bc449b37 ("fanotify: fix
copy_event_to_user() fid error clean up"), which is Linux v5.13.

Reference: minipli (OSS-Security)

Comment 1 juneau 2022-02-09 13:08:09 UTC
Marking Services notaffected per kernel analysis.

Comment 3 Alex 2022-02-14 17:21:32 UTC
Created kernel tracking bugs for this issue:

Affects: fedora-all [bug 2054336]

Comment 8 Eric Sandeen 2022-05-09 15:42:14 UTC
commit ee12595147ac1fbfb5bcb23837e26dd58d94b15d
Author: Dan Carpenter <dan.carpenter>
Date:   Fri Jan 28 22:57:01 2022 +0300

    fanotify: Fix stale file descriptor in copy_event_to_user()
    This code calls fd_install() which gives the userspace access to the fd.
    Then if copy_info_records_to_user() fails it calls put_unused_fd(fd) but
    that will not release it and leads to a stale entry in the file
    descriptor table.
    Generally you can't trust the fd after a call to fd_install().  The fix
    is to delay the fd_install() until everything else has succeeded.
    Fortunately it requires CAP_SYS_ADMIN to reach this code so the security
    impact is less.
    Fixes: f644bc449b37 ("fanotify: fix copy_event_to_user() fid error clean up")
    Link: https://lore.kernel.org/r/20220128195656.GA26981@kili
    Signed-off-by: Dan Carpenter <dan.carpenter>
    Reviewed-by: Mathias Krause <minipli>
    Signed-off-by: Jan Kara <jack>

Comment 13 Justin M. Forbes 2022-06-10 17:32:19 UTC
This was fixed for Fedora with the 5.16.6 stable kernel update.

Comment 23 errata-xmlrpc 2022-11-15 09:44:28 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9

Via RHSA-2022:7933 https://access.redhat.com/errata/RHSA-2022:7933

Comment 24 errata-xmlrpc 2022-11-15 10:47:01 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9

Via RHSA-2022:8267 https://access.redhat.com/errata/RHSA-2022:8267

Comment 25 Product Security DevOps Team 2022-12-05 10:36:31 UTC
This bug is now closed. Further updates for individual products will be reflected on the CVE page(s):


Note You need to log in before you can comment on or make changes to this bug.