Ticket #18737 (closed defect: fixed)

Opened 3 months ago

Last modified 2 weeks ago

Linux guests: open(filename, O_CREAT|..., mode) fails inside shared folder => fixed in SVN/6.0.x x>10

Reported by: jamesba Owned by: paulson
Component: shared folders Version: VirtualBox 6.0.8
Keywords: file create shared permissions Cc:
Guest type: Linux Host type: Linux


The following C code produces a simple executable which will attempt to create and open a read only test file in a single operation.

Expected behaviour when run:

  • A newly created file called test.txt is created on disk with read only permissions
  • A read-write file-handle for the file is returned by the open call
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>

int main() {
  int fd = open("test.txt", O_CREAT | O_EXCL | O_RDWR, 0444);

  if (fd < 0) {
    perror("Could not create file: ");
    return -fd;

  return 0;

When run on other file systems this works correctly but when run on a virtualbox shared folder the file is created correctly but the program exits with the error message:

Could not create file: : Permission denied

This can be bypassed by running the command with sudo, in which case it succeeds normally.

This is not a purely hypothetical problem, since the same error occurs when attempting to use any programme that makes this system call, such as a git clone.

Attachments Download (1.8 KB) - added by justinsteven 2 months ago.

Change History

comment:1 Changed 3 months ago by jamesba

Can confirm that this problem is not present on v6.0.4.

comment:2 Changed 2 months ago by justinsteven

Can confirm this was an issue for me on 6.0.8 and is still an issue on 6.0.10.

  • Host: Debian Linux
  • Guest: Debian Linux (running Guest Additions 6.0.10)
  • Host filesystem: ext4 (mounted rw,relatime,data=ordered)
  • Guest: vboxsf volume mounted rw,nodev,relatime,iocharset=utf8,uid=<my_uid>,gid=<my_gid>

OP's reproducer reproduces the issue for me.

I'm also having issues with git repos on a vboxsf volume.

comment:3 Changed 2 months ago by justinsteven

See also some of the comments in #18569 (they directly relate to the git failure)

Changed 2 months ago by justinsteven

comment:4 Changed 2 months ago by justinsteven

I've written a reproducer in Python and tried all file modes from 0o000 to 0o777 using flags O_CREAT | O_EXCL | O_RDWR.

If I map /home/justin/shared to my VirtualBox guest (mounted as /home/justin/shared within the guest) and place the reproducer in shared/test_file_creation, then the poc runs fine from my host but exhibits failures when run from the guest.

In summary, the following file modes are OK in the guest but everything else fails:

0o0             ---------        PASS
0o2             -------w-        PASS
0o20            ----w----        PASS
0o22            ----w--w-        PASS
0o6**           rw-******        PASS
0o7**           rwx******        PASS

(Where "*" is of course anything)

Curiously, mode 0o222 fails:

% python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>>"testfile", os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o222)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: 'testfile'

I've attached from which I got the above results.

comment:5 Changed 5 weeks ago by justinsteven

This still happens with VBoxGuestAdditions_6.0.12-132672.iso

comment:6 Changed 4 weeks ago by paulson

  • Owner set to paulson
  • Status changed from new to accepted
  • Summary changed from Open system call to create and open read only file fails on shared folder to Linux guests: open(filename, O_CREAT|..., mode) fails inside shared folder

comment:7 follow-up: ↓ 8 Changed 3 weeks ago by paulson

  • Status changed from accepted to closed
  • Resolution set to fixed
  • Summary changed from Linux guests: open(filename, O_CREAT|..., mode) fails inside shared folder to Linux guests: open(filename, O_CREAT|..., mode) fails inside shared folder => fixed in SVN/6.0.x x>10

This is a regression which was introduced in VirtualBox 6.0.6 and affects Linux guests which have a kernel > 3.16.0 and utilize the atomic_open() filesystem interface. The file creation succeeds but the follow-up call to the Linux kernel routine finish_open() happened without FMODE_CREATED set in the file->f_mode structure element which then erroneously returns EACCES for unprivileged users.

This has been fixed in trunk and the fix has also been backported to VirtualBox 6.0.x (x > 10) and any 6.0.x Testbuilds with a revision >= r132861. This issue doesn't apply to VirtualBox 5.2.x.

comment:8 in reply to: ↑ 7 Changed 3 weeks ago by socratis

Replying to paulson:

This is a regression which was introduced in VirtualBox 6.0.6 ... This has been fixed ... with a revision >= r132861.

I added the ticket and the fixed revision in the  Discuss the 6.0.6 release thread in the forums, thanks @paulson.

comment:9 Changed 2 weeks ago by justinsteven

The issue is fixed for me using VBoxGuestAdditions_6.0.11-132973.iso on VirtualBox 6.0.10 (Both the Python reproducer, as well as "git clone")

Thanks @paulson

Note: See TracTickets for help on using tickets.
ContactPrivacy policyTerms of Use