NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/57622: memfd mmap does not work for requests < page size



>Number:         57622
>Category:       kern
>Synopsis:       memfd mmap does not work for requests < page size
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 20 13:20:01 +0000 2023
>Originator:     Martin Husemann
>Release:        NetBSD 10.99.8
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD thirdstage.duskware.de 10.99.8 NetBSD 10.99.8 (MODULAR) #666: Wed Sep 20 15:01:11 CEST 2023 martin%thirdstage.duskware.de@localhost:/usr/src/sys/arch/sparc64/compile/MODULAR sparc64
Architecture: sparc64
Machine: sparc64
>Description:

I noticed a new failing test in the sparc64 test runs:

tc-end: 1695216107.518483, seal_grow, failed, /usr/src/tests/kernel/t_memfd_create.c:270: Mmap failed unexpectedly (Invalid argument)

and tracked it down to the test writing 4096 byte to the memfd and then trying
to map that. On sparc64 the page size is 8k.

This makes the code sys/kern/sys_memfd.c line 352 fail:

        if (*offp + size > mfd->mfd_size) {
                error = EINVAL;
                goto leave;
        }

because mmap rounded up the requested size "size" to full pages already,
but mfd->mfd_size is smaller:

	*offp: 0 + size: 8192 > mfd_size: 4096

>How-To-Repeat:
s/a

>Fix:
Adjust mfd_size to full pages and make sure the surplus bytes are zeroed?
Keep track of the number of pages separately from content size and make the
if test against the #pages?



Home | Main Index | Thread Index | Old Index