Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle overlay xattr opaque bit #538

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions oci/layer/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func GenerateLayer(path string, deltas []mtree.InodeDelta, opt *RepackOptions) (
return errors.Wrapf(err, "couldn't determine overlay whiteout for %s", fullPath)
}

whiteout, err := isOverlayWhiteout(fi)
whiteout, err := isOverlayWhiteout(fi, fullPath, tg.fsEval)
if err != nil {
return err
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func GenerateInsertLayer(root string, target string, opaque bool, opt *RepackOpt
}

pathInTar := path.Join(target, curPath[len(root):])
whiteout, err := isOverlayWhiteout(info)
whiteout, err := isOverlayWhiteout(info, curPath, tg.fsEval)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion oci/layer/tar_extract_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestUnpackEntryOverlayFSWhiteout(t *testing.T) {
t.Fatalf("failed to stat `file`: %v", err)
}

whiteout, err := isOverlayWhiteout(fi)
whiteout, err := isOverlayWhiteout(fi, filepath.Join(dir, "file"), te.fsEval)
if err != nil {
t.Fatalf("failed to check overlay whiteout: %v", err)
}
Expand Down
26 changes: 23 additions & 3 deletions oci/layer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/apex/log"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/umoci/pkg/fseval"
"github.com/opencontainers/umoci/pkg/idtools"
"github.com/pkg/errors"
rootlesscontainers "github.com/rootless-containers/proto/go-proto"
Expand Down Expand Up @@ -230,7 +231,7 @@ func InnerErrno(err error) error {

// isOverlayWhiteout returns true if the FileInfo represents an overlayfs style
// whiteout (i.e. mknod c 0 0) and false otherwise.
func isOverlayWhiteout(info os.FileInfo) (bool, error) {
func isOverlayWhiteout(info os.FileInfo, fullPath string, fsEval fseval.FsEval) (bool, error) {
var major, minor uint32
switch stat := info.Sys().(type) {
case *unix.Stat_t:
Expand All @@ -243,6 +244,25 @@ func isOverlayWhiteout(info os.FileInfo) (bool, error) {
return false, errors.Errorf("[internal error] unknown stat info type %T", info.Sys())
}

return major == 0 && minor == 0 &&
info.Mode()&os.ModeCharDevice != 0, nil
if major == 0 && minor == 0 &&
info.Mode()&os.ModeCharDevice != 0 {
return true, nil
}

// also evaluate xattrs which may have opaque value set
attr, err := fsEval.Lgetxattr(fullPath, "user.overlay.opaque")
if err != nil {
v := errors.Cause(err)
if !errors.Is(err, os.ErrNotExist) && v != unix.EOPNOTSUPP && v != unix.ENODATA && v != unix.EPERM && v != unix.EACCES {
return false, errors.Errorf("[internal error] unknown stat info type %T", info.Sys())
}

return false, nil
}

if string(attr) == "y" {
return true, nil
}

return false, nil
}
Loading