Skip to content

Commit

Permalink
shmfs/shmfs_alloc. Fix POSIX violation for shmfs_truncate
Browse files Browse the repository at this point in the history
When shmfs_truncate is called, it uses shmfs_alloc_object to create the
physical backing for the shm file. However, the allocated physical
memory returned by mm_pgalloc is not cleared when CONFIG_BUILD_KERNEL is
set, which is a clear POSIX violation:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html

"If the file was previously shorter than length, its size is increased,
and the extended area appears as if it were zero-filled."

For FLAT and PROTECTED modes zalloc is used, so the violation affects
KERNEL mode only.
  • Loading branch information
pussuw committed Feb 6, 2024
1 parent 9a979f1 commit 480e853
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions fs/shm/shmfs_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#include <stdbool.h>

#include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <nuttx/pgalloc.h>

Expand Down Expand Up @@ -87,6 +91,12 @@ FAR struct shmfs_object_s *shmfs_alloc_object(size_t length)
{
break;
}
else
{
/* Clear the page memory (requirement for truncate) */

up_addrenv_page_wipe((uintptr_t)pages[i]);
}
}
}

Expand Down

0 comments on commit 480e853

Please sign in to comment.