Blame SOURCES/0160-tests-disable-shmctl-IPC_STAT-test-with-a-bogus-addr.patch

242c1e
From 8c1a84778bb05a3becc493698b215681bf7249b3 Mon Sep 17 00:00:00 2001
242c1e
From: "Dmitry V. Levin" <ldv@altlinux.org>
242c1e
Date: Sat, 19 Sep 2020 08:00:00 +0000
242c1e
Subject: [PATCH 160/162] tests: disable shmctl IPC_STAT test with a bogus
242c1e
 address on glibc >= 2.32
242c1e
242c1e
Starting with commit glibc-2.32~80, on every 32-bit architecture where
242c1e
32-bit time_t support is enabled, glibc tries to retrieve the data
242c1e
provided in the third argument of shmctl call.  This results to
242c1e
segfaults inside glibc when shmctl is called with a bogus address.
242c1e
242c1e
* tests/ipc_shm.c [GLIBC_PREREQ_GE(2, 32) && __TIMESIZE != 64]
242c1e
(TEST_SHMCTL_BOGUS_ADDR): Define to 0.
242c1e
(main): Conditionalize on TEST_SHMCTL_BOGUS_ADDR the shmctl IPC_STAT
242c1e
invocation with a bogus address.
242c1e
---
242c1e
 tests/ipc_shm.c | 19 +++++++++++++++++++
242c1e
 1 file changed, 19 insertions(+)
242c1e
242c1e
diff --git a/tests/ipc_shm.c b/tests/ipc_shm.c
242c1e
index 5cd414e..695fd94 100644
242c1e
--- a/tests/ipc_shm.c
242c1e
+++ b/tests/ipc_shm.c
242c1e
@@ -73,6 +73,21 @@
242c1e
 # define str_bogus_cmd "0xdefaced2 /\\* SHM_\\?\\?\\? \\*/"
242c1e
 #endif
242c1e
 
242c1e
+#undef TEST_SHMCTL_BOGUS_ADDR
242c1e
+
242c1e
+/*
242c1e
+ * Starting with commit glibc-2.32~80, on every 32-bit architecture
242c1e
+ * where 32-bit time_t support is enabled, glibc tries to retrieve
242c1e
+ * the data provided in the third argument of shmctl call.
242c1e
+ */
242c1e
+#if GLIBC_PREREQ_GE(2, 32) && defined __TIMESIZE && __TIMESIZE != 64
242c1e
+# define TEST_SHMCTL_BOGUS_ADDR 0
242c1e
+#endif
242c1e
+
242c1e
+#ifndef TEST_SHMCTL_BOGUS_ADDR
242c1e
+# define TEST_SHMCTL_BOGUS_ADDR 1
242c1e
+#endif
242c1e
+
242c1e
 static int id = -1;
242c1e
 
242c1e
 static void
242c1e
@@ -92,7 +107,9 @@ main(void)
242c1e
 	static const key_t bogus_key = (key_t) 0xeca86420fdb97531ULL;
242c1e
 	static const int bogus_id = 0xdefaced1;
242c1e
 	static const int bogus_cmd = 0xdefaced2;
242c1e
+#if TEST_SHMCTL_BOGUS_ADDR
242c1e
 	static void * const bogus_addr = (void *) -1L;
242c1e
+#endif
242c1e
 	static const size_t bogus_size =
242c1e
 	/*
242c1e
 	 * musl sets size to SIZE_MAX if size argument is greater than
242c1e
@@ -160,10 +177,12 @@ main(void)
242c1e
 	printf("shmctl\\(%d, (%s\\|)?%s, NULL\\) = %s\n",
242c1e
 	       bogus_id, str_ipc_64, str_bogus_cmd, sprintrc_grep(rc));
242c1e
 
242c1e
+#if TEST_SHMCTL_BOGUS_ADDR
242c1e
 	rc = shmctl(bogus_id, IPC_STAT, bogus_addr);
242c1e
 	printf("shmctl\\(%d, (%s\\|)?%s, %p\\) = %s\n",
242c1e
 	       bogus_id, str_ipc_64, str_ipc_stat, bogus_addr,
242c1e
 	       sprintrc_grep(rc));
242c1e
+#endif
242c1e
 
242c1e
 	if (shmctl(id, IPC_STAT, &ds))
242c1e
 		perror_msg_and_skip("shmctl IPC_STAT");
242c1e
diff --git a/tests-m32/ipc_shm.c b/tests-m32/ipc_shm.c
242c1e
index 5cd414e..695fd94 100644
242c1e
--- a/tests-m32/ipc_shm.c
242c1e
+++ b/tests-m32/ipc_shm.c
242c1e
@@ -73,6 +73,21 @@
242c1e
 # define str_bogus_cmd "0xdefaced2 /\\* SHM_\\?\\?\\? \\*/"
242c1e
 #endif
242c1e
 
242c1e
+#undef TEST_SHMCTL_BOGUS_ADDR
242c1e
+
242c1e
+/*
242c1e
+ * Starting with commit glibc-2.32~80, on every 32-bit architecture
242c1e
+ * where 32-bit time_t support is enabled, glibc tries to retrieve
242c1e
+ * the data provided in the third argument of shmctl call.
242c1e
+ */
242c1e
+#if GLIBC_PREREQ_GE(2, 32) && defined __TIMESIZE && __TIMESIZE != 64
242c1e
+# define TEST_SHMCTL_BOGUS_ADDR 0
242c1e
+#endif
242c1e
+
242c1e
+#ifndef TEST_SHMCTL_BOGUS_ADDR
242c1e
+# define TEST_SHMCTL_BOGUS_ADDR 1
242c1e
+#endif
242c1e
+
242c1e
 static int id = -1;
242c1e
 
242c1e
 static void
242c1e
@@ -92,7 +107,9 @@ main(void)
242c1e
 	static const key_t bogus_key = (key_t) 0xeca86420fdb97531ULL;
242c1e
 	static const int bogus_id = 0xdefaced1;
242c1e
 	static const int bogus_cmd = 0xdefaced2;
242c1e
+#if TEST_SHMCTL_BOGUS_ADDR
242c1e
 	static void * const bogus_addr = (void *) -1L;
242c1e
+#endif
242c1e
 	static const size_t bogus_size =
242c1e
 	/*
242c1e
 	 * musl sets size to SIZE_MAX if size argument is greater than
242c1e
@@ -160,10 +177,12 @@ main(void)
242c1e
 	printf("shmctl\\(%d, (%s\\|)?%s, NULL\\) = %s\n",
242c1e
 	       bogus_id, str_ipc_64, str_bogus_cmd, sprintrc_grep(rc));
242c1e
 
242c1e
+#if TEST_SHMCTL_BOGUS_ADDR
242c1e
 	rc = shmctl(bogus_id, IPC_STAT, bogus_addr);
242c1e
 	printf("shmctl\\(%d, (%s\\|)?%s, %p\\) = %s\n",
242c1e
 	       bogus_id, str_ipc_64, str_ipc_stat, bogus_addr,
242c1e
 	       sprintrc_grep(rc));
242c1e
+#endif
242c1e
 
242c1e
 	if (shmctl(id, IPC_STAT, &ds))
242c1e
 		perror_msg_and_skip("shmctl IPC_STAT");
242c1e
diff --git a/tests-mx32/ipc_shm.c b/tests-mx32/ipc_shm.c
242c1e
index 5cd414e..695fd94 100644
242c1e
--- a/tests-mx32/ipc_shm.c
242c1e
+++ b/tests-mx32/ipc_shm.c
242c1e
@@ -73,6 +73,21 @@
242c1e
 # define str_bogus_cmd "0xdefaced2 /\\* SHM_\\?\\?\\? \\*/"
242c1e
 #endif
242c1e
 
242c1e
+#undef TEST_SHMCTL_BOGUS_ADDR
242c1e
+
242c1e
+/*
242c1e
+ * Starting with commit glibc-2.32~80, on every 32-bit architecture
242c1e
+ * where 32-bit time_t support is enabled, glibc tries to retrieve
242c1e
+ * the data provided in the third argument of shmctl call.
242c1e
+ */
242c1e
+#if GLIBC_PREREQ_GE(2, 32) && defined __TIMESIZE && __TIMESIZE != 64
242c1e
+# define TEST_SHMCTL_BOGUS_ADDR 0
242c1e
+#endif
242c1e
+
242c1e
+#ifndef TEST_SHMCTL_BOGUS_ADDR
242c1e
+# define TEST_SHMCTL_BOGUS_ADDR 1
242c1e
+#endif
242c1e
+
242c1e
 static int id = -1;
242c1e
 
242c1e
 static void
242c1e
@@ -92,7 +107,9 @@ main(void)
242c1e
 	static const key_t bogus_key = (key_t) 0xeca86420fdb97531ULL;
242c1e
 	static const int bogus_id = 0xdefaced1;
242c1e
 	static const int bogus_cmd = 0xdefaced2;
242c1e
+#if TEST_SHMCTL_BOGUS_ADDR
242c1e
 	static void * const bogus_addr = (void *) -1L;
242c1e
+#endif
242c1e
 	static const size_t bogus_size =
242c1e
 	/*
242c1e
 	 * musl sets size to SIZE_MAX if size argument is greater than
242c1e
@@ -160,10 +177,12 @@ main(void)
242c1e
 	printf("shmctl\\(%d, (%s\\|)?%s, NULL\\) = %s\n",
242c1e
 	       bogus_id, str_ipc_64, str_bogus_cmd, sprintrc_grep(rc));
242c1e
 
242c1e
+#if TEST_SHMCTL_BOGUS_ADDR
242c1e
 	rc = shmctl(bogus_id, IPC_STAT, bogus_addr);
242c1e
 	printf("shmctl\\(%d, (%s\\|)?%s, %p\\) = %s\n",
242c1e
 	       bogus_id, str_ipc_64, str_ipc_stat, bogus_addr,
242c1e
 	       sprintrc_grep(rc));
242c1e
+#endif
242c1e
 
242c1e
 	if (shmctl(id, IPC_STAT, &ds))
242c1e
 		perror_msg_and_skip("shmctl IPC_STAT");
242c1e
-- 
242c1e
2.1.4
242c1e