[LTP] [PATCH v2] accept03/tst_fd: Harden parallel runs against
Petr Vorel
pvorel@suse.cz
Wed Nov 4 19:32:59 CET 2026
> Concurrent syscall runs can TBROK in tst_fd when multiple processes
> race on fixed fd_file/fd_dir names (unlink ENOENT). Use pid-unique
> paths with O_EXCL, distinct names for the file and O_PATH cases.
>
> This covers accept03, epoll_pwait06, ioctl_pidfd01, and splice07,
> which call TST_FD_FOREACH without a private tmpdir.
While this is smart (no more tests will have bug due missing .needs_tmpdir = 1),
I'm not sure if it's a good idea. There is a reason why we have .needs_tmpdir,
e.g. CWD is read-only, no cleanup of created files, etc.
That's why I'd prefer to fix the 3 tests (add .needs_tmpdir) and then:
1) either add a check for missing .needs_tmpdir for these functions (patch
below) or
2) enable temporary directory creation for each test (slower, but no need to
ever worry).
The approach bellow is not ideal, because it covers only this case.
But adding check to safe_open() (and other functions) would have to check if the
path is relative or not, for which I would not bloat the library code.
Therefore I sent a patch checking this via sparse ('make check'):
https://lore.kernel.org/ltp/20261104182800.421758-1-pvorel@suse.cz/T/#u
Kind regards,
Petr
commit fa68043e5948ff1b8cb2c647d309ccf4808e23d7
Author: Petr Vorel <pvorel@suse.cz>
Date: 2026-11-04 18:34:06 +0100
tst_fd: Add check for missing .needs_tmpdir
Signed-off-by: Petr Vorel <pvorel@suse.cz>
diff --git lib/tst_fd.c lib/tst_fd.c
index 6538a098c7..05e1bbe8b0 100644
--- lib/tst_fd.c
+++ lib/tst_fd.c
@@ -22,6 +22,8 @@
#include "lapi/bpf.h"
#include "lapi/fsmount.h"
+#include "tso_tmpdir.h"
+
#include "tst_fd.h"
struct tst_fd_desc {
@@ -30,8 +32,17 @@ struct tst_fd_desc {
const char *desc;
};
+static void require_tmpdir(struct tst_fd *fd)
+{
+ if (!tst_tmpdir_created()) {
+ tst_brk(TBROK, "%s fd requires .needs_tmpdir = 1",
+ tst_fd_desc(fd));
+ }
+}
+
static void open_file(struct tst_fd *fd)
{
+ require_tmpdir(fd);
fd->fd = SAFE_OPEN("fd_file", O_RDWR | O_CREAT, 0666);
SAFE_UNLINK("fd_file");
}
@@ -40,6 +51,7 @@ static void open_path(struct tst_fd *fd)
{
int tfd;
+ require_tmpdir(fd);
tfd = SAFE_CREAT("fd_file", 0666);
SAFE_CLOSE(tfd);
@@ -50,6 +62,7 @@ static void open_path(struct tst_fd *fd)
static void open_dir(struct tst_fd *fd)
{
+ require_tmpdir(fd);
SAFE_MKDIR("fd_dir", 0700);
fd->fd = SAFE_OPEN("fd_dir", O_DIRECTORY);
SAFE_RMDIR("fd_dir");
More information about the ltp
mailing list