accept03/tst_fd: Harden parallel runs against shared path races
Subsystems (2)
PATCH 1/1 accept03/tst_fd: Harden parallel runs against shared path races
From: Stephen Bertram <[email protected]>
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, and give accept03 a private tmpdir.
Signed-off-by Stephen Bertram <[email protected]>
--- lib/tst_fd.c | 29 +++++++++++++++------ testcases/kernel/syscalls/accept/accept03.c | 1 + 2 files changed, 22 insertions(+), 8 deletions(-)
lib/tst_fd.c +21 -8
@@ -30,29 +30,42 @@ struct tst_fd_desc {const char *desc; }; +static void fd_path (char *buf,size_t len,const char *prefix) +{ +snprintf (buf, len,"%s_%d" , prefix,getpid ()); +} +static void open_file (struct tst_fd *fd) { - fd->fd =SAFE_OPEN ("fd_file" ,O_RDWR |O_CREAT ,0666 ); -SAFE_UNLINK ("fd_file" ); +char path[64 ]; + +fd_path (path,sizeof (path),"fd_file" ); + fd->fd =SAFE_OPEN (path,O_RDWR |O_CREAT |O_EXCL ,0666 ); +SAFE_UNLINK (path); }static void open_path (struct tst_fd *fd) { +char path[64 ];int tfd; - tfd =SAFE_CREAT ("fd_file" ,0666 ); +fd_path (path,sizeof (path),"fd_path" ); + tfd =SAFE_OPEN (path,O_RDWR |O_CREAT |O_EXCL ,0666 );SAFE_CLOSE (tfd); - fd->fd =SAFE_OPEN ("fd_file" ,O_PATH ); + fd->fd =SAFE_OPEN (path,O_PATH ); -SAFE_UNLINK ("fd_file" ); +SAFE_UNLINK (path); }static void open_dir (struct tst_fd *fd) { -SAFE_MKDIR ("fd_dir" ,0700 ); - fd->fd =SAFE_OPEN ("fd_dir" ,O_DIRECTORY ); -SAFE_RMDIR ("fd_dir" ); +char path[64 ]; + +fd_path (path,sizeof (path),"fd_dir" ); +SAFE_MKDIR (path,0700 ); + fd->fd =SAFE_OPEN (path,O_DIRECTORY ); +SAFE_RMDIR (path); }static void open_dev_zero (struct tst_fd *fd)
testcases/kernel/syscalls/accept/accept03.c +1 -0
@@ -55,4 +55,5 @@ static void verify_accept(void)static struct tst_test test = { .test_all = verify_accept, + .needs_tmpdir =1 , };
Signature · 1 line
2.55.0