diff mbox series

syscalls/getdents02: reserve big enough buffer

Message ID b35bcb5fb9a87e218ddccd3944b961568a831aa4.1726475265.git.jstancek@redhat.com
State Rejected
Headers show
Series syscalls/getdents02: reserve big enough buffer | expand

Commit Message

Jan Stancek Sept. 16, 2024, 8:30 a.m. UTC
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(-)

Comments

Cyril Hrubis Sept. 16, 2024, 10:09 a.m. UTC | #1
Hi!
What about the slightly different version from Andreas? Looks a bit better to me.
Jan Stancek Sept. 16, 2024, 10:32 a.m. UTC | #2
On Mon, Sep 16, 2024 at 12:10 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> What about the slightly different version from Andreas? Looks a bit better to me.

That works too, test still allocates only single dirp entry, but given what we
can expect to find in MNTPOINT that should be enough even if kernel
decides to change EINVAL check. I'll ACK his patch.
diff mbox series

Patch

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);