From 7e9e6745ca1f17031bbea14cb08b3ee3c0f9f818 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Mon, 10 Sep 2018 13:23:49 -0700 Subject: Allow '/dev/zero' to be mapped with unaligned length PiperOrigin-RevId: 212321271 Change-Id: I79d71c2e6f4b8fcd3b9b923fe96c2256755f4c48 --- pkg/sentry/mm/special_mappable.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pkg/sentry') 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 } -- cgit v1.2.3