Skip to content

Commit 2ac9968

Browse files
committed
replace uses of os/exec with golang.org/x/sys/execabs
Go 1.15.7 contained a security fix for CVE-2021-3115, which allowed arbitrary code to be executed at build time when using cgo on Windows. This issue also affects Unix users who have “.” listed explicitly in their PATH and are running “go get” outside of a module or with module mode disabled. This issue is not limited to the go command itself, and can also affect binaries that use `os.Command`, `os.LookPath`, etc. From the related blogpost (ttps://blog.golang.org/path-security): > Are your own programs affected? > > If you use exec.LookPath or exec.Command in your own programs, you only need to > be concerned if you (or your users) run your program in a directory with untrusted > contents. If so, then a subprocess could be started using an executable from dot > instead of from a system directory. (Again, using an executable from dot happens > always on Windows and only with uncommon PATH settings on Unix.) > > If you are concerned, then we’ve published the more restricted variant of os/exec > as golang.org/x/sys/execabs. You can use it in your program by simply replacing This patch replaces all uses of `os/exec` with `golang.org/x/sys/execabs`. While some uses of `os/exec` should not be problematic (e.g. part of tests), it is probably good to be consistent, in case code gets moved around. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent ebe8f8c commit 2ac9968

41 files changed

Lines changed: 166 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

archive/compression/compression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424
"fmt"
2525
"io"
2626
"os"
27-
"os/exec"
2827
"strconv"
2928
"sync"
3029

3130
"github.com/containerd/containerd/log"
3231
"github.com/klauspost/compress/zstd"
32+
exec "golang.org/x/sys/execabs"
3333
)
3434

3535
type (

archive/compression/compression_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ import (
2424
"io/ioutil"
2525
"math/rand"
2626
"os"
27-
"os/exec"
2827
"path/filepath"
2928
"runtime"
3029
"strings"
3130
"testing"
31+
32+
exec "golang.org/x/sys/execabs"
3233
)
3334

3435
func TestMain(m *testing.M) {

archive/tar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"io"
2828
"io/ioutil"
2929
"os"
30-
"os/exec"
3130
"path/filepath"
3231
"testing"
3332
"time"
@@ -39,6 +38,7 @@ import (
3938
"github.com/containerd/continuity/fs"
4039
"github.com/containerd/continuity/fs/fstest"
4140
"github.com/pkg/errors"
41+
exec "golang.org/x/sys/execabs"
4242
)
4343

4444
const tarCmd = "tar"

cmd/containerd-shim/main_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"io"
2828
"net"
2929
"os"
30-
"os/exec"
3130
"os/signal"
3231
"runtime"
3332
"runtime/debug"
@@ -48,6 +47,7 @@ import (
4847
ptypes "github.com/gogo/protobuf/types"
4948
"github.com/pkg/errors"
5049
"github.com/sirupsen/logrus"
50+
exec "golang.org/x/sys/execabs"
5151
"golang.org/x/sys/unix"
5252
)
5353

cmd/containerd/command/service_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"io/ioutil"
2222
"log"
2323
"os"
24-
"os/exec"
2524
"path/filepath"
2625
"time"
2726
"unsafe"
@@ -31,6 +30,7 @@ import (
3130
"github.com/pkg/errors"
3231
"github.com/sirupsen/logrus"
3332
"github.com/urfave/cli"
33+
exec "golang.org/x/sys/execabs"
3434
"golang.org/x/sys/windows"
3535
"golang.org/x/sys/windows/svc"
3636
"golang.org/x/sys/windows/svc/debug"

cmd/ctr/commands/content/content.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"io"
2222
"io/ioutil"
2323
"os"
24-
"os/exec"
2524
"strings"
2625
"text/tabwriter"
2726
"time"
@@ -35,6 +34,7 @@ import (
3534
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3635
"github.com/pkg/errors"
3736
"github.com/urfave/cli"
37+
exec "golang.org/x/sys/execabs"
3838
)
3939

4040
var (

contrib/apparmor/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import (
2727
"io"
2828
"io/ioutil"
2929
"os"
30-
"os/exec"
3130
"path"
3231
"strconv"
3332
"strings"
3433
"text/template"
3534

3635
"github.com/pkg/errors"
36+
exec "golang.org/x/sys/execabs"
3737
)
3838

3939
// NOTE: This code is copied from <github.com/docker/docker/profiles/apparmor>.

contrib/fuzz/container_fuzzer.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ import (
2626
"context"
2727
"errors"
2828
"fmt"
29-
fuzz "github.com/AdaLogics/go-fuzz-headers"
30-
"github.com/containerd/containerd"
31-
"github.com/containerd/containerd/oci"
32-
"github.com/containerd/containerd/sys"
3329
"io"
3430
"io/ioutil"
3531
"net/http"
3632
"os"
37-
"os/exec"
3833
"strings"
3934
"time"
35+
36+
fuzz "github.com/AdaLogics/go-fuzz-headers"
37+
"github.com/containerd/containerd"
38+
"github.com/containerd/containerd/oci"
39+
"github.com/containerd/containerd/sys"
40+
exec "golang.org/x/sys/execabs"
4041
)
4142

4243
var (

contrib/nvidia/nvidia.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import (
2020
"context"
2121
"fmt"
2222
"os"
23-
"os/exec"
2423
"strconv"
2524
"strings"
2625

2726
"github.com/containerd/containerd/containers"
2827
"github.com/containerd/containerd/oci"
2928
specs "github.com/opencontainers/runtime-spec/specs-go"
29+
exec "golang.org/x/sys/execabs"
3030
)
3131

3232
// NvidiaCLI is the path to the Nvidia helper binary

diff/stream_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import (
2525
"fmt"
2626
"io"
2727
"os"
28-
"os/exec"
2928
"sync"
3029

3130
"github.com/gogo/protobuf/proto"
3231
"github.com/gogo/protobuf/types"
3332
"github.com/pkg/errors"
33+
exec "golang.org/x/sys/execabs"
3434
)
3535

3636
// NewBinaryProcessor returns a binary processor for use with processing content streams

0 commit comments

Comments
 (0)