From 07ce2f717ab7cba7079d03130218c9d43ed2b062 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Thu, 1 Feb 2024 15:23:09 +0200 Subject: [PATCH] shmfs/shmfs_alloc. Fix POSIX violation for shmfs_truncate 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. --- fs/shm/shmfs_alloc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/shm/shmfs_alloc.c b/fs/shm/shmfs_alloc.c index 979fd4c3f4..65fb74ca3e 100644 --- a/fs/shm/shmfs_alloc.c +++ b/fs/shm/shmfs_alloc.c @@ -22,7 +22,11 @@ * Included Files ****************************************************************************/ +#include + #include + +#include #include #include @@ -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]); + } } }