Skip to content

Create files as mount points with read-only permissions - #405

Merged
cgwalters merged 1 commit into
containers:masterfrom
smcv:create-mountpoint-ro
Apr 16, 2021
Merged

cgwalters merged 1 commit into
containers:masterfrom
smcv:create-mountpoint-ro

Conversation

@smcv

@smcv smcv commented Feb 16, 2021 •

Copy link
Copy Markdown
Collaborator

If two mount namespaces can both see a directory, and we bind-mount a
non-directory into that directory, we have to create a non-directory
to mount it onto:

$ ls -l ~/tmp/mountpoint
ls: cannot access '/home/smcv/tmp/mountpoint': No such file or directory
$ bwrap --bind / / --bind /etc/os-release ~/tmp/mountpoint true
$ ls -l ~/tmp/mountpoint
-rw-rw-rw- 1 smcv smcv 0 Feb 16 10:27 /home/smcv/tmp/mountpoint

The mount point is currently created as an empty world-writable file,
but this doesn't seem like a least-astonishment thing to do.
Create it with read-only permissions instead, to make it clearer that
it's just a placeholder and prevent other users from filling it.

Resolves: #337

@smcv
smcv force-pushed the create-mountpoint-ro branch 2 times, most recently from 293b18a to f036772 Compare February 16, 2021 12:04
@smcv

smcv commented Feb 16, 2021 •

Copy link
Copy Markdown
Collaborator Author

I'd also be happy with consistently using 0644, 0600 or 0400 if maintainers would prefer those.

In the equivalent code paths for directories, we use 0755 whenever we create directories to mount onto.

If two mount namespaces can both see a directory, and we bind-mount a
non-directory into that directory, we have to create a non-directory
to mount it onto:

    $ ls -l ~/tmp/mountpoint
    ls: cannot access '/home/smcv/tmp/mountpoint': No such file or directory
    $ bwrap --bind / / --bind /etc/os-release ~/tmp/mountpoint true
    $ ls -l ~/tmp/mountpoint
    -rw-rw-rw- 1 smcv smcv 0 Feb 16 10:27 /home/smcv/tmp/mountpoint

The mount point is currently created as an empty world-writable file,
but this doesn't seem like a least-astonishment thing to do.
Create it with read-only permissions instead, to make it clearer that
it's just a placeholder and prevent other users from filling it.

Resolves: containers#337
Signed-off-by: Simon McVittie <[email protected]>
@smcv
smcv force-pushed the create-mountpoint-ro branch from f036772 to 411135b Compare April 7, 2021 11:51

@cgwalters cgwalters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, good catch. World writable is always a terrible idea, almost always a mistake since modern UNIX has ACLs.

(One motivation for SELinux was actually that people can accidentally or deliberately make files world writable/readable, i.e. discretionary access control whereas with a MAC one can actively stop that)

@cgwalters
cgwalters merged commit cfa3951 into containers:master Apr 16, 2021
@smcv

smcv commented Apr 16, 2021

Copy link
Copy Markdown
Collaborator Author

@cgwalters If you like this, you'll love #406!

@smcv
smcv deleted the create-mountpoint-ro branch May 14, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--ro-bind-data creates world-writable files

2 participants