Skip to content

Commit e7db065

Browse files
committed
pkg/subscriptions: use securejoin for the container path
If we join a path from the container image we must always use securejoin to prevent us from following a symlink onto the host. Fixes CVE-2024-9341 Signed-off-by: Paul Holzinger <[email protected]>
1 parent 91f5148 commit e7db065

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/subscriptions/subscriptions.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/containers/common/pkg/umask"
1212
"github.com/containers/storage/pkg/fileutils"
1313
"github.com/containers/storage/pkg/idtools"
14+
securejoin "github.com/cyphar/filepath-securejoin"
1415
rspec "github.com/opencontainers/runtime-spec/specs-go"
1516
"github.com/opencontainers/selinux/go-selinux/label"
1617
"github.com/sirupsen/logrus"
@@ -346,7 +347,10 @@ func addFIPSModeSubscription(mounts *[]rspec.Mount, containerRunDir, mountPoint,
346347

347348
srcBackendDir := "/usr/share/crypto-policies/back-ends/FIPS"
348349
destDir := "/etc/crypto-policies/back-ends"
349-
srcOnHost := filepath.Join(mountPoint, srcBackendDir)
350+
srcOnHost, err := securejoin.SecureJoin(mountPoint, srcBackendDir)
351+
if err != nil {
352+
return fmt.Errorf("resolve %s in the container: %w", srcBackendDir, err)
353+
}
350354
if err := fileutils.Exists(srcOnHost); err != nil {
351355
if errors.Is(err, os.ErrNotExist) {
352356
return nil

0 commit comments

Comments
 (0)