Skip to content

fix(kernelmod): handle path-type fsnotify events and filter pseudo fds - #298

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
wangrong1069:pr1124
Nov 24, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
wangrong1069:pr1124

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Add FSNOTIFY_EVENT_PATH/DENTRY handling in fsnotify_broadcast_listener, and skip FMODE_NONOTIFY/FMODE_PATH fds plus fix null-deref in __fput hook.

fsnotify广播监听新增PATH/DENTRY事件处理,__fput钩子过滤
FMODE_NONOTIFY/FMODE_PATH伪文件描述符并修复空指针解引用。

Log: 修复内核模块丢失路径类事件及伪fd误触发问题
PMS: BUG-370789
Influence: 修复后内核模块能正确捕获路径类fsnotify事件,并避免fanotify自身产生的伪文件描述符误触发变更事件,提升事件采集准确性与稳定性。

Summary by Sourcery

Improve kernel filesystem notification handling by capturing path-based events and filtering non-real file descriptors.

New Features:

  • Support path- and dentry-based fsnotify events in the kernel module listener.

Bug Fixes:

  • Prevent pseudo file descriptors from generating spurious close-write events and avoid null-pointer dereferences in the file-release hook.

Enhancements:

  • Improve filesystem event collection accuracy and stability by filtering fanotify-generated and path-only descriptors.

Add FSNOTIFY_EVENT_PATH/DENTRY handling in fsnotify_broadcast_listener,
and skip FMODE_NONOTIFY/FMODE_PATH fds plus fix null-deref in __fput hook.

fsnotify广播监听新增PATH/DENTRY事件处理,__fput钩子过滤
FMODE_NONOTIFY/FMODE_PATH伪文件描述符并修复空指针解引用。

Log: 修复内核模块丢失路径类事件及伪fd误触发问题
PMS: BUG-370789
Influence: 修复后内核模块能正确捕获路径类fsnotify事件,并避免fanotify自身产生的伪文件描述符误触发变更事件,提升事件采集准确性与稳定性。
@sourcery-ai

sourcery-ai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Handle path-type fsnotify events by broadcasting from the path, and accept inode or dentry event data while retaining the existing event filters.

  • src/kernelmod/vfs_fsnotify.c L1, L205-220

Guard the __fput hook against a null file before dereferencing it, and skip write-close events for fanotify-generated and path-only file descriptors.

  • src/kernelmod/vfs_kretprobes.c L544-552 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 6 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/kernelmod/vfs_fsnotify.c" line_range="216" />
<code_context>
+        path = data;
+        if (!path || !path->dentry)
+            return;
+        fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);
+        return;
+    }
</code_context>
<issue_to_address>
**Path renames lose pairing**

When a PATH notification carries FS_MOVED_FROM or FS_MOVED_TO, especially while other zero-cookie events are queued, `fsnotify_parent_broadcast_listener` passes cookie `0` to `fsnotify_event_handler`, so `event_merge` and `do_event_merge` pair rename events with the wrong events or treat them as unrelated, and callers receive incorrect rename operations.

Forward the callback’s rename cookie through `fsnotify_parent_broadcast_listener` to `fsnotify_event_handler`.
</issue_to_address>

### Comment 2
<location path="src/kernelmod/vfs_fsnotify.c" line_range="216" />
<code_context>
+        path = data;
+        if (!path || !path->dentry)
+            return;
+        fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);
+        return;
+    }
</code_context>
<issue_to_address>
**Events use the wrong path**

When a PATH event's parent inode has multiple dentry aliases, `fsnotify_parent_broadcast_listener` forwards the parent inode, and `on_file_op` selects its first dentry alias instead of using the event's path, so callers receive an event for a different pathname.

Pass the event's path through to the handler and build the event pathname from it instead of selecting an inode alias.
</issue_to_address>

### Comment 3
<location path="src/kernelmod/vfs_fsnotify.c" line_range="217" />
<code_context>
+    if (FSNOTIFY_EVENT_PATH == data_is) {
+        path = data;
+        if (!path || !path->dentry)
+            return;
+        fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);
+        return;
</code_context>
<issue_to_address>
**File events duplicate filename**

When a PATH file event has `to_tell` set to the target file inode, `fsnotify_parent_broadcast_listener` treats `to_tell` as the parent inode, so `on_file_op` builds the path from the target's dentry and appends its name again; callers receive an incorrect path.

Handle the PATH event using its target path rather than treating the target inode as a parent and appending the filename.

Also at `src/kernelmod/vfs_fsnotify.c:216`.
</issue_to_address>

### Comment 4
<location path="src/kernelmod/vfs_fsnotify.c" line_range="216" />
<code_context>
+        path = data;
+        if (!path || !path->dentry)
+            return;
+        fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);
+        return;
+    }
</code_context>
<issue_to_address>
**Mount events lose their path**

When a PATH notification carries `FS_MOUNT_DIR` or `FS_UNMOUNT_DIR` and its dentry is below the mount-point root, `fsnotify_parent_broadcast_listener` passes only the dentry name, which the mount and unmount handlers treat as the complete path, so consumers receive only the final component instead of the mount-point path.

Pass the complete mount-point path to the mount and unmount handlers instead of only the dentry name.
</issue_to_address>

### Comment 5
<location path="src/kernelmod/vfs_fsnotify.c" line_range="217" />
<code_context>
+    if (FSNOTIFY_EVENT_PATH == data_is) {
+        path = data;
+        if (!path || !path->dentry)
+            return;
+        fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);
+        return;
</code_context>
<issue_to_address>
**Mounted paths are misreported**

When a PATH notification refers to a bind mount or another mount of the same filesystem, the path is reduced to its dentry and later rendered with `dentry_path_raw`, discarding `path->mnt`; the server then prefixes the device’s mount point, so events from bind mounts or another mount of the same filesystem carry the wrong path and consumers update the wrong location.

Build the reported path using the supplied `struct path`, including its mount, rather than resolving only the dentry.
</issue_to_address>

### Comment 6
<location path="src/kernelmod/vfs_fsnotify.c" line_range="1" />
<code_context>
-// Copyright (C) 2021 UOS Technology Co., Ltd.
-// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd.
+// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
</code_context>
<issue_to_address>
**Required copyright header is missing**

`vfs_fsnotify.c` no longer contains the required UOS copyright header; the remaining SPDX-FileCopyrightText line does not satisfy the repository's stated header format.

Restore a `// Copyright (C) <year> UOS Technology Co., Ltd.` line in the file header.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

path = data;
if (!path || !path->dentry)
return;
fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Path renames lose pairing

When a PATH notification carries FS_MOVED_FROM or FS_MOVED_TO, especially while other zero-cookie events are queued, fsnotify_parent_broadcast_listener passes cookie 0 to fsnotify_event_handler, so event_merge and do_event_merge pair rename events with the wrong events or treat them as unrelated, and callers receive incorrect rename operations.

Forward the callback’s rename cookie through fsnotify_parent_broadcast_listener to fsnotify_event_handler.

Prompt for AI agents
In `src/kernelmod/vfs_fsnotify.c` at line 216:

**Path renames lose pairing**

When a PATH notification carries FS_MOVED_FROM or FS_MOVED_TO, especially while other zero-cookie events are queued, `fsnotify_parent_broadcast_listener` passes cookie `0` to `fsnotify_event_handler`, so `event_merge` and `do_event_merge` pair rename events with the wrong events or treat them as unrelated, and callers receive incorrect rename operations.

Forward the callback’s rename cookie through `fsnotify_parent_broadcast_listener` to `fsnotify_event_handler`.

path = data;
if (!path || !path->dentry)
return;
fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Events use the wrong path

When a PATH event's parent inode has multiple dentry aliases, fsnotify_parent_broadcast_listener forwards the parent inode, and on_file_op selects its first dentry alias instead of using the event's path, so callers receive an event for a different pathname.

Pass the event's path through to the handler and build the event pathname from it instead of selecting an inode alias.

Prompt for AI agents
In `src/kernelmod/vfs_fsnotify.c` at line 216:

**Events use the wrong path**

When a PATH event's parent inode has multiple dentry aliases, `fsnotify_parent_broadcast_listener` forwards the parent inode, and `on_file_op` selects its first dentry alias instead of using the event's path, so callers receive an event for a different pathname.

Pass the event's path through to the handler and build the event pathname from it instead of selecting an inode alias.

if (!path || !path->dentry)
return;
fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · File events duplicate filename

When a PATH file event has to_tell set to the target file inode, fsnotify_parent_broadcast_listener treats to_tell as the parent inode, so on_file_op builds the path from the target's dentry and appends its name again; callers receive an incorrect path.

Handle the PATH event using its target path rather than treating the target inode as a parent and appending the filename.

Also at src/kernelmod/vfs_fsnotify.c:216.

Prompt for AI agents
In `src/kernelmod/vfs_fsnotify.c` at line 217:

**File events duplicate filename**

When a PATH file event has `to_tell` set to the target file inode, `fsnotify_parent_broadcast_listener` treats `to_tell` as the parent inode, so `on_file_op` builds the path from the target's dentry and appends its name again; callers receive an incorrect path.

Handle the PATH event using its target path rather than treating the target inode as a parent and appending the filename.

Also at `src/kernelmod/vfs_fsnotify.c:216`.

path = data;
if (!path || !path->dentry)
return;
fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Mount events lose their path

When a PATH notification carries FS_MOUNT_DIR or FS_UNMOUNT_DIR and its dentry is below the mount-point root, fsnotify_parent_broadcast_listener passes only the dentry name, which the mount and unmount handlers treat as the complete path, so consumers receive only the final component instead of the mount-point path.

Pass the complete mount-point path to the mount and unmount handlers instead of only the dentry name.

Prompt for AI agents
In `src/kernelmod/vfs_fsnotify.c` at line 216:

**Mount events lose their path**

When a PATH notification carries `FS_MOUNT_DIR` or `FS_UNMOUNT_DIR` and its dentry is below the mount-point root, `fsnotify_parent_broadcast_listener` passes only the dentry name, which the mount and unmount handlers treat as the complete path, so consumers receive only the final component instead of the mount-point path.

Pass the complete mount-point path to the mount and unmount handlers instead of only the dentry name.

if (!path || !path->dentry)
return;
fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Mounted paths are misreported

When a PATH notification refers to a bind mount or another mount of the same filesystem, the path is reduced to its dentry and later rendered with dentry_path_raw, discarding path->mnt; the server then prefixes the device’s mount point, so events from bind mounts or another mount of the same filesystem carry the wrong path and consumers update the wrong location.

Build the reported path using the supplied struct path, including its mount, rather than resolving only the dentry.

Prompt for AI agents
In `src/kernelmod/vfs_fsnotify.c` at line 217:

**Mounted paths are misreported**

When a PATH notification refers to a bind mount or another mount of the same filesystem, the path is reduced to its dentry and later rendered with `dentry_path_raw`, discarding `path->mnt`; the server then prefixes the device’s mount point, so events from bind mounts or another mount of the same filesystem carry the wrong path and consumers update the wrong location.

Build the reported path using the supplied `struct path`, including its mount, rather than resolving only the dentry.

Comment thread src/kernelmod/vfs_fsnotify.c Resolved
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wangrong1069

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wangrong1069

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 32a8cc5 into linuxdeepin:develop/snipe Nov 24, 2026
17 of 20 checks passed
@wangrong1069
wangrong1069 deleted the pr1124 branch November 24, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants