diff --git a/devices/src/virtio/fs/passthrough.rs b/devices/src/virtio/fs/passthrough.rs index f065ce4e84..b9ebfafbca 100644 --- a/devices/src/virtio/fs/passthrough.rs +++ b/devices/src/virtio/fs/passthrough.rs @@ -1640,17 +1640,17 @@ impl FileSystem for PassthroughFs { .map(Arc::clone) .ok_or_else(ebadf)?; - // Safe because this is a constant value and a valid C string. - let empty = unsafe { CStr::from_bytes_with_nul_unchecked(EMPTY_CSTR) }; + let path = CString::new(format!("self/fd/{}", data.file.as_raw_fd())) + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; // Safe because this doesn't modify any memory and we check the return value. let res = unsafe { libc::linkat( - data.file.as_raw_fd(), - empty.as_ptr(), + self.proc.as_raw_fd(), + path.as_ptr(), new_inode.file.as_raw_fd(), newname.as_ptr(), - libc::AT_EMPTY_PATH, + libc::AT_SYMLINK_FOLLOW, ) }; if res == 0 {