Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/archive/tar_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"archive/tar"
"errors"
"fmt"
"math"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -121,6 +122,16 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
mode |= unix.S_IFIFO
}

// Devmajor and Devminor come straight from the (untrusted) tar header as
// int64, but Mkdev only takes uint32. Casting a value that does not fit
// silently truncates it, so the node created on disk would carry a
// different major/minor than the header declares. Reject those instead of
// creating a mismatched device.
if hdr.Devmajor < 0 || hdr.Devmajor > math.MaxUint32 ||
hdr.Devminor < 0 || hdr.Devminor > math.MaxUint32 {
return fmt.Errorf("device number %d:%d for %q out of range: %w", hdr.Devmajor, hdr.Devminor, hdr.Name, errInvalidArchive)
}

return mknod(path, mode, unix.Mkdev(uint32(hdr.Devmajor), uint32(hdr.Devminor)))
}

Expand Down
52 changes: 52 additions & 0 deletions pkg/archive/tar_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//go:build !windows

/*
Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package archive

import (
"archive/tar"
"errors"
"math"
"path/filepath"
"testing"
)

func TestHandleTarTypeBlockCharFifoDeviceRange(t *testing.T) {
for _, tc := range []struct {
name string
devmajor int64
devminor int64
}{
{"major above uint32", math.MaxUint32 + 1, 0},
{"minor above uint32", 0, math.MaxUint32 + 1},
{"negative major", -1, 0},
{"negative minor", 0, -1},
} {
t.Run(tc.name, func(t *testing.T) {
hdr := &tar.Header{
Typeflag: tar.TypeBlock,
Devmajor: tc.devmajor,
Devminor: tc.devminor,
}
err := handleTarTypeBlockCharFifo(hdr, filepath.Join(t.TempDir(), "dev"))
if !errors.Is(err, errInvalidArchive) {
t.Fatalf("expected errInvalidArchive for %d:%d, got %v", tc.devmajor, tc.devminor, err)
}
})
}
}
4 changes: 2 additions & 2 deletions plugins/diff/windows/cimfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func init() {
plugins.MetadataPlugin,
},
InitFn: func(ic *plugin.InitContext) (any, error) {
if !cimfs.IsBlockCimSupported() {
return nil, fmt.Errorf("host OS version doesn't support block CIMs: %w", plugin.ErrSkipPlugin)
if !cimfs.IsBlockCimWriteSupported() {
return nil, fmt.Errorf("host OS doesn't support writable block CIMs: %w", plugin.ErrSkipPlugin)
}

md, err := ic.GetSingle(plugins.MetadataPlugin)
Expand Down
4 changes: 2 additions & 2 deletions plugins/snapshots/windows/block_cimfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func init() {
}

func NewBlockCIMSnapshotter(root string, config *BlockCIMSnapshotterConfig) (snapshots.Snapshotter, error) {
if !cimfs.IsBlockCimSupported() {
return nil, fmt.Errorf("host windows version doesn't support block CIMs: %w", plugin.ErrSkipPlugin)
if !cimfs.IsBlockCimWriteSupported() {
return nil, fmt.Errorf("host OS doesn't support writable block CIMs: %w", plugin.ErrSkipPlugin)
}

baseSn, err := newBaseSnapshotter(root)
Expand Down
4 changes: 2 additions & 2 deletions plugins/snapshots/windows/cimfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WithSize(size uint64) scratchCreationOpt {
// defaultScratchCreationOptions returns the default options for scratch VHD creation
func defaultScratchCreationOptions() *scratchCreationOptions {
return &scratchCreationOptions{
ntfsFormat: true,
ntfsFormat: false,
sizeInBytes: defaultScratchVHDSizeInBytes,
}
}
Expand Down Expand Up @@ -420,7 +420,7 @@ func createDifferencingScratchVHDs(ctx context.Context, path string) (err error)
}()

if !baseVHDExists {
if err = createScratchVHD(ctx, baseVHDPath); err != nil {
if err = createScratchVHD(ctx, baseVHDPath, WithNTFSFormat()); err != nil {
return fmt.Errorf("failed to create base vhd: %w", err)
}
}
Expand Down
Loading