Blame SOURCES/docker-1879425.patch

7bbb67
From 0f90cc1ecb2db92e5388e07b8662b6c4a3a64f6c Mon Sep 17 00:00:00 2001
7bbb67
From: Kir Kolyshkin <kolyshkin@gmail.com>
7bbb67
Date: Tue, 15 Sep 2020 21:46:32 -0700
7bbb67
Subject: [PATCH] runc run: fix panic on error
7bbb67
7bbb67
In case (*initProcess).start did not set sentRun, and ierr is nil,
7bbb67
runc run panics:
7bbb67
7bbb67
```
7bbb67
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
7bbb67
	panic: runtime error: invalid memory address or nil pointer dereference
7bbb67
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x68a117]
7bbb67
7bbb67
goroutine 1 [running]:
7bbb67
github.com/urfave/cli.HandleAction.func1(0xc0002277d8)
7bbb67
	/home/kir/go/src/github.com/projectatomic/runc/Godeps/_workspace/src/github.com/urfave/cli/app.go:478 +0x22d
7bbb67
panic(0x730b60, 0xa06fc0)
7bbb67
	/usr/lib/golang/src/runtime/panic.go:969 +0x166
7bbb67
github.com/opencontainers/runc/libcontainer.(*genericError).Error(0x0, 0xc0002ca0e0, 0xe)
7bbb67
	/home/kir/go/src/github.com/projectatomic/runc/Godeps/_workspace/src/github.com/opencontainers/runc/libcontainer/generic_error.go:93 +0x37
7bbb67
github.com/opencontainers/runc/libcontainer.createSystemError(0x7fcd20, 0x0, 0x78c23e, 0xe, 0xc000098050, 0x0)
7bbb67
	/home/kir/go/src/github.com/projectatomic/runc/Godeps/_workspace/src/github.com/opencontainers/runc/libcontainer/generic_error.go:78 +0x14c
7bbb67
github.com/opencontainers/runc/libcontainer.newSystemErrorWithCause(...)
7bbb67
	/home/kir/go/src/github.com/projectatomic/runc/Godeps/_workspace/src/github.com/opencontainers/runc/libcontainer/generic_error.go:63
7bbb67
github.com/opencontainers/runc/libcontainer.(*initProcess).start(0xc000298000, 0x0, 0x0)
7bbb67
	/home/kir/go/src/github.com/projectatomic/runc/Godeps/_workspace/src/github.com/opencontainers/runc/libcontainer/process_linux.go:361 +0x94b
7bbb67
....
7bbb67
```
7bbb67
7bbb67
This is caused by the fact that `ierr` is a typed variable (rather than a
7bbb67
generic `error`), and when `newSystemErrorWithCause(ierr, ...)` is called
7bbb67
with a typed variable, the check `if err != nil` in `createSystemError`
7bbb67
does not work, since err has a type. This Golang peculiarity is described
7bbb67
in https://golang.org/doc/faq#nil_error.
7bbb67
7bbb67
After this patch (tested by temporarily modifying the source to set
7bbb67
`sentRun` to `false`) it no longer panics, instead we get:
7bbb67
7bbb67
```
7bbb67
container_linux.go:247: starting container process caused "container init failed"
7bbb67
```
7bbb67
7bbb67
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
7bbb67
---
7bbb67
 libcontainer/process_linux.go | 5 ++++-
7bbb67
 1 file changed, 4 insertions(+), 1 deletion(-)
7bbb67
7bbb67
diff --git a/libcontainer/process_linux.go b/libcontainer/process_linux.go
7bbb67
index 7c92c93a..53df9fa5 100644
7bbb67
--- docker-0be3e217c42ecf554bf5117bec9c832bd3f3b6fd/runc-66aedde759f33c190954815fb765eedc1d782dd9/libcontainer/process_linux.go
7bbb67
+++ docker-0be3e217c42ecf554bf5117bec9c832bd3f3b6fd/runc-66aedde759f33c190954815fb765eedc1d782dd9/libcontainer/process_linux.go
7bbb67
@@ -364,7 +364,10 @@ loop:
7bbb67
 		return newSystemError(fmt.Errorf("container init exited prematurely"))
7bbb67
 	}
7bbb67
 	if !sentRun {
7bbb67
-		return newSystemErrorWithCause(ierr, "container init")
7bbb67
+		if ierr != nil {
7bbb67
+			return newSystemErrorWithCause(ierr, "container init")
7bbb67
+		}
7bbb67
+		return newSystemError(errors.New("container init failed"))
7bbb67
 	}
7bbb67
 	if p.config.Config.Namespaces.Contains(configs.NEWNS) && !sentResume {
7bbb67
 		return newSystemError(fmt.Errorf("could not synchronise after executing prestart hooks with container process"))