lxc-start tries to change apparmor profile to unconfined

Bug #1215386 reported by Andre Nathan
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
lxc (Ubuntu)
Fix Released
High
Unassigned
Raring
Fix Released
Medium
Unassigned

Bug Description

=======================
SRU information
1. Impact: failure to start unconfined containers.
2. Development fix: make sure that the buffer into which we read the current container is \0-terminated
3. Stable fix: same as development fix
4. Test case:
     sudo lxc-create -t ubuntu -n x1
     sudo sed -i '/lxc.aa_profile/d' /var/lib/lxc/x1/config
     echo "lxc.aa_profile = unconfined" | sudo tee -a /var/lib/lxc/x1/config
     sudo lxc-start -n x1
     Unfortunately since the bug depends on a badly formed stack it can be hard to reproduce
5. Regression potential: there should be none, we are only setting the buffer to all zeros before we read into it.
========================

When starting a container that has 'lxc.aa_profile = unconfined' on its configuration file, lxc-start fails with

  lxc-start: Read-only file system - failed to change apparmor profile to unconfined

This happens because the buffer used by lxc-start to read the process' apparmor profile from /proc/<PID>/attr/current is not properly NULL-terminated. A patch for this has been applied upstream and is available at https://github.com/lxc/lxc/commit/626ad11bfee3e12e675f51e92920030a6f383b19

Ubuntu Release: Ubuntu 13.04
lxc package version: 0.9.0-0ubuntu3.4

Related branches

tags: added: lxc
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in lxc (Ubuntu):
status: New → Confirmed
Changed in lxc (Ubuntu):
importance: Undecided → High
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks for reporting this bug. Unfortunately it is rather hard to artificially reproduce as it requires just the right conditions on the stack. That'll make SRU justification harder, but I'll go ahead and push a proposal as it's important.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package lxc - 0.9.0-0ubuntu23

---------------
lxc (0.9.0-0ubuntu23) saucy; urgency=low

  * 0014-lxc-apparmor-null-terminate-buffer: make sure a value we fread is
    null-terminated (LP: #1215386)
  * 0015-fix-ipv6-pton: call inet_pton on the value without the netmask.
    (LP: #1215391)
 -- Serge Hallyn <email address hidden> Fri, 23 Aug 2013 11:39:55 -0500

Changed in lxc (Ubuntu):
status: Confirmed → Fix Released
Changed in lxc (Ubuntu Raring):
status: New → Triaged
importance: Undecided → Medium
description: updated
description: updated
Revision history for this message
Brian Murray (brian-murray) wrote : Please test proposed package

Hello Andre, or anyone else affected,

Accepted lxc into raring-proposed. The package will build now and be available at http://launchpad.net/ubuntu/+source/lxc/0.9.0-0ubuntu3.5 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in lxc (Ubuntu Raring):
status: Triaged → Fix Committed
tags: added: verification-needed
Revision history for this message
Andre Nathan (andre-digirati) wrote :

Hi

The issue is still not fixed with the patch. While there's no more garbage in the buffer that stores the apparmor profile read from /proc, that data is still terminated by a "\n", (ie., the profile is returned as, eg. "unconfined\n" instead of "unconfined"). This causes comparisons with the "unconfined" string further in the code to fail.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Hi Andre,

the test case in the bug description is passing for me. Can you please tell me exactly what you do to reproduce this, if possible starting from a clean install?

Based on your comment I thought it might be that you had disabled /etc/apparmor.d/usr.bin.lxc-start, but even doing that I'm still able to start a container which has lxc.aa_profile = unconfined

Revision history for this message
Andre Nathan (andre-digirati) wrote :

You are correct, the error I'm seeing comes from the fact that I have this line on the container's fstab:

  proc /var/lib/lxc/test/rootfs/proc proc ro,nodev,noexec,nosuid 0 0

That is, I was trying to mount /proc as read-only in the container. This works for me in 12.04 but not in 13.04.

Revision history for this message
Andre Nathan (andre-digirati) wrote :

Just to confirm, the bug wrt the apparmor profile is indeed fixed.

Revision history for this message
Serge Hallyn (serge-hallyn) wrote : Re: [Bug 1215386] Re: lxc-start tries to change apparmor profile to unconfined

Quoting Andre Nathan (<email address hidden>):
> You are correct, the error I'm seeing comes from the fact that I have
> this line on the container's fstab:
>
> proc /var/lib/lxc/test/rootfs/proc proc ro,nodev,noexec,nosuid 0 0
>
> That is, I was trying to mount /proc as read-only in the container. This
> works for me in 12.04 but not in 13.04.

Thank you - to make sure I understand, do you also have
/etc/apparmor.d/usr.bin.lxc-start disabled? If you do,
then when the container starts it is already undefined,
then lxc is supposed to detect that it is already
unconfined and not transition at all. But if you have
the lxc-start profile still enabled, then the container is
started while in the lxc-start profile, and a transition
is required (requiring read-write proc).

So if it is failing for you with /etc/apparmor.d/usr.bin.lxc-start
disabled, then let's open a new bug for that and I'll fix that in
a separate SRU.

Revision history for this message
Andre Nathan (andre-digirati) wrote :

I tried it with /etc/apparmor.d/usr.bin.lxc-start both enabled and disabled, and also with and without lxc.aa_profile = unconfined in the configuration file and all tests worked fine in the four possible combinations of those settings.

tags: added: verification-done
removed: verification-needed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package lxc - 0.9.0-0ubuntu3.5

---------------
lxc (0.9.0-0ubuntu3.5) raring-proposed; urgency=low

  * 0014-lxc-apparmor-null-terminate-buffer: make sure a value we fread is
    null-terminated (LP: #1215386)
  * 0015-fix-ipv6-pton: call inet_pton on the value without the netmask.
    (LP: #1215391)
 -- Serge Hallyn <email address hidden> Fri, 23 Aug 2013 11:38:57 -0500

Changed in lxc (Ubuntu Raring):
status: Fix Committed → Fix Released
Revision history for this message
Brian Murray (brian-murray) wrote : Update Released

The verification of this Stable Release Update has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regresssions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.