splice10.c: New splice tests involving memfd secret
PATCH 1/1 splice10.c: New splice tests involving memfd secret
Linux commit cbe4134ea4bc ("fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass") prevents any access to secret memory pages from other kernel subsystems.
Splice operations involving memfd secret are checked within this case.
Discussed-on: https://lists.linux.it/pipermail/ltp/2025-July/044351.html
Reference: cbe4134ea4bc ("fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass")
--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice10.c | 48 +++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice10.c
runtest/syscalls +1 -0
@@ -1585,6 +1585,7 @@ splice06 splice06 splice07 splice07 splice08 splice08 splice09 splice09 +splice10 splice10 tee01 tee01 tee02 tee02
testcases/kernel/syscalls/splice/.gitignore +1 -0
@@ -7,3 +7,4 @@ /splice07 /splice08 /splice09 +/splice10
testcases/kernel/syscalls/splice/splice10.c new file +48 -0
48 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 5 lines · Wei Gao via ltp
Linux commit
cbe4134ea4bc("fs: exportanon_inode_make_secure_inode()and fix secretmem LSM bypass") prevents any access to secret memory pages from other kernel subsystems.Splice operations involving memfd secret are checked within this case.
"Test if splice syscall prevents any access to secret memory pages from other kernel subsystems."
The linux commit is given via "Reference:" anyway.
Quoted 49 lines
Discussed-on: https://lists.linux.it/pipermail/ltp/2025-July/044351.html
Reference:cbe4134ea4bc("fs: exportanon_inode_make_secure_inode()and fix secretmem LSM bypass")Signed-off-by Wei Gao <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice10.c | 48 +++++++++++++++++++++ 3 files changed, 50 insertions(+)create mode 100644
testcases/kernel/syscalls/splice/splice10.cruntest/syscalls +1
-0@@ -1585,6 +1585,7 @@ splice06 splice06 splice07 splice07 splice08 splice08 splice09 splice09 +splice10 splice10 tee01 tee01 tee02 tee02testcases/kernel/syscalls/splice/.gitignore +1
-0@@ -7,3 +7,4 @@ /splice07 /splice08 /splice09 +/splice10testcases/kernel/syscalls/splice/splice10.c new file +11
-0@@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2025 Wei Gao <[email protected]> +*/ + +/*\ +* Linux commit cbe4134ea4bc ("fs: export anon_inode_make_secure_inode() and fix +* secretmem LSM bypass") prevents any access to secret memory pages from other +* kernel subsystems. +* This case check splice operations involving memfd secret should return EACCES. +*/
testcases/kernel/syscalls/splice/splice10.c line 21
Quoted 10 lines
testcases/kernel/syscalls/splice/splice10.c new file +10
-0+ +#define _GNU_SOURCE +#include "tst_test.h" +#include "lapi/syscalls.h" + +static void verify_splice (void ) +{ +char buf[1024 ]; +int fd; +int pipefd[2 ];
Since we are testing only a failure, it makes sense to create input arguments via tst_test.bufs and initialize them in the setup().
testcases/kernel/syscalls/splice/splice10.c line 25
Quoted 4 lines
testcases/kernel/syscalls/splice/splice10.c new file +4
-0+ +memset (buf,0xff ,sizeof (buf)); + +if (!tst_selinux_enforcing ())
Maybe it's better to use tst_selinux_enabled() after merging: https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Quoted 7 lines
testcases/kernel/syscalls/splice/splice10.c new file +7
-0+tst_brk (TCONF ,"SELinux not running" ); + + fd =syscall (__NR_memfd_secret,0 ); +if (fd <0 ) { +tst_brk (TCONF |TERRNO , +"Skipping __NR_memfd_secret check" ); + }
testcases/kernel/syscalls/splice/splice10.c line 42
Quoted 10 lines
testcases/kernel/syscalls/splice/splice10.c new file +10
-0+ +SAFE_PIPE (pipefd); +SAFE_WRITE (1 , pipefd[1 ], buf,sizeof (buf)); + +TST_EXP_FAIL (splice (pipefd[0 ],NULL , fd,NULL ,sizeof (buf),0 ),EACCES ); +TST_EXP_FAIL (splice (fd,NULL , pipefd[1 ],NULL ,sizeof (buf),0 ),EACCES ); + +SAFE_CLOSE (pipefd[0 ]); +SAFE_CLOSE (pipefd[1 ]); +SAFE_CLOSE (fd);
And this part will go in the cleanup().
testcases/kernel/syscalls/splice/splice10.c line 47
Quoted 5 lines
testcases/kernel/syscalls/splice/splice10.c new file +5
-0+} + +static struct tst_test test = { + .test_all = verify_splice, + .min_kver ="6.16" ,
We will need to add the reference to commit cbe4134ea4bc in here.
testcases/kernel/syscalls/splice/splice10.c line 48
Quoted 1 line
testcases/kernel/syscalls/splice/splice10.c new file +1
-0+};
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 8 lines · Andrea Cervesato
Hi!
testcases/kernel/syscalls/splice/splice10.c line 21
Quoted 4 lines
testcases/kernel/syscalls/splice/splice10.c new file +4
-0+{ +char buf[1024 ]; +int fd; +int pipefd[2 ];Since we are testing only a failure, it makes sense to create input arguments via tst_test.bufs and initialize them in the
setup().
Quoted 5 lines
testcases/kernel/syscalls/splice/splice10.c line 25
Quoted 4 lines
testcases/kernel/syscalls/splice/splice10.c new file +4
-0+ +memset (buf,0xff ,sizeof (buf)); + +if (!tst_selinux_enforcing ())Maybe it's better to use
tst_selinux_enabled()after merging: https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
This case need check selinux runing status instead of enable or not. So i will keep this unchanged for next patch, correct me if any misunderstanding, thanks :)
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 splice10.c: New splice tests involving memfd secret
In reply to Wei Gao via ltpLinux commit cbe4134ea4bc ("fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass") prevents any access to secret memory pages from other kernel subsystems.
Splice operations involving memfd secret are checked within this case.
Discussed-on: https://lists.linux.it/pipermail/ltp/2025-July/044351.html
Reference: cbe4134ea4bc ("fs: export anon_inode_make_secure_inode() and fix secretmem LSM bypass")
--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice10.c | 72 +++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice10.c
runtest/syscalls +1 -0
@@ -1585,6 +1585,7 @@ splice06 splice06 splice07 splice07 splice08 splice08 splice09 splice09 +splice10 splice10 tee01 tee01 tee02 tee02
testcases/kernel/syscalls/splice/.gitignore +1 -0
@@ -7,3 +7,4 @@ /splice07 /splice08 /splice09 +/splice10
testcases/kernel/syscalls/splice/splice10.c new file +72 -0
72 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
LGTM
Signature · 7 lines
Andrea Cervesato SUSE QE Automation Engineer Linux [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp