Introduce SAFE_SPLICE()
cover Introduce SAFE_SPLICE()
- add SAFE_SPLICE()
- update tests to use the new macro
---
Andrea Cervesato (2):
lib: Add SAFE_SPLICE() macro
tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
include/tst_safe_macros.h | 8 ++++++++ lib/tst_safe_macros.c | 17 +++++++++++++++++ testcases/kernel/crypto/af_alg08.c | 10 ++-------- testcases/kernel/syscalls/tee/tee01.c | 9 ++------- testcases/kernel/syscalls/vmsplice/vmsplice01.c | 6 +----- 5 files changed, 30 insertions(+), 20 deletions(-)
---
base-commit: 72ca484cca53710b956ba2fcc1ff203fe9c9b73b
change-id: 20260430-safe_splice-a3d6403f99cd
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/2 lib: Add SAFE_SPLICE() macro
From: Andrea Cervesato <[email protected]>
splice() is used as utility plumbing in several tests (tee01, vmsplice01, af_alg08) but lacks a SAFE_* wrapper, forcing each caller to manually check the return value. Add SAFE_SPLICE() following the existing safe_pipe2() pattern.
--- include/tst_safe_macros.h | 8 ++++++++ lib/tst_safe_macros.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+)
include/tst_safe_macros.h +8 -0
@@ -114,6 +114,14 @@ int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags);#define SAFE_PIPE2 (fildes, flags) \ safe_pipe2(__FILE__, __LINE__, (fildes), (flags)) +ssize_t safe_splice (const char *file,const int lineno, +int fd_in,loff_t *off_in,int fd_out,loff_t *off_out, +size_t len,unsigned int flags); + +#define SAFE_SPLICE (fd_in, off_in, fd_out, off_out, len, flags) \ + safe_splice(__FILE__, __LINE__, (fd_in), (off_in), (fd_out), \ + (off_out), (len), (flags)) +#define SAFE_READ (len_strict, fildes, buf, nbyte) \ safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
lib/tst_safe_macros.c +17 -0
@@ -21,6 +21,7 @@#include "tst_safe_macros.h" #include "lapi/personality.h" #include "lapi/pidfd.h" +#include "lapi/splice.h" int safe_access (const char *file,const int lineno,const char *pathname,int mode)
@@ -512,6 +513,22 @@ int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags)return ret; } +ssize_t safe_splice (const char *file,const int lineno, +int fd_in,loff_t *off_in,int fd_out,loff_t *off_out, +size_t len,unsigned int flags) +{ +ssize_t ret; + + ret =splice (fd_in, off_in, fd_out, off_out, len, flags); + +if (ret <0 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"splice(%d, %d, %zu) failed" , fd_in, fd_out, len); + } + +return ret; +} +int safe_dup (const char *file,const int lineno,int oldfd) {int rval;
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lib: Add SAFE_SPLICE() macro
Hi Andrea,
Quoted 2 lines · Andrea Cervesato
lib: Add
SAFE_SPLICE()macro
tee01, vmsplice01,af_alg08: UseSAFE_SPLICE()
---
Note:
Our agent completed the review of the patch.
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Replace raw splice() calls with manual error checking by SAFE_SPLICE() in tests where splice is not the subject of testing but just utility plumbing.
--- testcases/kernel/crypto/af_alg08.c | 10 ++-------- testcases/kernel/syscalls/tee/tee01.c | 9 ++------- testcases/kernel/syscalls/vmsplice/vmsplice01.c | 6 +----- 3 files changed, 5 insertions(+), 20 deletions(-)
testcases/kernel/crypto/af_alg08.c +2 -8
@@ -27,7 +27,6 @@#include "tst_test.h" #include "tst_af_alg.h" #include "lapi/socket.h" -#include "lapi/splice.h" #define TESTFILE "copy_fail"#define OVERWRITE_SIZE 4
@@ -92,13 +91,8 @@ static void try_corrupt(void)SAFE_PIPE (pipefd); -TEST (splice (file_fd, &off_in, pipefd[1 ],NULL ,OVERWRITE_SIZE ,0 )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"splice(file -> pipe)" ); - -TEST (splice (pipefd[0 ],NULL , reqfd,NULL ,OVERWRITE_SIZE ,0 )); -if (TST_RET <0 ) -tst_brk (TBROK |TTERRNO ,"splice(pipe -> AF_ALG)" ); +SAFE_SPLICE (file_fd, &off_in, pipefd[1 ],NULL ,OVERWRITE_SIZE ,0 ); +SAFE_SPLICE (pipefd[0 ],NULL , reqfd,NULL ,OVERWRITE_SIZE ,0 );/* Expected to fail (invalid ciphertext); triggers the scratch write */ TST_EXP_FAIL_SILENT (recv (reqfd, recvbuf,sizeof (recvbuf),0 ),EBADMSG );
testcases/kernel/syscalls/tee/tee01.c +2 -7
@@ -15,7 +15,6 @@#include "tst_test.h" #include "lapi/fcntl.h" #include "lapi/tee.h" -#include "lapi/splice.h" #define TEST_BLOCK_SIZE 1024
@@ -58,17 +57,13 @@ static void tee_test(void)SAFE_PIPE (pipe1);SAFE_PIPE (pipe2); - ret =splice (fd_in,NULL , pipe1[1 ],NULL ,TEST_BLOCK_SIZE ,0 ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"splice(fd_in, pipe1) failed" ); +SAFE_SPLICE (fd_in,NULL , pipe1[1 ],NULL ,TEST_BLOCK_SIZE ,0 ); ret =tee (pipe1[0 ], pipe2[1 ],TEST_BLOCK_SIZE ,SPLICE_F_NONBLOCK );if (ret <0 )tst_brk (TBROK |TERRNO ,"tee() failed" ); - ret =splice (pipe2[0 ],NULL , fd_out,NULL ,TEST_BLOCK_SIZE ,0 ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"splice(pipe2, fd_out) failed" ); +SAFE_SPLICE (pipe2[0 ],NULL , fd_out,NULL ,TEST_BLOCK_SIZE ,0 );SAFE_CLOSE (pipe2[0 ]);SAFE_CLOSE (pipe2[1 ]);
testcases/kernel/syscalls/vmsplice/vmsplice01.c +1 -5
@@ -15,7 +15,6 @@#include "tst_test.h" #include "lapi/fcntl.h" -#include "lapi/splice.h" #include "lapi/vmsplice.h" #define TEST_BLOCK_SIZE (1<<17)/* 128K */
@@ -50,7 +49,6 @@ static void vmsplice_test(void) {int pipes[2 ];long written; -int ret;int fd_out;struct iovec v;loff_t offset;
@@ -85,9 +83,7 @@ static void vmsplice_test(void) } } - ret =splice (pipes[0 ],NULL , fd_out, &offset, written,0 ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"splice() failed" ); +SAFE_SPLICE (pipes[0 ],NULL , fd_out, &offset, written,0 );//printf("offset = %lld\n", (long long)offset); }
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp