Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 556526 - mpd can't interact with PulseAudio
Summary: mpd can't interact with PulseAudio
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: SELinux (show other bugs)
Hardware: All Linux
: Normal major (vote)
Assignee: Jason Zaman
URL:
Whiteboard: sec-policy r9
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-02 19:09 UTC by Niklas Haas
Modified: 2015-11-22 10:39 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Niklas Haas 2015-08-02 19:09:27 UTC
mpd is unable to play audio via PulseAudio

Reproducible: Always

Steps to Reproduce:
1. Install mpd
2. Enable PulseAudio output in mpd.conf (type "pulse")
3. Start mpd and try to play back audio

Actual Results:  
type=AVC msg=audit(1438542397.578:41803): avc:  denied  { getattr } for  pid=3036 comm="output:PulseAud" path="/tmp/pulse-41hVSyvkKCJe" dev="tmpfs" ino=193762 scontext=system_u:system_r:mpd_t tcontext=staff_u:object_r:user_tmp_t tclass=dir permissive=0
Comment 1 Franz Trischberger 2015-08-03 16:21:01 UTC
Is that a system mpd.conf, or the one of your user?
Do you start mpd as a system service or as user?
If you start it as a user do you have write access to the relevant files/directories? (see your other issue).
And your complete mpd config would help, too.

I start mpd as a user and use pulseaudio without any issues.
Comment 2 Niklas Haas 2015-08-03 16:41:46 UTC
It's a system-wide mpd.conf; I *start* it system-wide via rc-service, but it drops privs to my user account. (I have “user nand” in my system-wide mpd.conf)

Complete mpd config: https://github.com/haasn/gentoo-conf/blob/nanodesu/etc/mpd.conf

It has access to /y/media/music, but not to /tmp/pulse-*, as evidenced by this command:

{{{
$ sesearch -AC -s mpd_t -t user_tmp_t -p getattr -c dir

$
}}}
Comment 3 Niklas Haas 2015-08-08 02:42:42 UTC
After some further testing, I noticed that if I start mpd in permissive mode and successfully start playback at least once, I can then turn off permissive mode and it continues working.

It seems like once it successfully reads the /tmp/pulse-* files once, it keeps that data in memory.

Furthermore, if pulse is *not* already running, I get weirder behavior:

1. I get a failure because mpd tries writing to /var/log/mpd.log from within pulseaudio_t.

2. If I disable logging in order to bypass this, it successfully creates the /tmp/pulse-* directory but as mpd_t, and so it ends up labeled as mpd_tmp_t. PulseAudio itself then fails reading this directory.

The only way I can get it to work, currently:

1. Spawn PulseAudio separately
2. Start mpd in permissive mode and have it play back audio at least once
3. Disable permissive mode
Comment 4 Sven Vermeulen (RETIRED) gentoo-dev 2015-08-16 17:19:57 UTC
Right now the SELinux policy for pulseaudio does not use regular temporary files/directories. I don't use it myself so I don't know if this was never needed (and is recently added) or if there is a setting that is able to deal with this differently.

We should try to figure out which process is creating the /tmp/pulse-.* directory. If it is pulseaudio, then it should be running in the pulseaudio domain (and the file should be pulseaudio_tmp_t). We could then allow the pulseaudio clients to read this information.
Comment 5 Jason Zaman gentoo-dev 2015-08-23 04:14:44 UTC
userdom_list_user_tmp(pulseaudio_client)

added in commit 74d30592c6783e
Comment 6 Jason Zaman gentoo-dev 2015-08-23 04:37:09 UTC
(In reply to Sven Vermeulen from comment #4)
> Right now the SELinux policy for pulseaudio does not use regular temporary
> files/directories. I don't use it myself so I don't know if this was never
> needed (and is recently added) or if there is a setting that is able to deal
> with this differently.
> 
> We should try to figure out which process is creating the /tmp/pulse-.*
> directory. If it is pulseaudio, then it should be running in the pulseaudio
> domain (and the file should be pulseaudio_tmp_t). We could then allow the
> pulseaudio clients to read this information.

I looked through the pulse source. It looks like the lib creates the dir first so its made by whatever process starts pulse. It looks like it is made before forking off the pulse server, so it is not actually created by pulseaudio_t.

The longer term solution is to get XDG_RUNTIME_DIR working so that pulse will put its dir in /run/user/$USER/pulse/ then we can use a named filetrans to label it properly. I filed an issue with consolekit2 to implement $XDG_RUNTIME_DIR

https://github.com/pulseaudio/pulseaudio/blob/1db12f50106735f021202b51bc62e1bfc16260f1/src/pulsecore/core-util.c#L1839
Comment 7 Jason Zaman gentoo-dev 2015-09-06 13:04:48 UTC
r9 is in ~arch
Comment 8 Jason Zaman gentoo-dev 2015-11-22 10:39:57 UTC
r9 stable