interProcess - Permission denied when creating named_mutex

Hey!
I’m snapping an application that use interprocess tools from boost (boost::named_mutex, boost::named_condition).
Processes that I want to synchronise are all in this snap.
When I try to create such objet I always catch an exception “Permission denied”.

I try to enable the following interfaces:
plugs: [network, netwok-bind, process-control, system-observe]
but it doesn’t seem to help.
Do you know which plug should I activate? Is there other solution to use interprocess mecanism with a snap?

It woud hep if you could pull the actual denials out of syslog and post them here:

grep DEN /var/log/syslog

after you ran the app…

Sure:

Oct 27 13:27:06 beaulieu-VirtualBox kernel: [ 4034.641054] audit: type=1400 audit(1509103626.195:195): apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.svc” name="/dev/shm/yLYqn6" pid=4789 comm=“IPLCoreServiceL” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
Oct 27 13:27:06 beaulieu-VirtualBox kernel: [ 4034.750952] audit: type=1400 audit(1509103626.303:196): apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.svc” name="/dev/shm/i0ErML" pid=1398 comm=“IPLCoreServiceL” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
Oct 27 13:27:16 beaulieu-VirtualBox kernel: [ 4045.133086] audit: type=1400 audit(1509103636.692:197): apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.svc” name="/dev/shm/ZwIE1a" pid=4816 comm=“IPLCoreServiceL” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
Oct 27 13:27:16 beaulieu-VirtualBox kernel: [ 4045.133089] audit: type=1400 audit(1509103636.692:198): apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.svc” name="/dev/shm/C5Notn" pid=4816 comm=“IPLCoreServiceL” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
Oct 27 13:27:21 beaulieu-VirtualBox kernel: [ 4050.240214] audit: type=1400 audit(1509103641.799:199): apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.svc” name="/dev/shm/ODe0Kw" pid=4834 comm=“DFYRobotManager” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
Oct 27 13:27:21 beaulieu-VirtualBox kernel: [ 4050.252386] audit: type=1400 audit(1509103641.811:200): apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.svc” name="/dev/shm/ngzuOY" pid=4834 comm=“DFYRobotManager” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
Oct 27 13:27:21 beaulieu-VirtualBox kernel: [ 4050.252755] audit: type=1400 audit(1509103641.815:201): apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.svc” name="/dev/shm/Pop3Rq" pid=4834 comm=“DFYRobotManager” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0

Has expected I don’t have the rights on /dev/shm/

Note that you can also use the ‘snappy-debug’ snap (sudo snappy-debug.security scanlog) and it will make suggestions.

The shm denials are covered here: Shared memory in /dev/shm rewriting. Does using the snapcraft preload part resolve this? Otherwise you could update the source to for it to use snap.$SNAP_NAME.XXXXXX (eg, conditional on if SNAP_NAME is set).

Note: I just now updated snappy-debug to suggest snapcraft preload

I’m pretty new at snapping and I have never use snappy-debug.
If I run my program as usual everything is ok, and the other and if I run it with snappy-debug my program freeze, nothing and the shell and I have to kill (Ctrl+C) to quit.

mmo@beaulieu-VirtualBox:~/Documents$ sudo dfy.test
[sudo] password for mmo:
15:36:32.844 WARN:sid 2244
15:36:32.874 ERR:Cannot create event ‘TATTATAT’ [Permission denied, Permission denied]
15:36:32.875 ERR:Cannot create event ‘snap.TATTATAT’ [Permission denied, Permission denied]
15:36:32.875 ERR:Cannot create event ‘snap.test.TATTATAT’ [Permission denied, Permission denied]
mmo@beaulieu-VirtualBox:~/Documents$
mmo@beaulieu-VirtualBox:~/Documents$
mmo@beaulieu-VirtualBox:~/Documents$ sudo snappy-debug.security scanlog dfy.test
INFO: following ‘/var/log/syslog’. If have dropped messages, use:
INFO: $ sudo journalctl --output=short --follow --all | sudo snappy-debug.security scanlog
kernel.printk_ratelimit = 0
^C
kernel.printk_ratelimit = 5

mmo@beaulieu-VirtualBox:~/Documents$

I have try snacraft preload but I see no difference. Actually I don’t even know what it does…

Has suggested I have try to rename using “snap.$SNAP_NAME.XXXXXX” format. When I run it outside of the snap I can see files in /dev/shm/

But when I run it from the snap, names are modified:

I don’t know where this renaming come from …

you do not usually “run an app with” snappy-debug, just run your app normally so that it logs the issues that happen into syslog/journal … after you ran your app you run:

sudo snappy-debug.security scanlog

and snappy-debug will scan the log and make suggestions about the logged issues …

ok, Thanks I get it:

mmo@beaulieu-VirtualBox:~/Documents$ sudo snappy-debug.security scanlog
[sudo] password for mmo:
INFO: following ‘/var/log/syslog’. If have dropped messages, use:
INFO: $ sudo journalctl --output=short --follow --all | sudo snappy-debug.security scanlog
kernel.printk_ratelimit = 0
= AppArmor =
Time: Oct 27 16:14:40
Log: apparmor=“DENIED” operation=“capable” profile=“snap.dfy.test” pid=3592 comm=“IPLCoreLinuxTes” capability=35 capname=“wake_alarm”
Capability: wake_alarm
Suggestions:

  • adjust program to not require ‘CAP_WAKE_ALARM’ (see ‘man 7 capabilities’)
  • do nothing if program otherwise works properly

= AppArmor =
Time: Oct 27 16:14:40
Log: apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.test” name="/dev/shm/bTBtxy" pid=3592 comm=“IPLCoreLinuxTes” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
File: /dev/shm/bTBtxy (write)
Suggestion:

  • adjust program to create files and directories in /dev/shm/snap.$SNAP_NAME.*

= AppArmor =
Time: Oct 27 16:14:40
Log: apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.test” name="/dev/shm/YsjHmS" pid=3592 comm=“IPLCoreLinuxTes” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
File: /dev/shm/YsjHmS (write)
Suggestion:

  • adjust program to create files and directories in /dev/shm/snap.$SNAP_NAME.*

= AppArmor =
Time: Oct 27 16:14:40
Log: apparmor=“DENIED” operation=“mknod” profile=“snap.dfy.test” name="/dev/shm/TLF3bc" pid=3592 comm=“IPLCoreLinuxTes” requested_mask=“c” denied_mask=“c” fsuid=0 ouid=0
File: /dev/shm/TLF3bc (write)
Suggestion:

  • adjust program to create files and directories in /dev/shm/snap.$SNAP_NAME.*

Still don’t know how is renaming those …

Ok, after some reshearch I found that the renaming come from the implementation of open_sem() in glibc.
Thanks:


When creating a file on /dev/shm glibc start by creating a random file and if everything is ok link the random file to the requested one.
My problem is that I don’t I the right to create the random file.

My question is: am I allowed to create a file called “snap.blabla” in /dev/shm/ ? If yes who is giving me this right? And why i creating a file named “blabla” is forbidden ?

you got that worng …

/dev/shm/snap.$SNAP_NAME.* is supposed to be a subdirectory, not a file (@jdstrand i think the snappy-debug text should be clearer there)

in general snapd disallows accessing /dev/shm/, snaps could spy on each other through that.
so snapd makes sure each snap gets a subdir on its own where it can drop in its named semaphores instead …

and for this you need the preloading, it will intercept the function and use the subdir instead of directly trying to write to /dev/shm … the alternative would be to patch your app everywhere it uses that function and hardcode that dir … but thats not really feasable …

@ogra, no, it can be either file or directory:

/{dev,run}/shm/snap.@{SNAP_NAME}.** mrwlkix,

@thooxx - yes, you are allowed to create /dev/shm/snap.blabla.ANYTHING, where ‘blabla’ is your snap name (note that the ‘.’ after ‘blabla’ is important).

2 Likes

Adding a prefix “snap.$SNAP_NAME.” for all named mutex in my app is not a problem but it’s not the solution.
I’m stuck with glibc that create a temporary file with a random name in the /dev/shm directory and this action is not catched by the preload scnapcraft.

i don’t know preload snapcraft woks, one solution could consiste on overiding the function that provide the shm directory but i don’t know if it can be done.

const char *
__shm_directory (size_t *len)

Unfortunatly, I think snapd is not mature enought for me …

I was looking into this problem and it’s not an easy fix unfortunately. I’ll talk to the snapd team and see if we can make something that we could deploy for everyone in general.

1 Like