[Bugfix] Match the mapped filename in find_loaded_library (#47586)

Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Shengqi Chen <harry-chen@outlook.com>

Gabriel Wu committed Jul 7, 2026 at 16:06 UTC ba50b9763f2feafeef9971b42a81088a2d98717d
1 file changed +17 -17
vllm/utils/system_utils.py
+17 -17
@@ -308,26 +308,26 @@ def set_ulimit(target_soft_limit: int = 65535):
308
309 def find_loaded_library(lib_name: str) -> str | None:
310 """
311 - According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
311 + According to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
312 the file `/proc/self/maps` contains the memory maps of the process, which includes the
313 shared libraries loaded by the process. We can use this file to find the path of the
314 loaded library.
315 """ # noqa
316 - found_line = None
316 + # Match the mapped file's name, not the whole line: an unrelated library
317 + # whose name merely contains lib_name (e.g. TileLang's libcudart_stub.so
318 + # when looking for libcudart) or a directory component containing it must
319 + # not win. Legitimate filenames are {lib_name}.so[.*] or a name-mangled
320 + # {lib_name}-<hash>.so[.*], and /proc/self/maps is ordered by mapping
321 + # address rather than load order, so a substring hit is a
322 + # nondeterministic hijack.
323 with open("/proc/self/maps") as f:
324 for line in f:
319 - if lib_name in line:
320 - found_line = line
321 - break
322 - if found_line is None:
323 - # the library is not loaded in the current process
324 - return None
325 - # if lib_name is libcudart, we need to match a line with:
326 - # address /path/to/libcudart-hash.so.11.0
327 - start = found_line.index("/")
328 - path = found_line[start:].strip()
329 - filename = path.split("/")[-1]
330 - assert filename.rpartition(".so")[0].startswith(lib_name), (
331 - f"Unexpected filename: {filename} for library {lib_name}"
332 - )
333 - return path
325 + start = line.find("/")
326 + if start == -1:
327 + continue
328 + path = line[start:].strip()
329 + filename = path.rsplit("/", maxsplit=1)[-1]
330 + if filename.startswith((f"{lib_name}.", f"{lib_name}-")):
331 + return path
332 + # the library is not loaded in the current process
333 + return None