interfaces/default: allow mknod for regular files, pipes and sockets (LP: #1636540) #2749

Merged
merged 34 commits into from Apr 27, 2017

Conversation

Projects
None yet
5 participants
Contributor

jdstrand commented Jan 30, 2017

This adds SCMP_CMP_MASKED_EQ support for doing things like '|S_IFIFO' in the policy to support
mknod which uses bitmasks for the permissions and file type. Developing this PR uncovered a number of testsuite rough edges, so fix those along the way.

interfaces/default: allow mknod for regular files, pipes and sockets
This add SCMP_CMP_MASKED_EQ support for doing |S_IFIFO in the policy to support
mknod which uses bitmasks for the permissions and file type.
Contributor

jdstrand commented Jan 30, 2017

@tyhicks - can you take a look at the policy syntax changes?

@@ -423,7 +435,12 @@ static int parse_line(char *line, struct seccomp_args *sargs)
if (errno != 0)
return PARSE_ERROR;
- sargs->arg_cmp[sargs->length] = SCMP_CMP(pos, op, value);
+ if (op == SCMP_CMP_MASKED_EQ)
@zyga

zyga Jan 30, 2017

Contributor

Can you please explain the reasoning behind this? I'm just unfamiliar and I'd like to understand it better.

@jdstrand

jdstrand Jan 30, 2017

Contributor

SCMP_CMP_MASKED_EQ is what you use to check bitmasks (eg, '|S_IFREG'). Since for mknod(2) the second argument is a bitmask for mode_t, we need to see if S_IFREG is set within the mode_t, and you do that with SCMP_CMP_MASKED_EQ. Because SCMP_CMP takes an additional argument for the mask when op is 'SCMP_CMP_MASKED_EQ', we check if the op is 'SCMP_CMP_MASKED_EQ' and give that extra argument, otherwise we do like we've always done. It is sufficient for us to use 'value' for both the mask and the datum because if we have have rule mknod - |S_IFREG - then <mode_t>|S_IFREG matches S_IFREG when using something like mknod(..., S_IFREG|S_IRUSR|S_IWUSR, ...).

For more information, see 'man 3 seccomp_rule_add'.

Contributor

jdstrand commented Jan 31, 2017

Closing for the moment since the spread test failure needs to be investigated.

@jdstrand jdstrand closed this Jan 31, 2017

jdstrand added some commits Jan 31, 2017

adjust mknod tests for mount namespace and running as root
- adjust common.sh to create a temp dir in /run/shm that is auto-cleaned
- put the pipes in /run/shm since run is shared between global and app mount
  namespace
- adjust logic of perms test to use 'stat' instead of 'test -w' for when the
  testsuite is run as root (as with spread)
- adjust common.sh to add more helpful debug output as part of FAIL

@jdstrand jdstrand reopened this Jan 31, 2017

jdstrand added some commits Jan 31, 2017

increase debug verbosity for security policy denials
- disable kernel rate limiting
- also search for seccomp denials in debug output
Contributor

zyga commented Feb 1, 2017

The final logged seccomp event is about system call 201 which on x86 is geteuid32 but AFAIR it was added to common.sh when i386 support was fixed.

Contributor

jdstrand commented Feb 1, 2017

@zyga - the geteuid32 is in the default policy but the denial is not from this test. I think it is from test_restrictions, but I'll make this test clearer so the geteuid32/geteuid stops confusing people.

If you look at the latest travis failure, it is in linode:ubuntu-16.04-32:tests/main/gccgo. c-unit-tests passes everywhere now. The failure in linode:ubuntu-16.04-32:tests/main/gccgo is confusing since c-unit-tests is passing and so are the autopkgtests (minus ppc64el). I'll take a look at that test now.

Contributor

jdstrand commented Feb 1, 2017

And of course, this seems to be an intermittent failure:

$ spread -reuse -resend -debug linode:ubuntu-16.04-32:tests/main/gccgo
2017/02/01 12:21:39 Allocating linode:ubuntu-16.04-32...
2017/02/01 12:22:36 Allocated linode:ubuntu-16.04-32 (Spread-X).
2017/02/01 12:22:36 Connecting to linode:ubuntu-16.04-32 (Spread-X)...
2017/02/01 12:22:53 Connected to linode:ubuntu-16.04-32 (Spread-X) at 45.79.186.250.
2017/02/01 12:22:53 Sending project content to linode:ubuntu-16.04-32 (Spread-X)...
2017/02/01 12:35:09 Successful tasks: 1
2017/02/01 12:35:09 Aborted tasks: 0
2017/02/01 12:35:09 Keeping linode:ubuntu-16.04-32 (Spread-X) at 45.79.186.250
Contributor

jdstrand commented Feb 1, 2017

I checked the original log and saw that linode:ubuntu-16.04-32 went to Spread-C and Spread-D. Perhaps Spread-C or Spread-D is out of date?

jdstrand added some commits Feb 1, 2017

copy snap-confine ($L) to name of the test to improve logging
Seccomp logs might show up as:
audit: type=1326 audit(1485875879.395:1909): auid=1000 uid=0 gid=0 ses=14
pid=13916 comm="snap-confine"
exe=".../snap-confine"
sig=31 arch=c000003e syscall=107 compat=0 ip=0x7f5a332e46a7 code=0x0

Some tests have expected failures but these tests are all logged as
comm="snap-confine" exe="/path/to/snap-confine" which leads to confusion when
debugging (eg, in the above example syscall 107 (geteuid) was blocked, but it
is in the list of common syscalls. This denial is from test_restrictions which
is expected to have geteuid blocked).

The fix is to copy snap-confine to the name of the test so that exe and comm
use the name of the test. Eg:

audit: type=1326 audit(1485956974.614:58308): auid=4294967295
uid=1000 gid=1000 ses=4294967295 pid=3472 comm="test_restrictio"
exe="/tmp/tmp.dsDGaRXxWx/test_restrictions" sig=31 arch=c000003e syscall=107
compat=0 ip=0x7f5bd35446a7 code=0x0
Contributor

jdstrand commented Feb 1, 2017

This is annoying. The autopkgtests fail with tests/main/gccgo and so does continuous-integration via travis, but locally and running spread -reuse -resend -debug linode:ubuntu-16.04-32:tests/main/gccgo with spread 27 runs fine. I suspect something wrong with the tests/main/gccgo but I can't get it to reproduce to debug it.

Contributor

jdstrand commented Feb 1, 2017

Ok, finally got gccgo test to work. Now unrelated tests are failing:

2017/02/01 21:45:42 Successful tasks: 520
2017/02/01 21:45:42 Aborted tasks: 1
2017/02/01 21:45:42 Failed tasks: 3
    - linode:ubuntu-14.04-64:tests/main/snap-run-alias:testsnapdtoolscat
    - linode:ubuntu-14.04-64:tests/regression/lp-1595444
    - linode:ubuntu-16.04-32:tests/main/revert-devmode:remote
2017/02/01 21:45:42 Failed task prepare: 1
    - linode:ubuntu-14.04-64:tests/main/interfaces-cups-control
Contributor

jdstrand commented Feb 2, 2017

After a couple of tries, the unrelated tests (finally) passed.

@jdstrand jdstrand changed the title from interfaces/default: allow mknod for regular files, pipes and sockets to interfaces/default: allow mknod for regular files, pipes and sockets (LP: #1636540) Feb 2, 2017

jdstrand added some commits Feb 2, 2017

Contributor

jdstrand commented Feb 7, 2017

FYI, @tyhicks and I discussed the syntax changes over IRC and hangout and we agreed the syntax changes in this PR are ok.

Contributor

jdstrand commented Feb 8, 2017

The zesty-amd64 test failures are unrelated:

2017/02/07 21:44:55 Aborted tasks: 111
2017/02/07 21:44:55 Failed task prepare: 6
    - autopkgtest:ubuntu-17.04-amd64:tests/main/cmdline
    - autopkgtest:ubuntu-17.04-amd64:tests/main/help:install
    - autopkgtest:ubuntu-17.04-amd64:tests/main/help:remove
    - autopkgtest:ubuntu-17.04-amd64:tests/main/interfaces-udev
    - autopkgtest:ubuntu-17.04-amd64:tests/main/security-profiles
    - autopkgtest:ubuntu-17.04-amd64:tests/main/try-snap-is-optional
2017/02/07 21:44:55 Failed task restore: 1
    - autopkgtest:ubuntu-17.04-amd64:tests/main/security-profiles
error: unsuccessful run
Contributor

jdstrand commented Feb 9, 2017

The continuous integration test is unrelated:
linode:ubuntu-14.04-64:tests/regression/lp-1595444

Contributor

jdstrand commented Feb 13, 2017

@mvo5 - fyi, not sure what happened if anything, but the CI tests got restarted and just passed.

Let's please wait until snap-confine is executed from the core before landing this

@mvo5 mvo5 added this to the 2.23 milestone Feb 14, 2017

Seems fine, but please make sure tests are actually running and verifying what they're supposed to together with the remaining of our automated spread tests.

@@ -18,7 +18,7 @@ execute: |
! /snap/bin/snapd-hacker-toolbelt.busybox true
sysctl -w kernel.printk_ratelimit=$orig_ratelimit
echo "Not only the command failed because snap-confine failed, we see why!"
- dmesg | grep 'apparmor="DENIED" operation="mount" info="failed srcname match" error=-13 profile="/usr/lib/snapd/snap-confine" name="/snap/bin/" pid=[0-9]\+ comm="ubuntu-core-lau" srcname="/snap/snapd-hacker-toolbelt/[0-9]\+/mnt/" flags="rw, bind"'
+ dmesg --ctime | grep 'apparmor="DENIED" operation="mount" info="failed srcname match" error=-13 profile="/usr/lib/snapd/snap-confine" name="/snap/bin/" pid=[0-9]\+ comm="ubuntu-core-lau" srcname="/snap/snapd-hacker-toolbelt/[0-9]\+/mnt/" flags="rw, bind"'
@niemeyer

niemeyer Feb 14, 2017

Contributor

I don't think these tests are even running. Actual tests live in /tests by now.

We need to kill these for good @zyga.

spread.yaml
+ # apparmor
+ dmesg --ctime | grep DENIED || true
+ # seccomp
+ dmesg --ctime | grep type=1326 || true
@niemeyer

niemeyer Feb 14, 2017

Contributor

Thanks, that's nicer.

@mvo5 mvo5 removed this from the 2.23 milestone Feb 16, 2017

Collaborator

mvo5 commented Feb 16, 2017

Yeah, we can not land this before #2810 has landed

mvo5 approved these changes Mar 3, 2017

We re-generate seccomp/apparmor in 2.23 now on startup. So this can land now AFAICT.

Contributor

jdstrand commented Mar 3, 2017

@mvo5 - "We re-generate seccomp/apparmor in 2.23 now on startup. So this can land now AFAICT."

We did? Part of that change was supposed to revert the revert of the quotactl and 'ioctl - !TIOCSTI' rules, but that isn't in trunk now.

Contributor

niemeyer commented Mar 10, 2017

@mvo5 @jdstrand I'm a bit lost here. What are these quotactl changes and what is this PR blocked on?

Collaborator

mvo5 commented Mar 13, 2017

@jdstrand Uh, sorry. We do re-generate the profiles now but that is not sufficient because we do not yet run the matching snap-confine. So This can not quite be merged :/

@chipaca chipaca added the Blocked label Mar 15, 2017

jdstrand and others added some commits Mar 29, 2017

Contributor

jdstrand commented Apr 17, 2017

It is my understanding that this is now unblocked, so removing that tag, but closing until I have a chance to review and retest everything.

@jdstrand jdstrand closed this Apr 17, 2017

@jdstrand jdstrand removed the Blocked label Apr 17, 2017

Contributor

jdstrand commented Apr 18, 2017

I'm told that we can start landing the seccomp changes since snap-confine now is re-exec'd as necessary on classic.

@jdstrand jdstrand reopened this Apr 18, 2017

mvo5 and others added some commits Apr 19, 2017

@elopio elopio referenced this pull request in bigchaindb/bigchaindb Apr 20, 2017

Merged

Add the packaging metadata to build the bigchaindb snap #1415

zyga approved these changes Apr 27, 2017

zyga approved these changes Apr 27, 2017

+1

tests/unit/c-unit-tests/task.yaml
@@ -37,4 +37,4 @@ debug: |
# Show the test suite failure log if there's one
cat $SPREAD_PATH/cmd/autogarbage/test-suite.log || true
# Show seccomp audit messages
- tail /var/log/kern.log | grep -F type=1326
@zyga

zyga Apr 27, 2017

Contributor

This is now in default debug-each so we could drop this copy.

jdstrand added some commits Apr 27, 2017

data/info
@@ -1 +1 @@
-VERSION=unknown
+VERSION=2.24
@zyga

zyga Apr 27, 2017

Contributor

You don't want this change.

@jdstrand

jdstrand Apr 27, 2017

Contributor

Hrmm, that came in as a result of the merge from trunk. Removing.

@@ -383,4 +391,6 @@ prepare_all_snap() {
tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd $BOOT
systemctl start snapd.socket
fi
+
+ disable_kernel_rate_limiting
@jdstrand

jdstrand Apr 27, 2017

Contributor

I think it is these that are causing the issues with the testsuite. There are tons of apparmor denials in the snapd-reexec test for snap.network-bind-consumer.network-consumer:

2017-04-19 13:36:01 Error executing linode:ubuntu-14.04-64:tests/main/snapd-reexec : 
-----
+ '[' '' = 0 ']'
+ echo 'Ensure we re-exec by default'
Ensure we re-exec by default
+ snap list
2017/04/19 13:35:59.295076 main.go:237: WARNING: cannot create syslog logger
2017/04/19 13:35:59.431711 main.go:237: WARNING: cannot create syslog logger
Name  Version  Rev   Developer  Notes
core  16-2     1736  canonical  -
+ MATCH 'DEBUG: restarting into'
+ journalctl
error: pattern not found, got:
-- Logs begin at Wed 2017-04-19 13:31:24 UTC, end at Wed 2017-04-19 13:31:25 UTC. --
Apr 19 13:31:24 ubuntu kernel: audit: type=1400 audit(1492608684.195:6094): apparmor="DENIED" operation="accept" profile="snap.network-bind-consumer.network-consumer" pid=16384 comm="python3" laddr=127.0.0.1 lport=8081 family="inet" sock_type="stream" protocol=6 requested_mask="accept" denied_mask="accept"
Apr 19 13:31:24 ubuntu kernel: audit: type=1400 audit(1492608684.195:6095): apparmor="DENIED" operation="accept" profile="snap.network-bind-consumer.network-consumer" pid=16384 comm="python3" laddr=127.0.0.1 lport=8081 family="inet" sock_type="stream" protocol=6 requested_mask="accept" denied_mask="accept"

I'm going to revert the disabling of rate limiting for now so this PR will pass and add a forum topic that the tests should be able to run with this enabled.

zyga approved these changes Apr 27, 2017

Contributor

jdstrand commented Apr 27, 2017

The xenial-i386 failure is unrelated:

2017-04-27 20:16:45 Failed tasks: 1
    - autopkgtest:ubuntu-16.04-i386:tests/main/completion

@zyga zyga merged commit 25e1239 into snapcore:master Apr 27, 2017

5 of 6 checks passed

xenial-i386 autopkgtest finished (failure)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-amd64 autopkgtest finished (success)
Details
xenial-ppc64el autopkgtest finished (success)
Details
yakkety-amd64 autopkgtest finished (success)
Details
zesty-amd64 autopkgtest finished (success)
Details
Contributor

jdstrand commented Apr 27, 2017

Thanks for the reviews and merge! :)

@jdstrand jdstrand deleted the jdstrand:seccomp-mknod branch May 3, 2017

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