VirtualBox

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#18737 closed defect (fixed)

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

Description

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 (1)

poc_18737.py (1.8 KB ) - added by justinsteven 5 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by jamesba, 5 years ago

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

comment:2 by justinsteven, 5 years ago

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 by justinsteven, 5 years ago

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

by justinsteven, 5 years ago

Attachment: poc_18737.py added

comment:4 by justinsteven, 5 years ago

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
>>> os.open("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 poc_18737.py from which I got the above results.

comment:5 by justinsteven, 5 years ago

This still happens with VBoxGuestAdditions_6.0.12-132672.iso

comment:6 by paulson, 5 years ago

Owner: set to paulson
Status: newaccepted
Summary: Open system call to create and open read only file fails on shared folderLinux guests: open(filename, O_CREAT|..., mode) fails inside shared folder

comment:7 by paulson, 5 years ago

Resolution: fixed
Status: acceptedclosed
Summary: Linux guests: open(filename, O_CREAT|..., mode) fails inside shared folderLinux 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.

in reply to:  7 comment:8 by Socratis, 5 years ago

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 by justinsteven, 5 years ago

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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette