[linux] fix: memory-mapped file, stat: No such file or directory by jones2024gh · Pull Request #329 · lsof-org/lsof

@jones2024gh

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>

@jones2024gh

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>

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>