summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-09-10 13:23:49 -0700
committerShentubot <shentubot@google.com>2018-09-10 13:24:55 -0700
commit7e9e6745ca1f17031bbea14cb08b3ee3c0f9f818 (patch)
tree7c5ab289cbfb433d08a2c7e1e0192686982d4577 /pkg
parentda9ecb748cf6eb26e43338481d1ecba22eea09b2 (diff)
Allow '/dev/zero' to be mapped with unaligned length
PiperOrigin-RevId: 212321271 Change-Id: I79d71c2e6f4b8fcd3b9b923fe96c2256755f4c48
Diffstat (limited to 'pkg')
-rw-r--r--pkg/sentry/mm/special_mappable.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/pkg/sentry/mm/special_mappable.go b/pkg/sentry/mm/special_mappable.go
index aa2f87107..5d7bd33bd 100644
--- a/pkg/sentry/mm/special_mappable.go
+++ b/pkg/sentry/mm/special_mappable.go
@@ -138,10 +138,15 @@ func (m *SpecialMappable) Length() uint64 {
// uses an ephemeral file created by mm/shmem.c:shmem_zero_setup(); we should
// do the same to get non-zero device and inode IDs.
func NewSharedAnonMappable(length uint64, p platform.Platform) (*SpecialMappable, error) {
- if length == 0 || length != uint64(usermem.Addr(length).RoundDown()) {
+ if length == 0 {
return nil, syserror.EINVAL
}
- fr, err := p.Memory().Allocate(length, usage.Anonymous)
+ alignedLen, ok := usermem.Addr(length).RoundUp()
+ if !ok {
+ return nil, syserror.EINVAL
+ }
+
+ fr, err := p.Memory().Allocate(uint64(alignedLen), usage.Anonymous)
if err != nil {
return nil, err
}