Skip to content

Systemd/Snapd: /dev/shm symlink breaks some snaps with "Private Shared Memory" enabled. #8996

Closed

Description

Version

0.68.4.0

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

Linux version 5.15.68.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Mon Sep 19 19:14:52 UTC 2022

Distro Version

Ubuntu 20.04

Other Software

james@James-Desktop:~$ snap version
snap 2.55.5+20.04
snapd 2.55.5+20.04
series 16
ubuntu 20.04
kernel 5.15.68.1-microsoft-standard-WSL2

Repro Steps

-- Install any snap with "Private Shared Memory" enabled. (Context: https://snapcraft.io/blog/private-shared-memory-support-for-snaps)

E.G: sudo snap install joplin-desktop

N.B: it is essential that snapd is version 2.55.5+, older versions of snapd do not understand this interface and will silently ignore it, and otherwise appear to install correctly.

Expected Behavior

Snap installs succesfully.

Actual Behavior

Snap fails to install due

- Setup snap "joplin-desktop" (28) security profiles for auto-connections (cannot obtain mount security snippets for snap "joplin-desktop": shared-memory plug with "private: true" cannot be connected if "/dev/shm" is a symlink)

Workaround:

james@James-Desktop:~$ sudo snap install joplin-desktop
[sudo] password for james:
error: cannot perform the following tasks:
- Setup snap "joplin-desktop" (28) security profiles for auto-connections (cannot obtain mount security snippets for snap "joplin-desktop": shared-memory plug with "private: true" cannot be connected if "/dev/shm" is a symlink)
james@James-Desktop:~$ sudo rm /dev/shm
james@James-Desktop:~$ sudo snap install joplin-desktop
joplin-desktop v2.8.8 from James Carroll installed
james@James-Desktop:~$ exit
logout
PS C:\Users\eloqu> wsl --shutdown
PS C:\Users\eloqu> ubuntu
james@James-Desktop:~$ joplin-desktop
>> opens, but with inproperly configured /dev/shm, as /dev/shm is re-created as a symlink on every boot.

Diagnostic Logs

No response

Activity

  1. cerebrate commented on Oct 13, 2022

    @cerebrate

    I note that systemd should be mounting the tmpfs at /dev/shm automatically, per

    https://github.com/systemd/systemd/blob/13a5ffa4777545ca18971bf23c6dfd12f005eef2/src/shared/mount-setup.c#L79

    (As I understand the history of the issue, this is a change from the pre-systemd practice which did require the symlink, and so if WSL is to also support those distributions - and indeed systemd-using distributions which aren't configured to run systemd - that'll need to be there. Perhaps creating it only if systemd != true in /etc/wsl.conf would be viable?)

  2. ghost
    self-assigned this
    on Oct 18, 2022
  3. cerebrate commented on Oct 29, 2022

    @cerebrate

    Apparently this is also the real underlying cause of the longstanding systemd-sysusers.service issue (reported here at #9012 for native systemd support, but a long-running issue for systemd hacks such as genie, per https://github.com/arkane-systems/genie/wiki/Systemd-units-known-to-be-problematic-under-WSL#systemd-sysusersservice ), and indeed will cause any systemd unit making use of the LoadCredential=, etc., options to fail.

    (Debian sid just added systemd-sysctl.service, systemd-tmpfiles-setup-dev.service, and systemd-tmpfiles-setup.service to the list of units which make use of this, for example.)

    These options require the shared memory tmpfs to be mounted at /dev/shm where systemd would, on native linux, put it automatically and fail if they find a symlink there instead.

    I am currently working around this by creating and enabling the following systemd service (as fixshm.service) to swap the mount and symlink into their proper-under-systemd places:

    [Unit]
    Description=Fix the /dev/shm symlink to be a mount
    DefaultDependencies=no
    Before=sysinit.target
    ConditionPathExists=/dev/shm
    ConditionPathIsSymbolicLink=/dev/shm
    ConditionPathIsMountPoint=/run/shm
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/rm /dev/shm
    ExecStart=/usr/bin/mkdir /dev/shm
    ExecStart=/bin/umount /run/shm
    ExecStart=/usr/bin/rmdir /run/shm
    ExecStart=/bin/mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs /dev/shm
    ExecStart=/usr/bin/ln -s /dev/shm /run/shm
    
    [Install]
    WantedBy=sysinit.target
    

    (Which workaround does also resolve the private-memory snap install issue.)

  4. NotTheDr01ds commented on Nov 24, 2022

    @NotTheDr01ds

    I am currently working around this by creating and enabling the following systemd service (as fixshm.service) to swap the mount and symlink into their proper-under-systemd places:

    That's working for me, but what about a simplified version (2-steps vs. 6) using a bind-mount:

    [Unit]
    Description=Fix the /dev/shm symlink to be a mount
    DefaultDependencies=no
    Before=sysinit.target
    ConditionPathExists=/dev/shm
    ConditionPathIsSymbolicLink=/dev/shm
    ConditionPathIsMountPoint=/run/shm
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/rm /dev/shm
    ExecStart=/bin/mount --bind -o X-mount.mkdir /run/shm /dev/shm
    
    [Install]
    WantedBy=sysinit.target
    
  5. cerebrate commented on Nov 26, 2022

    @cerebrate

    No reason that wouldn't work; I only used the symlink version in the first place because that's what I was familiar with from previous experience. I've updated the server in bottle-imp 1.0 to use the bind mount, and it seems to be working fine.

  6. NotTheDr01ds commented on Nov 28, 2022

    @NotTheDr01ds

    Ben Hillis (@benhillis) (and Alistair Young (@cerebrate)) In that case, this (and other related issues) seems resolvable by init just creating /dev/shm as a bind-mount rather than a symlink, right?

  7. cerebrate commented on Nov 28, 2022

    @cerebrate

    I would expect so, but I am not familiar enough with Linux deep internals to know if there're any subtle differences between a bind mount of a mount point and the original mount point that something might care about.

    (I think it's very unlikely that there is, but it's easy enough to emulate the exact systemd behavior that, well, why not?)

  8. cerebrate commented on Nov 28, 2022

    @cerebrate

    Side note: actually, in the current version of the service I make it less error-prone by moving the /run/shm mount rather than replacing it. as per here:

    https://github.com/arkane-systems/bottle-imp/blob/master/binsrc/imp-executor/__main__.py#L28-L33

  9. gfreitash commented on Jan 19, 2023

    @gfreitash
    [Unit]
    Description=Fix the /dev/shm symlink to be a mount
    DefaultDependencies=no
    Before=sysinit.target
    ConditionPathExists=/dev/shm
    ConditionPathIsSymbolicLink=/dev/shm
    ConditionPathIsMountPoint=/run/shm
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/rm /dev/shm
    ExecStart=/bin/mount --bind -o X-mount.mkdir /run/shm /dev/shm
    
    [Install]
    WantedBy=sysinit.target
    

    That was very useful in solving a similar issue I was having in ManjaroWSL2 where systemd-tmpfiles-setup.service, systemd-tmpfiles-setup-dev.service and systemd-sysctl.service where failing causing apache and mariadb services to also fail.

    I found the link to this issue here, that is also another similar issue. Additionally, in that issue a user give the following suggestion:

    Before = "sysinit.targets"; should be changed to Before = [ "sysinit.target" "systemd-tmpfiles-setup-dev.service" "systemd-tmpfiles-setup.service" "systemd-sysctl.service" ], otherwise this service might run after those services in before, which causes them fail to start.

    Might be useful for others in the future.

  10. JGCarroll commented on Jan 21, 2023

    @JGCarroll
    Author

    This is apparently fixed in the latest pre-release.
    https://github.com/microsoft/WSL/releases/tag/1.1.0

    Marking this issue as closed as a result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions