* [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN
@ 2026-05-07 9:46 Li Wang
2026-05-07 10:21 ` Cyril Hrubis
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Li Wang @ 2026-05-07 9:46 UTC (permalink / raw)
To: ltp
Commit 7276e7c154 ("ima_violations.sh: ima_mmap.c: Replace sleep with
checkpoints") called tst_reinit() inside the run() callback of a
struct tst_test based binary. This is incorrect because the test
framework has already initialized the IPC during setup, and calling
tst_reinit() re-maps the shared memory to the parent shell's IPC
region, corrupting the C binary's own test infrastructure.
Fix this by converting ima_mmap to a TST_NO_DEFAULT_MAIN helper
binary. In this mode there is no prior framework initialization, so
tst_reinit() correctly attaches to the parent shell test's shared
memory for checkpoint communication, following the same pattern used
by other LTP helper binaries (e.g. execvp01_child).
Fixes: 7276e7c154 ("ima_violations.sh: ima_mmap.c: Replace sleep with checkpoints")
Signed-off-by: Li Wang <li.wang@linux.dev>
---
.../security/integrity/ima/src/ima_mmap.c | 40 ++++++-------------
.../integrity/ima/tests/ima_violations.sh | 5 +--
2 files changed, 14 insertions(+), 31 deletions(-)
diff --git a/testcases/kernel/security/integrity/ima/src/ima_mmap.c b/testcases/kernel/security/integrity/ima/src/ima_mmap.c
index 09b22fd4f..1861147f8 100644
--- a/testcases/kernel/security/integrity/ima/src/ima_mmap.c
+++ b/testcases/kernel/security/integrity/ima/src/ima_mmap.c
@@ -7,46 +7,30 @@
* Mimi Zohar <zohar@us.ibm.com>
*/
+#define TST_NO_DEFAULT_MAIN
#include "tst_test.h"
#define MMAPSIZE 1024
-static char *filename;
-static void *file;
-static int fd;
-
-static void cleanup(void)
+int main(int argc, char *argv[])
{
- if (file)
- SAFE_MUNMAP(file, MMAPSIZE);
-
- if (fd > 0)
- SAFE_CLOSE(fd);
-}
+ int fd;
+ void *file;
-static void run(void)
-{
- if (!filename)
- tst_brk(TBROK, "missing filename (-f filename)");
+ tst_reinit();
- fd = SAFE_OPEN(filename, O_CREAT | O_RDWR, S_IRWXU);
+ if (argc != 2)
+ tst_brk(TBROK, "usage: ima_mmap <filename>");
+ fd = SAFE_OPEN(argv[1], O_CREAT | O_RDWR, S_IRWXU);
file = SAFE_MMAP(NULL, MMAPSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
SAFE_CLOSE(fd);
- tst_reinit();
- TST_CHECKPOINT_WAIT(0);
- /* keep running until ima_violations.sh open and close file */
+ /* Waiting until ima_violations.sh open and close file */
TST_CHECKPOINT_WAKE_AND_WAIT(0);
+ SAFE_MUNMAP(file, MMAPSIZE);
tst_res(TPASS, "test completed");
-}
-static struct tst_test test = {
- .options = (struct tst_option[]) {
- {"f:", &filename, "File to mmap"},
- {}
- },
- .test_all = run,
- .cleanup = cleanup,
-};
+ return 0;
+}
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh
index d7dcd077b..6271bba35 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh
@@ -170,11 +170,10 @@ test3()
echo 'testing testing' > $FILE
- ima_mmap -f $FILE &
+ ima_mmap $FILE &
pid=$!
- # wait for violations appear in logs
- TST_CHECKPOINT_WAKE_AND_WAIT 0
+ TST_CHECKPOINT_WAIT 0
open_file_read
close_file_read
--
2.54.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN
2026-05-07 9:46 [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN Li Wang
@ 2026-05-07 10:21 ` Cyril Hrubis
2026-05-07 11:34 ` Andrea Cervesato via ltp
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2026-05-07 10:21 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN
2026-05-07 9:46 [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN Li Wang
2026-05-07 10:21 ` Cyril Hrubis
@ 2026-05-07 11:34 ` Andrea Cervesato via ltp
2026-05-07 12:05 ` Li Wang
2026-05-07 11:58 ` [LTP] " linuxtestproject.agent
2026-05-12 16:45 ` [LTP] [PATCH] " Petr Vorel
3 siblings, 1 reply; 6+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-07 11:34 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Acked-by: Andrea Cervesato <andrea.cervesato@suse.com>
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN
2026-05-07 9:46 [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN Li Wang
2026-05-07 10:21 ` Cyril Hrubis
2026-05-07 11:34 ` Andrea Cervesato via ltp
@ 2026-05-07 11:58 ` linuxtestproject.agent
2026-05-12 16:45 ` [LTP] [PATCH] " Petr Vorel
3 siblings, 0 replies; 6+ messages in thread
From: linuxtestproject.agent @ 2026-05-07 11:58 UTC (permalink / raw)
To: Li Wang; +Cc: ltp, LTP AI Reviewer
Hi Li,
On 2026-05-07, Li Wang wrote:
> ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN
> +#define TST_NO_DEFAULT_MAIN
> #include "tst_test.h"
> + tst_reinit();
> + if (argc != 2)
> + tst_brk(TBROK, "usage: ima_mmap <filename>");
> +
> + fd = SAFE_OPEN(argv[1], O_CREAT | O_RDWR, S_IRWXU);
> file = SAFE_MMAP(NULL, MMAPSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> SAFE_CLOSE(fd);
> + /* Waiting until ima_violations.sh open and close file */
> TST_CHECKPOINT_WAKE_AND_WAIT(0);
> + SAFE_MUNMAP(file, MMAPSIZE);
> tst_res(TPASS, "test completed");
Correct pattern. Moving tst_reinit() before any framework use and
switching to TST_NO_DEFAULT_MAIN properly fixes the IPC corruption.
The checkpoint handshake inversion between the helper and the shell
script is consistent.
Reviewed-by: LTP AI Reviewer <ltp-ai@noreply.github.com>
---
Note:
Our agent completed the review of the patch. The full review can be
found at: (not available)
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN
2026-05-07 9:46 [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN Li Wang
` (2 preceding siblings ...)
2026-05-07 11:58 ` [LTP] " linuxtestproject.agent
@ 2026-05-12 16:45 ` Petr Vorel
3 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-05-12 16:45 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi Li, all,
> Commit 7276e7c154 ("ima_violations.sh: ima_mmap.c: Replace sleep with
> checkpoints") called tst_reinit() inside the run() callback of a
> struct tst_test based binary. This is incorrect because the test
> framework has already initialized the IPC during setup, and calling
> tst_reinit() re-maps the shared memory to the parent shell's IPC
> region, corrupting the C binary's own test infrastructure.
> Fix this by converting ima_mmap to a TST_NO_DEFAULT_MAIN helper
> binary. In this mode there is no prior framework initialization, so
> tst_reinit() correctly attaches to the parent shell test's shared
> memory for checkpoint communication, following the same pattern used
> by other LTP helper binaries (e.g. execvp01_child).
> Fixes: 7276e7c154 ("ima_violations.sh: ima_mmap.c: Replace sleep with checkpoints")
Li, thanks for fixing the problem I introduced. It's nice to get from vacation
and see the work has been done :).
And using TST_NO_DEFAULT_MAIN is indeed the best way for these simple helpers.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-05-12 16:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07 9:46 [LTP] [PATCH] ima: rewrite ima_mmap auxiliary with TST_NO_DEFAULT_MAIN Li Wang
2026-05-07 10:21 ` Cyril Hrubis
2026-05-07 11:34 ` Andrea Cervesato via ltp
2026-05-07 12:05 ` Li Wang
2026-05-07 11:58 ` [LTP] " linuxtestproject.agent
2026-05-12 16:45 ` [LTP] [PATCH] " Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.