public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] hugeshmctl02: Skipped EFAULT tests for libc variant
@ 2023-06-15  9:39 Dylan Jhong
  2023-06-26  2:36 ` Dylan Dai-Rong Jhong(鍾岱融)
  2023-06-26  6:57 ` Li Wang
  0 siblings, 2 replies; 12+ messages in thread
From: Dylan Jhong @ 2023-06-15  9:39 UTC (permalink / raw)
  To: ltp; +Cc: minachou, tim609, x5710999x

When testing hugeshmctl02 under the 32bit architecture, a segmentation fault
will occur. This patch will skip EFAULT tests for libc variant.

Hugeshmctl02 will intentionally pass "(struct shmid_ds *)-1" to shmctl(), but
glibc will perform an additional conversion function when the architecture is
32bit, which will try to copy all items in (struct shmid_ds *) to another
structure[*1]. In the process of copying, it is necessary to dereference
"(struct shmid_ds *)-1", resulting in segmentation fault.

The LTP also has similar problems before, this patch is reference from the
shmctl03 patch[*2].

[*1]: https://github.com/bminor/glibc/blob/master/sysdeps/unix/sysv/linux/shmctl.c#L37
[*2]: https://github.com/linux-test-project/ltp/commit/a5a80aa8485a7cb017f96aba8d7b5ea79f1ba4d4

Signed-off-by: Dylan Jhong <dylan@andestech.com>
---
 .../mem/hugetlb/hugeshmctl/hugeshmctl02.c     | 35 ++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
index 0bc9ffd74..e9c2e9fc8 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
@@ -27,6 +27,7 @@
 #include <pwd.h>
 #include <limits.h>
 #include "hugetlb.h"
+#include "lapi/syscalls.h"
 
 static size_t shm_size;
 static int shm_id_1 = -1;
@@ -50,9 +51,37 @@ struct tcase {
 	{&shm_id_2, -1, &buf, EINVAL},
 };
 
+static int libc_shmctl(int shmid, int cmd, void *buf)
+{
+	return shmctl(shmid, cmd, buf);
+}
+
+static int sys_shmctl(int shmid, int cmd, void *buf)
+{
+	return tst_syscall(__NR_shmctl, shmid, cmd, buf);
+}
+
+static struct test_variants
+{
+	int (*shmctl)(int shmid, int cmd, void *buf);
+	char *desc;
+} variants[] = {
+	{ .shmctl = libc_shmctl, .desc = "libc shmctl()"},
+#if (__NR_shmctl != __LTP__NR_INVALID_SYSCALL)
+	{ .shmctl = sys_shmctl,  .desc = "__NR_shmctl syscall"},
+#endif
+};
+
 static void test_hugeshmctl(unsigned int i)
 {
-	TEST(shmctl(*(tcases[i].shmid), tcases[i].cmd, tcases[i].sbuf));
+	struct test_variants *tv = &variants[tst_variant];
+
+	if (tcases[i].error == EFAULT && tv->shmctl == libc_shmctl) {
+		tst_res(TCONF, "EFAULT is skipped for libc variant");
+		return;
+	}
+
+	TEST(tv->shmctl(*(tcases[i].shmid), tcases[i].cmd, tcases[i].sbuf));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "shmctl succeeded unexpectedly");
 		return;
@@ -70,8 +99,11 @@ static void test_hugeshmctl(unsigned int i)
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
 	long hpage_size;
 
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+
 	if (tst_hugepages == 0)
 		tst_brk(TCONF, "No enough hugepages for testing.");
 
@@ -101,6 +133,7 @@ static void cleanup(void)
 
 static struct tst_test test = {
 	.test = test_hugeshmctl,
+	.test_variants = ARRAY_SIZE(variants),
 	.tcnt = ARRAY_SIZE(tcases),
 	.needs_root = 1,
 	.needs_tmpdir = 1,
-- 
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-07-11 22:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-15  9:39 [LTP] [PATCH] hugeshmctl02: Skipped EFAULT tests for libc variant Dylan Jhong
2023-06-26  2:36 ` Dylan Dai-Rong Jhong(鍾岱融)
2023-06-26  6:57 ` Li Wang
2023-06-26  9:14   ` Dylan Dai-Rong Jhong(鍾岱融)
2023-06-26  9:23   ` Cyril Hrubis
2023-06-27  1:26     ` Li Wang
2023-06-27 13:50       ` Petr Vorel
2023-06-27 15:06         ` Cyril Hrubis
2023-06-27 18:26           ` Petr Vorel
2023-07-06  3:13             ` Dylan Dai-Rong Jhong(鍾岱融)
2023-07-11 11:24               ` Dylan Dai-Rong Jhong(鍾岱融)
2023-07-11 22:24                 ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox