From 67472f4a428c093b8dda8bf558140e32c2c951a1 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Fri, 17 Jan 2025 14:52:40 -0700 Subject: [PATCH] syms: Initialize ModulePath::fd_ to invalid FD ~ModulePath() does `if (fd_ > 0) close fd_;`. But ModulePath constructor has early return codepath for `!enter_ns` which does not initialize `fd_`. So `fd_` can potentially have junk value. That junk value could be any FD downstream. bcc cannot be closing random FDs. --- src/cc/syms.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/syms.h b/src/cc/syms.h index 3dffdda73603..94ed7ac8a73d 100644 --- a/src/cc/syms.h +++ b/src/cc/syms.h @@ -130,7 +130,7 @@ class ProcSyms : SymbolCache { // process by storing a file descriptor created from openat(2) if possible // if openat fails, falls back to process-dependent path with /proc/.../root private: - int fd_; + int fd_ = -1; std::string proc_root_path_; std::string path_;