Commit Graph

292 Commits

Author SHA1 Message Date
c66cb2a6ce Fix race in container creation
Only register a container once it's successfully started. This avoids a
race condition where the daemon is killed while in the process of
calling `libcontainer.Container.Start`, and ends up killing -1.

There is a time window where the container `initProcess` is not set, and
its PID unknown. This commit fixes the race Engine side.

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
Upstream-commit: ad2fa3945997905760a4c7ef0444580ffb4b939a
Component: engine
2016-03-03 20:25:03 -08:00
cf6760a787 Remove some unused structs and fields
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Upstream-commit: 0a352e1a906fbf7592aa95d6327776236d13392a
Component: engine
2016-03-01 09:59:29 -08:00
8135f8d68c Merge pull request #20699 from calavera/remove_static_error_declarations
Remove static errors from errors package.
Upstream-commit: df2b74188ec51422e84ec1dbdc58abf08c215019
Component: engine
2016-02-26 16:30:12 -08:00
e0b6d7e1f3 Merge pull request #20729 from estesp/pipework
Add synchronization and closure to IO pipes in userns path
Upstream-commit: 51302c29edf256276ba4ba9a20076866db522f66
Component: engine
2016-02-26 13:33:02 -08:00
b2ac99b3fa Remove static errors from errors package.
Moving all strings to the errors package wasn't a good idea after all.

Our custom implementation of Go errors predates everything that's nice
and good about working with errors in Go. Take as an example what we
have to do to get an error message:

```go
func GetErrorMessage(err error) string {
	switch err.(type) {
	case errcode.Error:
		e, _ := err.(errcode.Error)
		return e.Message

	case errcode.ErrorCode:
		ec, _ := err.(errcode.ErrorCode)
		return ec.Message()

	default:
		return err.Error()
	}
}
```

This goes against every good practice for Go development. The language already provides a simple, intuitive and standard way to get error messages, that is calling the `Error()` method from an error. Reinventing the error interface is a mistake.

Our custom implementation also makes very hard to reason about errors, another nice thing about Go. I found several (>10) error declarations that we don't use anywhere. This is a clear sign about how little we know about the errors we return. I also found several error usages where the number of arguments was different than the parameters declared in the error, another clear example of how difficult is to reason about errors.

Moreover, our custom implementation didn't really make easier for people to return custom HTTP status code depending on the errors. Again, it's hard to reason about when to set custom codes and how. Take an example what we have to do to extract the message and status code from an error before returning a response from the API:

```go
	switch err.(type) {
	case errcode.ErrorCode:
		daError, _ := err.(errcode.ErrorCode)
		statusCode = daError.Descriptor().HTTPStatusCode
		errMsg = daError.Message()

	case errcode.Error:
		// For reference, if you're looking for a particular error
		// then you can do something like :
		//   import ( derr "github.com/docker/docker/errors" )
		//   if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... }

		daError, _ := err.(errcode.Error)
		statusCode = daError.ErrorCode().Descriptor().HTTPStatusCode
		errMsg = daError.Message

	default:
		// This part of will be removed once we've
		// converted everything over to use the errcode package

		// FIXME: this is brittle and should not be necessary.
		// If we need to differentiate between different possible error types,
		// we should create appropriate error types with clearly defined meaning
		errStr := strings.ToLower(err.Error())
		for keyword, status := range map[string]int{
			"not found":             http.StatusNotFound,
			"no such":               http.StatusNotFound,
			"bad parameter":         http.StatusBadRequest,
			"conflict":              http.StatusConflict,
			"impossible":            http.StatusNotAcceptable,
			"wrong login/password":  http.StatusUnauthorized,
			"hasn't been activated": http.StatusForbidden,
		} {
			if strings.Contains(errStr, keyword) {
				statusCode = status
				break
			}
		}
	}
```

You can notice two things in that code:

1. We have to explain how errors work, because our implementation goes against how easy to use Go errors are.
2. At no moment we arrived to remove that `switch` statement that was the original reason to use our custom implementation.

This change removes all our status errors from the errors package and puts them back in their specific contexts.
IT puts the messages back with their contexts. That way, we know right away when errors used and how to generate their messages.
It uses custom interfaces to reason about errors. Errors that need to response with a custom status code MUST implementent this simple interface:

```go
type errorWithStatus interface {
	HTTPErrorStatusCode() int
}
```

This interface is very straightforward to implement. It also preserves Go errors real behavior, getting the message is as simple as using the `Error()` method.

I included helper functions to generate errors that use custom status code in `errors/errors.go`.

By doing this, we remove the hard dependency we have eeverywhere to our custom errors package. Yes, you can use it as a helper to generate error, but it's still very easy to generate errors without it.

Please, read this fantastic blog post about errors in Go: http://dave.cheney.net/2014/12/24/inspecting-errors

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: a793564b2591035aec5412fbcbcccf220c773a4c
Component: engine
2016-02-26 15:49:09 -05:00
5e9f05d546 Add synchronization and closure to IO pipes in userns path
The execdriver pipes setup uses OS pipes with fds so that they can be
chown'ed to the remapped root user for proper access. Recent flakiness
in certain short-lived tests (usually via the "exec" path) reveals that
the copy routines are not completing before exit/tear-down.

This fix adds synchronization and proper closure such that these
routines exit successfully.

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)
Upstream-commit: 995386735c2fe47ebb144f95adbc8eb1341ac48b
Component: engine
2016-02-26 13:47:34 -05:00
bea41e64ba generate seccomp profile convert type
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: ad600239bca1ac89d9684a98d6f7f260959e81d2
Component: engine
2016-02-19 13:32:54 -08:00
dad375d1d2 /dev/mqueue should never be mounted readonly
If user specifies --read-only flag it should not effect /dev/mqueue.
This is causing SELinux issues in docker-1.10.  --read-only blows up
on SELinux enabled machines.  Mounting /dev/mqueue read/only would also
blow up any tool that was going to use /dev/mqueue.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
Upstream-commit: adb2e3fedc76fbaecce0d75a29aa0d419be5c4c2
Component: engine
2016-02-15 14:56:07 -05:00
1a4e7d1b20 Make mqueue container specific
mqueue can not be mounted on the host os and then shared into the container.
There is only one mqueue per mount namespace, so current code ends up leaking
the /dev/mqueue from the host into ALL containers.  Since SELinux changes the
label of the mqueue, only the last container is able to use the mqueue, all
other containers will get a permission denied.  If you don't have SELinux protections
sharing of the /dev/mqueue allows one container to interact in potentially hostile
ways with other containers.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
Upstream-commit: ba38d58659cc155aebf89a2ea4cfc3cd7ba04a64
Component: engine
2016-02-05 16:50:35 +01:00
dce9d7fda4 remove the unused Info interface in daemon/execdriver/driver.go and related code
Signed-off-by: Fangyuan Gao <21551127@zju.edu.cn>
Upstream-commit: 5d07d83ee0802391ff2ed5e10838376a9b817bba
Component: engine
2016-02-02 09:04:52 +08:00
025414686c Fix typos in create.go
There were a few spelling issues that I noticed when reading about shared mounts.

Signed-off-by: jgeiger <joey.geiger@irco.com>
Upstream-commit: 318b4f0b5f0639149f5e88aba805cdd454d4d9ee
Component: engine
2016-01-28 14:08:11 -07:00
25f186f583 Merge pull request #19688 from crosbymichael/tmpfs-tar
Remove tar copy-up for tmpfs mounts
Upstream-commit: 3a70ab3a2c78ab40a5fdfe55be5745753eb41139
Component: engine
2016-01-26 17:03:07 -08:00
0bed041a45 Move tar copy-up for tmpfs mounts
We cannot rely on the tar command for this type of operation because tar
versions, flags, and functionality can very from distro to distro.
Since this is in the container execution path it is not safe to have
this as a dependency from dockers POV where the user cannot change the
fact that docker is adding these pre and post mount commands.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Upstream-commit: ae8ec4860e68e945cf6b2c157fa4e243c35c54a5
Component: engine
2016-01-26 14:00:39 -08:00
7187db20a2 move default seccomp profile into package
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: bed0bb7d017bb4a8400ac2c031dc74cd74240bfb
Component: engine
2016-01-21 16:55:29 -08:00
190d8fab36 move default apparmor policy into package
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: 35e50119fc2a2a6d9bcdc95c000df8b66d6cb9d3
Component: engine
2016-01-21 16:55:27 -08:00
7141a04b13 Merge pull request #19263 from jfrazelle/update-aa-parser
refactor aaparser pkg, add unit tests
Upstream-commit: 3233f4560912fee87857f653a8bb32050dc04927
Component: engine
2016-01-21 19:40:53 -05:00
6541731269 add send, recv, and x32 so we can install i386 pkgs on amd64
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: 308eff99e8468be4e92951de0ac69b27042a833b
Component: engine
2016-01-18 19:24:01 -08:00
a0c04482f7 refactor aaparser pkg, add unit tests
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: 446f498ebac56d4ed396b6c20252d152926dc30e
Component: engine
2016-01-13 08:43:12 -08:00
fb652937c3 read seccomp profile locally then pass to daemon
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: 062d0b3921316bc348c7930ce6599e1f8f297090
Component: engine
2016-01-12 13:12:29 -08:00
622bd04e41 Merge pull request #19217 from justincormack/arm_syscalls
Add arm specific syscalls to default seccomp profile
Upstream-commit: a96a0b37818e26bea173aa718df92f50b21093c3
Component: engine
2016-01-11 15:26:09 -08:00
8e7c65a2dd Merge pull request #19069 from jfrazelle/apparmor-regex-proc
fix proc regex
Upstream-commit: 9c9a1d1b4bc2122548a38b233a2f26ab5304de4c
Component: engine
2016-01-11 13:50:25 -08:00
ddd50b3705 Merge pull request #18512 from euank/18510-fixOomKilled
Set OOMKilled state on any OOM event
Upstream-commit: 967acd56c175b7c0f3ad4236c664730338a94bb8
Component: engine
2016-01-11 00:09:26 +01:00
1567cd421d Add arm specific syscalls to default seccomp profile
Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: 37d35f3c280dc27a00f2baa16431d807b24f8b92
Component: engine
2016-01-10 19:55:24 +00:00
fd32c5b230 Add i386 specific modify_ldt syscall to default seccomp filter
This syscall is used by Go on i386 binaries, although not by libc.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: 13a9d4e8993997b2bf9be7e96a8d7978a73d0b9b
Component: engine
2016-01-10 12:00:11 +00:00
d9a92e1dc3 Choose default-cgroup parent by cgroup driver
It's "/docker" for cgroupfs and "system.slice" for systemd.

Fix #19140

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Upstream-commit: c1cd45d547ef26cf988dc72d456430361dafcf08
Component: engine
2016-01-07 08:56:26 -08:00
f720f8755b Merge pull request #19110 from brahmaroutu/update_openc
update runc to the latest code base to fix gccgo builds
Upstream-commit: 4ee3048fa8382f9e9af2418029b8e53885bb906a
Component: engine
2016-01-06 15:09:11 -08:00
4d9fdc3032 fix proc regex
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: 2b4f64e59018c21aacbf311d5c774dd5521b5352
Component: engine
2016-01-06 10:08:35 -08:00
4da63ae80d update runc to the latest code base to fix gccgo build
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
Upstream-commit: 998263170750ee5504bc4fe23f9a3d1f797e2a41
Component: engine
2016-01-06 00:02:56 +00:00
f1e6f39a8c Allow the waitpid syscall
This version is sometimes used eg by glibc on x86

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: 822c4f79ab5c84d48bbdd5534cdfd98990cdcee7
Component: engine
2016-01-05 09:29:16 -08:00
92f421f9e7 Support compatible architectures with default seccomp rules
In the default seccomp rule, allow use of 32 bit syscalls on
64 bit architectures, so you can run x86 Linux images on x86_64
without disabling seccomp or using a custom rule.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: ca3ae72e43a0e6ad2f4f548586110c2e296ae1e9
Component: engine
2016-01-05 09:28:42 -08:00
cd434f010f Allow sigreturn syscall
This is used on some 32 bit architectures, eg x86

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: d8e06d54cf3f6478ba85f60cca4a9b03bbc68f10
Component: engine
2016-01-04 16:11:59 -08:00
31f24aba30 Add _llseek syscall
This is the newer verion of lseek on many 32 bit platforms

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: 923609179b18fb5fc9d4ad7820646af7e09786a2
Component: engine
2016-01-04 11:55:28 -08:00
2c12c040cd Do not allow obsolete syscalls
sysfs and ustat syscalls are marked obsolete.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: d6a9c5abed7370d9ef20b488e315b9730f22ed44
Component: engine
2016-01-04 11:55:28 -08:00
c09b757a5f Do not allow name_to_handle_at, as we have already blocked open_by_handle_at
Being able to obtain a file handle is no use as we cannot perform
any operation in it, and it may leak kernel state.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: c1b57fc1c9e230b95c2c76d1eaca0e3622fc72d5
Component: engine
2016-01-04 11:55:27 -08:00
93a585808e add 32bit syscalls to whitelist
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: a1747b3cc861c00803a67e5a61dce73db6ac8eee
Component: engine
2016-01-04 11:55:26 -08:00
f435c7102a change seccomp blacklist to whitelist
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: 17735c3c98056006b40834d7426d8d90afae5a2c
Component: engine
2016-01-04 11:55:21 -08:00
da10444c78 Fix declarations of of execdriver/native.NewDriver to have the same signature.
This change is done so that driver_unsupported.go and driver_unsupported_nocgo.go
declare the same signature for NewDriver as driver.go.

Fixes #19032

Signed-off-by: Lukas Waslowski <cr7pt0gr4ph7@gmail.com>
Upstream-commit: 9a03967f0abae4cc1dca00f339c58c31579c45b5
Component: engine
2016-01-02 19:55:37 +01:00
80207e0951 Merge pull request #18974 from jfrazelle/remove-seccomp-from-seccomp-profile
remove seccomp from seccomp profile
Upstream-commit: abc695d9d540610546e860ed5a9e432685b924b3
Component: engine
2015-12-29 13:15:14 -08:00
1149d92821 Merge pull request #18969 from justincormack/vm86
Block vm86 syscalls in default seccomp profile
Upstream-commit: a81e438544500a121298c82f340db490efda8a86
Component: engine
2015-12-29 11:57:35 -08:00
44a3b715ef Merge pull request #18972 from justincormack/bpf
Block bpf syscall from default seccomp profile
Upstream-commit: 2307f47fdd2b3079cb623a69b0fa0a0ef502c624
Component: engine
2015-12-29 11:57:07 -08:00
ed8f5303d0 Merge pull request #18971 from justincormack/ptrace
Block additional ptrace related syscalls in default seccomp profile
Upstream-commit: e01cab1cc5c7f92747a479b5480ca78f7fc37101
Component: engine
2015-12-29 11:56:51 -08:00
ba9125a4e7 remove seccomp from seccomp profile
This can be allowed because it should only restrict more per the seccomp docs, and multiple apps use it today.

Signed-off-by: Jessica Frazelle <acidburn@docker.com>
Upstream-commit: b610fc226afdf663b0ad46ad982c27fdee61f671
Component: engine
2015-12-29 11:21:33 -08:00
9e1ed3e829 Merge pull request #18947 from jfrazelle/fix-seccomp-unsupported
fix default profile where unsupported
Upstream-commit: 94e076086820aa34e6fc4fadb18714cd8b9263df
Component: engine
2015-12-29 10:21:07 -08:00
0adeca917f Merge pull request #18953 from justincormack/robust_list
Allow use of robust list syscalls in default seccomp policy
Upstream-commit: afdc4747dc16d4302ffd4f5dcb0fc537108862b7
Component: engine
2015-12-29 10:19:41 -08:00
f88929edd0 Merge pull request #18956 from justincormack/umount
Block original umount syscall in default seccomp filter
Upstream-commit: a32b06b067f847ee2cefe104430499c425c8fc2c
Component: engine
2015-12-29 10:19:04 -08:00
c726c9026e Block additional ptrace related syscalls in default seccomp profile
Block kcmp, procees_vm_readv, process_vm_writev.
All these require CAP_PTRACE, and are only used for ptrace related
actions, so are not useful as we block ptrace.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: a0a8ca0ae0bc9dc7faa0b8bacf4ca376c7257348
Component: engine
2015-12-29 18:17:28 +00:00
42db75c945 Merge pull request #18959 from justincormack/finit_module
Deny finit_module in default seccomp profile
Upstream-commit: ad8bce2ce4e27f7484fc65a3e6b9bf111793a263
Component: engine
2015-12-29 10:12:50 -08:00
00259400b7 Merge pull request #18961 from justincormack/clock_adjtime
Block clock_adjtime in default seccomp config
Upstream-commit: 8ac3d083a856729bc78adad3924e85d73d07173f
Component: engine
2015-12-29 10:08:45 -08:00
cb797e315a Block bpf syscall from default seccomp profile
The bpf syscall can load code into the kernel which may
persist beyond container lifecycle. Requires CAP_SYS_ADMIN
already.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: 33568405f34f363de49b1146119cc53bcb9e5f16
Component: engine
2015-12-29 17:28:30 +00:00
e76b5dd895 Block vm86 syscalls in default seccomp profile
These provide an in kernel virtual machine for x86 real mode on x86
used by one very early DOS emulator. Not required for any normal use.

Signed-off-by: Justin Cormack <justin.cormack@unikernel.com>
Upstream-commit: 6c3ea7a511ca641cdf4fa4da1d775d5b6f4bef3e
Component: engine
2015-12-29 15:47:23 +00:00