Add apparmor support module #188

Merged
merged 11 commits into from Nov 30, 2016

Conversation

Projects
None yet
3 participants
Collaborator

zyga commented Nov 23, 2016

This patch adds a new set of files, mimicking the xxx-support pattern
used for other changes, that so some extent abstracts the use of
apparmor in snap-confine.

Even when snap-confine is not compiled with apparmor support the same
APIs are available and gracefully degrade to no-ops.

As a small extension, snap confine can now know if it is confined (e.g.
a development version running in a random directory is not confined) and
will no longer crash when changing hats via aa_change_hat().

The patch doesn't yet change any of the tree to use the new functions.
This will be done in the next commit.

Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com

Add apparmor support module
This patch adds a new set of files, mimicking the xxx-support pattern
used for other changes, that to some extent abstracts the use of
apparmor in snap-confine.

Even when snap-confine is not compiled with apparmor support the same
APIs are available and gracefully degrade to no-ops.

As a small extension, snap confine can now know if it is confined (e.g.
a development version running in a random directory is not confined) and
will no longer crash when changing hats via aa_change_hat().

The patch doesn't yet change any of the tree to use the new functions.
This will be done in the next commit.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

zyga added some commits Nov 23, 2016

Rename sc_mode to sc_apparmor_mode
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Make sc_apparmor public
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Tweak docs for aa-support
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix stale header
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix typo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix another typo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

@zyga zyga referenced this pull request Nov 23, 2016

Merged

Use apparmor-support module #189

zyga added some commits Nov 29, 2016

Check for NULL mode and label
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Fix check for apparmor label
Unconfined processes get "unconfined", not an empty label.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

This looks good. I only have two small suggestions that I left inline.

src/apparmor-support.c
+ char *mode = NULL; // mode cannot be free'd
+ if (aa_getcon(&label, &mode) < 0) {
+ die("cannot query current apparmor profile");
+ }
@tyhicks

tyhicks Nov 29, 2016

Collaborator

This misses the situation where AppArmor support is compiled into snap-confine but AppArmor has been explicitly disabled by passing "apparmor=0" on the kernel command line. aa_getcon() will return -1 with errno set to EINVAL in this condition but that errno unfortunately overlaps with some other conditions.

The definitive way to see if AppArmor is enabled is aa_is_enabled(). You should call it first and, if it returns 1, proceed to calling aa_getcon() to check if snap-confine is confined. See the aa_is_enabled() man page for details.

@zyga

zyga Nov 29, 2016

Collaborator

+1 Thanks for this feedback. I'll do this.

src/apparmor-support.c
+ apparmor->mode = SC_AA_ENFORCE;
+ } else {
+ apparmor->mode = SC_AA_INVALID;
+ }
@tyhicks

tyhicks Nov 29, 2016

Collaborator

You'll want to check for "mixed" mode here. I've left a more descriptive review comment in the accompanying header file.

@zyga

zyga Nov 29, 2016

Collaborator

Ack

src/apparmor-support.h
+ SC_AA_ENFORCE = 1,
+ // The enforcement mode is "complain"
+ SC_AA_COMPLAIN,
+};
@tyhicks

tyhicks Nov 29, 2016

Collaborator

There is a new'ish mode (as of the 16.04 kernel), called "mixed". It means that two or more AppArmor profiles are stacked together but not all of their enforcement modes are the same. The mode string returned from aa_getcon() is "mixed".

@zyga

zyga Nov 29, 2016

Collaborator

Thanks, I'll update the code to handle this as well.

zyga added some commits Nov 30, 2016

Add support for 'mixed' confinement
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Use aa_is_enabled() to determine if apparmor is enabled
This patch changes the apparmor support initialization routine to first
call aa_is_enabled(). The rest of the code is tweaked for readability.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

@zyga zyga merged commit 267ca91 into master Nov 30, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@zyga zyga deleted the aa-support branch Nov 30, 2016

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