Skip to content

Commit 0ec6bba

Browse files
committed
Handle wrapped errors correctly in libcontainer/init_linux.go
Signed-off-by: Curd Becker <me@curd-becker.de>
1 parent e0adafb commit 0ec6bba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libcontainer/init_linux.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func finalizeNamespace(config *initConfig) error {
314314
switch {
315315
case err == nil:
316316
doChdir = false
317-
case os.IsPermission(err):
317+
case errors.Is(err, os.ErrPermission):
318318
// If we hit an EPERM, we should attempt again after setting up user.
319319
// This will allow us to successfully chdir if the container user has access
320320
// to the directory, but the user running runc does not.
@@ -480,7 +480,12 @@ func setupUser(config *initConfig) error {
480480
setgroups, err = io.ReadAll(setgroupsFile)
481481
_ = setgroupsFile.Close()
482482
}
483-
if err != nil && !os.IsNotExist(err) {
483+
// be sure to use check for wrapped errors, since pathrs-lite will always
484+
// wrap os.ErrNotExist in procfs.errUnsafeProcfs
485+
// see:
486+
// https://github.com/opencontainers/runc/blob/59a5ff14a2c1f6beb74982a9c03e31c5fb49859d/vendor/github.com/cyphar/filepath-securejoin/pathrs-lite/internal/procfs/procfs_linux.go#L329C1-L330C1
487+
// https://github.com/opencontainers/runc/blob/59a5ff14a2c1f6beb74982a9c03e31c5fb49859d/vendor/github.com/cyphar/filepath-securejoin/pathrs-lite/internal/procfs/procfs_lookup_linux.go#L93
488+
if err != nil && !errors.Is(err, os.ErrNotExist) {
484489
return err
485490
}
486491

0 commit comments

Comments
 (0)