Skip to content

Commit 1bd9ace

Browse files
authored
Fix bug with resolving relative symlinks during linux header detection (#2038)
Summary: Fix bug with resolving relative symlinks during linux header detection Please see linked issue for details Relevant Issues: Closes #2037 Type of change: /kind bugfix Test Plan: Verified the following - [x] Confirmed with user that reported the issue that this works for openSUSE's MicroOS linux headers - [x] Verified on Ubuntu that using an absolute symlink works (upstream package, no modification) ``` ddelnano@dev-vm:/lib/modules/6.8.0-1015-gcp$ ls -l build lrwxrwxrwx 1 root root 37 Sep 2 14:42 build -> /usr/src/linux-headers-6.8.0-1015-gcp # Verify custom built stirling_wrapper identifies absolute headers $ sudo docker run -v /:/host -v /sys:/sys -v /var/lib/docker:/var/lib/docker --pid=host --cgroupns host --env "PL_HOST_PATH=/host" bazel/src/stirling/binaries:stirling_wrapper_image I20241011 21:32:38.893605 395713 linux_headers.cc:257] Looking for host Linux headers at /host/lib/modules/6.8.0-1015-gcp/build. I20241011 21:32:38.893646 395713 linux_headers.cc:237] Symlink target is an absolute path. Converting that to host path: /usr/src/linux-headers-6.8.0-1015-gcp -> /host/usr/src/linux-headers-6.8.0-1015-gcp. I20241011 21:32:38.893750 395713 linux_headers.cc:261] Linked host headers at /host/usr/src/linux-headers-6.8.0-1015-gcp to symlink in pem namespace at /lib/modules/6.8.0-1015-gcp/build. I20241011 21:32:38.893783 395713 linux_headers.cc:257] Looking for host Linux headers at /host/lib/modules/6.8.0-1015-gcp/source. ``` - [x] Verified on Ubuntu that using a relative symlink (modified by hand with reproduction steps in #2037) ``` # Verify build is a relative symlink and resolves outside a container ddelnano@dev-vm:/lib/modules/6.8.0-1015-gcp$ ls -l total 1480 lrwxrwxrwx 1 root root 48 Oct 11 20:39 build -> ../../../../usr/src/linux-headers-6.8.0-1015-gcp # Verify custom built stirling_wrapper identifies relative headers $ sudo docker run -v /:/host -v /sys:/sys -v /var/lib/docker:/var/lib/docker --pid=host --cgroupns host --env "PL_HOST_PATH=/host" bazel/src/stirling/binaries:stirling_wrapper_image I20241011 21:30:16.825937 395471 linux_headers.cc:257] Looking for host Linux headers at /host/lib/modules/6.8.0-1015-gcp/build. I20241011 21:30:16.825973 395471 linux_headers.cc:242] Symlink target is a relative path. Concatenating it to parent directory: /host/lib/modules/6.8.0-1015-gcp/../../../../usr/src/linux-headers-6.8.0-1015-gcp I20241011 21:30:16.826067 395471 linux_headers.cc:261] Linked host headers at /host/lib/modules/6.8.0-1015-gcp/../../../../usr/src/linux-headers-6.8.0-1015-gcp to symlink in pem namespace at /lib/modules/6.8.0-1015-gcp/build. ``` Changelog Message: Fixed an issue where certain linux upstream distro's header packages would fail to be identified --------- Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 738111f commit 1bd9ace

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/stirling/utils/linux_headers.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,21 @@ StatusOr<std::filesystem::path> ResolvePossibleSymlinkToHostPath(const std::file
229229
return error::Internal(ec.message());
230230
}
231231

232-
const auto resolved_host_path = system::Config::GetInstance().ToHostPath(resolved);
232+
// Relative paths containing "../" can result in an invalid host mount path when using
233+
// ToHostPath. Therefore, we need to treat the absolute and relative cases differently.
234+
std::filesystem::path resolved_host_path;
235+
if (resolved.is_absolute()) {
236+
resolved_host_path = system::Config::GetInstance().ToHostPath(resolved);
237+
VLOG(1) << absl::Substitute(
238+
"Symlink target is an absolute path. Converting that to host path: $0 -> $1.",
239+
resolved.string(), resolved_host_path.string());
240+
} else {
241+
resolved_host_path = p.parent_path();
242+
resolved_host_path /= resolved.string();
243+
VLOG(1) << absl::Substitute(
244+
"Symlink target is a relative path. Concatenating it to parent directory: $0",
245+
resolved_host_path.string());
246+
}
233247

234248
// Downstream won't be ok unless the resolved host path exists; return an error if needed.
235249
if (!fs::Exists(resolved_host_path)) {

0 commit comments

Comments
 (0)