Troubleshooting an AppArmor profile – Ubuntu 16.04

As you've just seen, I used aa-enforce to put the two Samba-related profiles into enforce mode. But watch what happens now when I try to restart Samba in order to get the profiles to take effect:

donnie@ubuntu3:/etc/apparmor.d$ sudo systemctl restart smbd
Job for smbd.service failed because the control process exited with error code. See "systemctl status smbd.service" and "journalctl -xe" for details.
donnie@ubuntu3:/etc/apparmor.d$

Okay, that's not good. Looking at the status for the smbd service, I see the following:

donnie@ubuntu3:/etc/apparmor.d$ sudo systemctl status smbd
● smbd.service - LSB: start Samba SMB/CIFS daemon (smbd)
Loaded: loaded (/etc/init.d/smbd; bad; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2017-12-05 14:56:35 EST; 13s ago
Docs: man:systemd-sysv-generator(8)
Process: 31160 ExecStop=/etc/init.d/smbd stop (code=exited, status=0/SUCCESS)
Process: 31171 ExecStart=/etc/init.d/smbd start (code=exited, status=1/FAILURE)
Dec 05 14:56:35 ubuntu3 systemd[1]: Starting LSB: start Samba SMB/CIFS daemon (smbd)...
Dec 05 14:56:35 ubuntu3 smbd[31171]: * Starting SMB/CIFS daemon smbd
Dec 05 14:56:35 ubuntu3 smbd[31171]: ...fail!
. . .

The important things to note here are all the places where some form of the word fail shows up.

The original error message said to use journalctl -xe to view the log message. But journalctl has this bad habit of truncating lines of output at the right edge of the screen. So instead, I'll just use either less or tail to look in the regular /var/log/syslog log file:

Dec  5 20:09:10 ubuntu3 smbd[14599]:  * Starting SMB/CIFS daemon smbd
Dec 5 20:09:10 ubuntu3 kernel: [174226.392671] audit: type=1400 audit(1512522550.765:510): apparmor="DENIED" operation="mknod" profile="/usr/sbin/smbd" name="/run/samba/msg.
lock/14612" pid=14612 comm="smbd" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Dec 5 20:09:10 ubuntu3 smbd[14599]: ...fail!
Dec 5 20:09:10 ubuntu3 systemd[1]: smbd.service: Control process exited, code=exited status=1
Dec 5 20:09:10 ubuntu3 systemd[1]: Failed to start LSB: start Samba SMB/CIFS daemon (smbd).
Dec 5 20:09:10 ubuntu3 systemd[1]: smbd.service: Unit entered failed state.
Dec 5 20:09:10 ubuntu3 systemd[1]: smbd.service: Failed with result 'exit-code'.

So, we see apparmor=DENIED. Obviously, Samba is trying to do something that the profile doesn't allow. Samba needs to write temporary files to the /run/samba/msg.lock directory, but it isn't allowed to. I'm guessing that the profile lacks a rule that allows that to happen.

But even if this log file entry gave me no clue at all, I could just cheat, using a troubleshooting technique that has served me well for many years. That is, I could just copy and paste the error message from the log file into my favorite search engine. Pretty much every time I've ever done that, I've found that other people before me have already had the same problem:

Okay, I didn't paste in the entire error message, but I did paste in enough for DuckDuckGo to work with. And lo and behold, it worked:

Hmmm, it looks like my profile file might be missing an important line. So, I'll open the usr.sbin.smbd file and place this line at the end of the rule set:

/run/samba/** rw,

This line will allow read and write access to everything in the /run/samba directory. After making the edit, I'll need to reload this profile because it's already been loaded with aa-enforce. For this, I'll use the apparmor_parser utility:

donnie@ubuntu3:/etc/apparmor.d$ sudo apparmor_parser -r usr.sbin.smbd
donnie@ubuntu3:/etc/apparmor.d$

All you need to do is use the -r option for reloading and list the name of the profile file. Now, let's try to restart Samba:

donnie@ubuntu3:/etc/apparmor.d$ sudo systemctl restart smbd

donnie@ubuntu3:/etc/apparmor.d$ sudo systemctl status smbd
● smbd.service - LSB: start Samba SMB/CIFS daemon (smbd)
Loaded: loaded (/etc/init.d/smbd; bad; vendor preset: enabled)
Active: active (running) since Wed 2017-12-06 13:31:32 EST; 3min 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 17317 ExecStop=/etc/init.d/smbd stop (code=exited, status=0/SUCCESS)
Process: 16474 ExecReload=/etc/init.d/smbd reload (code=exited, status=0/SUCCESS)
Process: 17326 ExecStart=/etc/init.d/smbd start (code=exited, status=0/SUCCESS)
Tasks: 3
Memory: 9.3M
CPU: 594ms
CGroup: /system.slice/smbd.service
├─17342 /usr/sbin/smbd -D
├─17343 /usr/sbin/smbd -D
└─17345 /usr/sbin/smbd -D

Dec 06 13:31:28 ubuntu3 systemd[1]: Stopped LSB: start Samba SMB/CIFS daemon (smbd).
Dec 06 13:31:28 ubuntu3 systemd[1]: Starting LSB: start Samba SMB/CIFS daemon (smbd)...
Dec 06 13:31:32 ubuntu3 smbd[17326]: * Starting SMB/CIFS daemon smbd
Dec 06 13:31:32 ubuntu3 smbd[17326]: ...done.
Dec 06 13:31:32 ubuntu3 systemd[1]: Started LSB: start Samba SMB/CIFS daemon (smbd).
donnie@ubuntu3:/etc/apparmor.d$

And it works! The two Samba profiles are in enforce mode, and Samba finally starts up just fine.

The odd part about this is that I had this same problem with both Ubuntu 16.04 and Ubuntu 17.10. So, the bug has been there for a long time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.183.172