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...
Keywords:
Status: NEW
Alias: CVE-2022-1998
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard:
Depends On: 2054337 2100470 2054336 2100329
Blocks: 2047918
TreeView+ depends on / blocked
 
Reported: 2022-02-09 00:39 UTC by Todd Cullum
Modified: 2022-07-16 03:22 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:
Environment:
Last Closed:


Attachments (Terms of Use)

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@grsecurity.net (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@oracle.com>
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@oracle.com>
    Reviewed-by: Mathias Krause <minipli@grsecurity.net>
    Signed-off-by: Jan Kara <jack@suse.cz>

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.


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