Skip to content

Commit

Permalink
runroot: add check that it is on volatile storage
Browse files Browse the repository at this point in the history
Make sure the runroot won't persist after a reboot, if it happens then
we can carry wrong information on the current active mounts.

Closes: containers/podman#2150

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Apr 12, 2019
1 parent f00b842 commit 04ce96b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ var (
ErrDigestUnknown = errors.New("could not compute digest of item")
// ErrLayerNotMounted is returned when the requested information can only be computed for a mounted layer, and the layer is not mounted.
ErrLayerNotMounted = errors.New("layer is not mounted")
// ErrTargetNotVolatile is returned when a path must be on volatile storage.
ErrTargetNotVolatile = errors.New("the target is not on tmpfs")
)
5 changes: 5 additions & 0 deletions pkg/mount/mountinfo_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ func parseMountTable() ([]*Info, error) {
}
return out, nil
}

// IsOnVolatileStorage returns whether the specified target is on tmpfs.
func IsOnVolatileStorage(target string) (bool, error) {
return true, nil
}
14 changes: 14 additions & 0 deletions pkg/mount/mountinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"io"
"os"
"strings"

"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

const (
Expand Down Expand Up @@ -93,3 +96,14 @@ func PidMountInfo(pid int) ([]*Info, error) {

return parseInfoFile(f)
}

// IsOnVolatileStorage returns whether the specified target is on tmpfs.
func IsOnVolatileStorage(target string) (bool, error) {
var fs unix.Statfs_t
// Make sure it's read-only.
if err := unix.Statfs(target, &fs); err != nil {
return false, errors.Wrapf(err, "error statfs %s", target)
}

return fs.Type == unix.TMPFS_MAGIC, nil
}
5 changes: 5 additions & 0 deletions pkg/mount/mountinfo_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ func parseMountTable() ([]*Info, error) {
C.fclose(mnttab)
return out, nil
}

// IsOnVolatileStorage returns whether the specified target is on tmpfs.
func IsOnVolatileStorage(target string) (bool, error) {
return true, nil
}
5 changes: 5 additions & 0 deletions pkg/mount/mountinfo_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ import (
func parseMountTable() ([]*Info, error) {
return nil, fmt.Errorf("mount.parseMountTable is not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
}

// IsOnVolatileStorage returns whether the specified target is on tmpfs.
func IsOnVolatileStorage(target string) (bool, error) {
return true, nil
}
5 changes: 5 additions & 0 deletions pkg/mount/mountinfo_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ func parseMountTable() ([]*Info, error) {
// Do NOT return an error!
return nil, nil
}

// IsOnVolatileStorage returns whether the specified target is on tmpfs.
func IsOnVolatileStorage(target string) (bool, error) {
return true, nil
}
9 changes: 9 additions & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/containers/storage/pkg/directory"
"github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/ioutils"
"github.com/containers/storage/pkg/mount"
"github.com/containers/storage/pkg/parsers"
"github.com/containers/storage/pkg/stringid"
"github.com/containers/storage/pkg/stringutils"
Expand Down Expand Up @@ -600,6 +601,14 @@ func GetStore(options StoreOptions) (Store, error) {
}
}

if onTmpfs, err := mount.IsOnVolatileStorage(options.RunRoot); err != nil || !onTmpfs {
if err != nil {
return nil, errors.Wrapf(err, "cannot check if %s is on tmpfs", options.RunRoot)
} else {
return nil, errors.Wrapf(ErrTargetNotVolatile, "%s must be on tmpfs", options.RunRoot)
}
}

graphLock, err := GetLockfile(filepath.Join(options.GraphRoot, "storage.lock"))
if err != nil {
return nil, err
Expand Down

0 comments on commit 04ce96b

Please sign in to comment.