Repository navigation
fix(kernelmod): handle path-type fsnotify events and filter pseudo fds - #298
Conversation
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自身产生的伪文件描述符误触发变更事件,提升事件采集准确性与稳定性。
Reviewer's GuideImplementationHandle path-type fsnotify events by broadcasting from the path, and accept inode or dentry event data while retaining the existing event filters.
Guard the __fput hook against a null file before dereferencing it, and skip write-close events for fanotify-generated and path-only file descriptors.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>| path = data; | ||
| if (!path || !path->dentry) | ||
| return; | ||
| fsnotify_parent_broadcast_listener(path, path->dentry, mask, to_tell); |
There was a problem hiding this comment.
🟠 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); |
There was a problem hiding this comment.
🟡 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; |
There was a problem hiding this comment.
🟡 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); |
There was a problem hiding this comment.
🟡 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; |
There was a problem hiding this comment.
🟡 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.|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
32a8cc5
into
linuxdeepin:develop/snipe
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:
Bug Fixes:
Enhancements: