diff --git a/pkg/sentry/fsimpl/tmpfs/tmpfs.go b/pkg/sentry/fsimpl/tmpfs/tmpfs.go index 9ac6d5518..e9fb3b90f 100644 --- a/pkg/sentry/fsimpl/tmpfs/tmpfs.go +++ b/pkg/sentry/fsimpl/tmpfs/tmpfs.go @@ -972,7 +972,14 @@ func parseSize(s string) (uint64, error) { count = count << 10 s = s[:len(s)-1] } - bytes, err := strconv.ParseUint(s, 10, 64) - bytes = bytes * uint64(count) + byteTmp, err := strconv.ParseUint(s, 10, 64) + if err != nil { + return 0, linuxerr.EINVAL + } + // Check for overflow. + bytes := byteTmp * uint64(count) + if byteTmp != 0 && bytes/byteTmp != uint64(count) { + return 0, fmt.Errorf("size overflow") + } return bytes, err } diff --git a/pkg/sentry/fsimpl/tmpfs/tmpfs_test.go b/pkg/sentry/fsimpl/tmpfs/tmpfs_test.go index 2aa58c8ec..df3ad2286 100644 --- a/pkg/sentry/fsimpl/tmpfs/tmpfs_test.go +++ b/pkg/sentry/fsimpl/tmpfs/tmpfs_test.go @@ -171,6 +171,8 @@ func TestParseSize(t *testing.T) { {"5P", (5 * 1024 * 1024 * 1024 * 1024 * 1024), false}, {"5e", (5 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024), false}, {"5e3", 0, true}, + {"", 0, true}, + {"9999999999999999P", 0, true}, } for _, tt := range tests { testname := fmt.Sprintf("%s", tt.s)