[LTP] [PATCH] syscalls/getdents02: reserve big enough buffer

Jan Stancek jstancek@redhat.com
Mon Sep 16 10:30:24 CEST 2024


The test sporadically fails EFAULT testcase because kernel can iterate over
directory entries in different order. In most runs the first entry it finds
is '.', but in others it can be 'lost+found' or directory/file created by test.

Test currently only reserves space for buffer via tst_dirp_size(),
which uses sizeof() and doesn't take into account number of entries or
the size of d_name.

Since sizeof returns the aligned size, in some runs there's just enough
space for '.' entry, and test fails as expected on EFAULT. But if there's
entry with larger d_name we hit EINVAL check first and test fails.

Reserve large enough buffer.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/syscalls/getdents/getdents02.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/getdents/getdents02.c b/testcases/kernel/syscalls/getdents/getdents02.c
index 805a8bc481e6..d17410c52afc 100644
--- a/testcases/kernel/syscalls/getdents/getdents02.c
+++ b/testcases/kernel/syscalls/getdents/getdents02.c
@@ -60,7 +60,8 @@ static void setup(void)
 {
 	getdents_info();
 
-	size = tst_dirp_size();
+	/* reserve big enough buffer for all entries we might find */
+	size = 4096;
 	dirp = tst_alloc(size);
 
 	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
-- 
2.43.0



More information about the ltp mailing list