Opened 2 months ago
Last modified 2 months ago
#22165 new defect
Bad address error copying files to shared folder with latest Rocky Linux 9.4 kernel
Reported by: | Guillermo Jano | Owned by: | |
---|---|---|---|
Component: | guest additions | Version: | VirtualBox-7.1.0 |
Keywords: | Cc: | ||
Guest type: | Linux | Host type: | Windows |
Description
I have a sources directory mounted into a VM running Rocky Linux 9.4 on a Windows 10 host:
!sources on /sources type vboxsf (rw,nodev,relatime,iocharset=utf8,uid=0,gid=0)
While building a Maven project within the folder, I encountered an issue when Maven tries copying some file from a local path (located in the VM disk) to a subdirectory located in the shared folder (within the project directory). First, I tried to reproduce the issue using cp, just copying the same file into the same location, but that worked just fine. So next I investigated a little into how Maven is trying to copy this file, and found it is using
Files.copy
, so I wrote a simple Java cp-clone and was able to reproduce the issue as well. Next, using strace
I investigated a little and figured out what Java was doing under the hood, then I came up with this C-based implementation, which should make reproducing easier:
#include <stdio.h> #include <fcntl.h> #include <sys/sendfile.h> #include <sys/stat.h> #include <unistd.h> int main(int argc, char* argv[]) { if (argc != 3) { printf("Usage: %s <source_file> <destination_file>\n", argv[0]); return 1; } const char* source_file = argv[1]; const char* destination_file = argv[2]; int source_fd = open(source_file, O_RDONLY); if (source_fd == -1) { perror("Failed to open source file"); return 1; } int destination_fd = open(destination_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (destination_fd == -1) { perror("Failed to open destination file"); close(source_fd); return 1; } struct stat stat_buf; if (fstat(source_fd, &stat_buf) == -1) { perror("Failed to get source file size"); close(source_fd); close(destination_fd); return 1; } off_t offset = 0; ssize_t bytes_sent = sendfile(destination_fd, source_fd, &offset, stat_buf.st_size); if (bytes_sent == -1) { perror("Failed to copy file"); close(source_fd); close(destination_fd); return 1; } printf("File copied successfully.\n"); close(source_fd); close(destination_fd); return 0; }
I guess the most relevant detail here is Java is using sendfile
:
... [pid 6023] openat(AT_FDCWD, "/bin/ls", O_RDONLY) = 5 [pid 6023] openat(AT_FDCWD, "/sources/temp", O_WRONLY|O_CREAT|O_EXCL, 0100755) = 6 [pid 6023] sendfile(6, 5, NULL, 2147479552) = -1 EFAULT (Bad address) ...
Now, regarding the issue I am observing:
- It occurs when copying files to the mounted shared folder (
vboxsf
filesystem) - Looks like it only happens for files over a certain size. I tried copying all binaries in
/bin
one by one to the same destination path and some worked while some did not. - I found the problem running kernel
5.14.0-427.33.1.el9_4.x86_64
. I tried going back to5.14.0-284.11.1.el9_2.x86_64
which I also had installed and that fixes the issue. - I have reproduced this with both 7.0.20 and 7.1.0. Tried multiple Guest Additions versions apart from 7.0.20 and 7.1.0 but found no differences.
So, it looks to me like there is some regression with Guest Additions and guests running recent Rocky Linux 9 (likely RHEL and clones as well) kernels.
The issue persists with kernel version
5.14.0-427.35.1.el9_4.x86_64
.