git: 2a61bc857f23 - releng/15.2 - inotify: Make the oneshot watch lookup stricter

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 17:09:35 UTC
The branch releng/15.2 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=2a61bc857f23440bb51dee4555c11727adc038f9

commit 2a61bc857f23440bb51dee4555c11727adc038f9
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-10-28 19:31:13 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-17 13:34:30 +0000

    inotify: Make the oneshot watch lookup stricter
    
    inotify_log_one() needs to handle one-shot watches, which are removed
    from the inotify descriptor after the first event.  To handle races with
    a close of the inotify descriptor, which frees all watches, it re-looks
    up the watch in the descriptor's watch tree, which is keyed by the watch
    descriptor number.
    
    inotify_log_one() assumed that presence of the watch descriptor in the
    tree meant that the watch on which it is operating is also present in
    the tree.  However, watch descriptors are 32 bits wide and malicious
    userspace can trigger descriptor reuse such that this assumption is
    false, and inotify_log_one() ends up freeing the wrong watch, resulting
    in an exploitable use-after-free.
    
    Approved by:    re (cperciva)
    Approved by:    so
    Security:       FreeBSD-SA-26:80.vfs
    Security:       CVE-2026-101316
    Fixes:          f1f230439fa4 ("vfs: Initial revision of inotify")
    Reported by:    OpenAI Security Research Team
    Sponsored by:   The FreeBSD Foundation
---
 sys/kern/vfs_inotify.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/vfs_inotify.c b/sys/kern/vfs_inotify.c
index fe9dedfaa942..fceadce25515 100644
--- a/sys/kern/vfs_inotify.c
+++ b/sys/kern/vfs_inotify.c
@@ -660,7 +660,7 @@ inotify_log_one(struct inotify_watch *watch, const char *name, size_t namelen,
 		 * responsible for freeing it.
 		 */
 		key.wd = watch->wd;
-		if (RB_FIND(inotify_watch_tree, &sc->watches, &key) != NULL) {
+		if (RB_FIND(inotify_watch_tree, &sc->watches, &key) == watch) {
 			RB_REMOVE(inotify_watch_tree, &sc->watches, watch);
 			inotify_unlink_watch_locked(sc, watch);