[linux] fix: memory-mapped file, stat: No such file or directory#329
Merged
jiegec merged 2 commits intolsof-org:masterfrom Jan 9, 2025
Merged
Conversation
In old linux kernel (e.g. linux-2.6) which does not have this feature: Commit
6b4e306aa3dc ("ns: proc files for namespace naming policy."), means this path
"/proc/self/ns" is not existed. Since lsof-4.96.0 with Commit dbad150 ("
[linux] obtain correct information of memory-mapped file."), compare_mntns()
would misunderstand it is in a different mount namespace if "/proc/self/ns" is
not existed, returns -1, go through map_files lookup, and finally lead to lsof
gets failed with error message "stat: No such file or directory".
If "/proc/self/ns" or its underlying path is not existed, compare_mntns()
returns 0 instead of -1, in order to go through stat_directly as old days.
Signed-off-by: Jones Syue <jones_syue@askey.com>
Member
|
Nice observation! Regarding the code change, maybe we could add some comments on the logic behind comparison: when it is regarded as different, and how it works in different kernel versions. |
Add comments: Compare the inode number of mount namespace, to see if target process is in a different mount namespace from lsof process: return 0 (false) means mount namespace is the same, and return 1 (true) means mount namespace is different. Note that legacy linux kernel (e.g. linux-2.6) might not have this mount namespace path, so makes this case return 0 (false) and acts as old days. Signed-off-by: Jones Syue <jones_syue@askey.com>
Contributor
Author
|
Hello @jiegec Thank you for kind feedback! Add comments and hope im doing this in the correct way :) |
Contributor
Author
|
Thank you @jiegec and your time :) |
mstorchak
added a commit
to mstorchak/packages
that referenced
this pull request
Jul 4, 2025
- [linux] fix legacy linux kernel compatibility due to missing /proc/self/ns (lsof-org/lsof#329) - [linux] fix potential null pointer deference, reported by @mono-trip (lsof-org/lsof#332) Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
mstorchak
added a commit
to mstorchak/packages
that referenced
this pull request
Jul 4, 2025
- [linux] fix legacy linux kernel compatibility due to missing /proc/self/ns (lsof-org/lsof#329) - [linux] fix potential null pointer deference, reported by @mono-trip (lsof-org/lsof#332) Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
pprindeville
pushed a commit
to openwrt/packages
that referenced
this pull request
Jul 13, 2025
- [linux] fix legacy linux kernel compatibility due to missing /proc/self/ns (lsof-org/lsof#329) - [linux] fix potential null pointer deference, reported by @mono-trip (lsof-org/lsof#332) Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
HiGarfield
pushed a commit
to HiGarfield/lede-17.01.4-Mod
that referenced
this pull request
Jul 14, 2025
- [linux] fix legacy linux kernel compatibility due to missing /proc/self/ns (lsof-org/lsof#329) - [linux] fix potential null pointer deference, reported by @mono-trip (lsof-org/lsof#332) Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the bug
Since lsof-4.96.0, run lsof with old linux kernel (e.g. linux-2.6),
lsof would print error message "stat: No such file or directory"
when visiting memory-mapped files; but /bin/stat could visit it without issue.
lsof-4.95.0 and earlier does not have this issue.
In old linux kernel (e.g. linux-2.6) which does not have this feature: Commit
6b4e306aa3dc ("ns: proc files for namespace naming policy."), means this path
"/proc/self/ns" is not existed. Since lsof-4.96.0 with Commit dbad150 ("
[linux] obtain correct information of memory-mapped file."), compare_mntns()
would misunderstand it is in a different mount namespace if "/proc/self/ns" is
not existed, returns -1, go through map_files lookup, and finally lead to lsof
gets failed with error message "stat: No such file or directory".
If "/proc/self/ns" or its underlying path is not existed, compare_mntns()
returns 0 instead of -1, in order to go through stat_directly as old days.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Should not print 'stat: No such file or directory'.
Program output
Environment (please complete the following information):