7

I wrote a script that generates a PDF and an HTML file on RAM-disk:

  • The PDF file can be opened as expected.
  • The HTML file can be opened with an editor, but not with a browser.

This is the error message I get from the browser (Chrome, Firefox) on Ubuntu Linux 24.04:

Access to the file was denied
The file at file:///dev/shm/test.html is not readable. It may have been removed, moved or file permissions may be preventing access.
ERR_ACCESS_DENIED

These are the file details:

/dev/shm> ll
-rw-rw-r-- 1  11K 2024-08-30 11:06 test.html

If I copy the file to the hard disk, it can be opened as expected:

/dev/shm> cp ./test.html ~

If I build Chromium from source as explained here, will I be able to open files stored on RAM-disk like /dev/shm?

9
  • Can the browser open any html file on /dev/shm? And what OS are you using? Commented Aug 30, 2024 at 10:55
  • 2
    Have you modified the output of ls -l? It usually includes the owner and group. Commented Aug 30, 2024 at 12:04
  • @Kusalananda - Yes, I have. Most of the times I do not need the user and group. Commented Aug 30, 2024 at 13:44
  • 3
    Is the browser a snap? Commented Aug 30, 2024 at 14:15
  • 4
    Then it's probably a snap. Commented Aug 30, 2024 at 14:25

1 Answer 1

17

It's not that /dev/shm is of filesystem type tmpfs, but directly related to the snap installation. Evidence:

echo '<h1>Header</h1><p>Paragraph of text</p>' >/tmp/file.html
cp /tmp/file.html /dev/shm

firefox file:///tmp/file.html        # Firefox renders the file as expected

firefox file:///dev/shm/file.html    # Firefox fails to render, with permission denied
firefox file:///dev/shm              # Firefox renders the directory as expected

sudo umount /dev/shm                 # Remove the tmpfs filesystem
cp /tmp/file.html /dev/shm

firefox file:///dev/shm/file.html    # Firefox STILL fails to render, with permission denied

Furthermore

sudo mkdir /mnt/shm
sudo mount -t tmpfs /mnt/shm         # Mount a tmpfs filesystem elsewhere
cp /tmp/file.html /mnt/shm

firefox file:///mnt/shm/file.html    # Firefox renders as expected

Ubuntu 22.04 uses a "snap" version of Firefox as part of its standard installation, and such applications are sandboxed and prevented from accessing files in much of the filesystem (including those in /dev/shm but not the directory itself). Furthermore, the set of accessible directories is not configurable.


Relevant references

6
  • 5
    Yup. askubuntu.com/questions/1227963/… tells how to disable sandboxing for an app. Strictly speaking this makes a lot of sense; the browser should not need to poke things in /dev normally. Commented Aug 30, 2024 at 14:26
  • @vidarlo thanks. I don't run Ubuntu (or snap) usually so this was an interesting exercise Commented Aug 30, 2024 at 14:30
  • I use the /dev/shm RAM-disk when I have to generate many temporary files, to avoid SSD wearing. I will see how to disable sandboxing for Chrome. Hopefully this will have no side effects... Commented Aug 30, 2024 at 14:43
  • What I would like to do is to add /dev/shm to the list of directories accessible by all snap based applications. Is there a way to do it? Commented Aug 30, 2024 at 15:23
  • 10
    @vidarlo "the browser should not need to poke things in /dev normally" /dev/shm is a backing store for shared memory that any process may use. Certainly, chromium on my system uses it, as well as /dev/urandom and /dev/null. So I disagree with your statement there. Commented Aug 31, 2024 at 8:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.