test/ipc_namespace: set random values less that IPCMNI for *mni sysctls

Submitted by Andrei Vagin on Oct. 15, 2018, 4:22 p.m.

Details

Message ID 20181015162233.3649-1-avagin@gmail.com
State Accepted
Series "test/ipc_namespace: set random values less that IPCMNI for *mni sysctls"
Headers show

Commit Message

Andrei Vagin Oct. 15, 2018, 4:22 p.m.
There are a few patches in linux-next, which added this check:
    ipc: IPCMNI limit check for semmni
    ipc: IPCMNI limit check for msgmni and shmmni

Signed-off-by: Andrei Vagin <avagin@gmail.com>
---
 test/zdtm/static/ipc_namespace.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/ipc_namespace.c b/test/zdtm/static/ipc_namespace.c
index a7f0fd103..d01d654e5 100644
--- a/test/zdtm/static/ipc_namespace.c
+++ b/test/zdtm/static/ipc_namespace.c
@@ -7,6 +7,7 @@ 
 #include <linux/sem.h>
 #include <linux/shm.h>
 #include <fcntl.h>
+#include <limits.h>
 
 #include "zdtmtst.h"
 
@@ -237,6 +238,8 @@  static int rand_ipc_sysctl(char *name, unsigned int val)
 	return 0;
 }
 
+#define MAX_MNI (1<<15)
+
 static int rand_ipc_sem(void)
 {
 	int fd;
@@ -249,8 +252,8 @@  static int rand_ipc_sem(void)
 		pr_perror("Can't open %s", name);
 		return fd;
 	}
-	sprintf(buf, "%d %d %d %d\n", (unsigned)lrand48(), (unsigned)lrand48(),
-				      (unsigned)lrand48(), (unsigned)lrand48());
+	sprintf(buf, "%d %d %d %d\n", (unsigned) lrand48(), (unsigned) lrand48(),
+				      (unsigned) lrand48(), (unsigned) lrand48() % MAX_MNI);
 	ret = write(fd, buf, 128);
 	if (ret < 0) {
 		pr_perror("Can't write %s: %d", name, errno);
@@ -260,8 +263,6 @@  static int rand_ipc_sem(void)
 	return 0;
 }
 
-#define INT_MAX ((int)(~0U>>1))
-
 static int rand_ipc_ns(void)
 {
 	int ret;
@@ -272,7 +273,7 @@  static int rand_ipc_ns(void)
 	if (!ret)
 		ret = rand_ipc_sysctl("/proc/sys/kernel/msgmnb", (unsigned)lrand48());
 	if (!ret)
-		ret = rand_ipc_sysctl("/proc/sys/kernel/msgmni", (unsigned)lrand48());
+		ret = rand_ipc_sysctl("/proc/sys/kernel/msgmni", (unsigned)lrand48() % MAX_MNI);
 	if (!ret)
 		ret = rand_ipc_sysctl("/proc/sys/kernel/auto_msgmni", 0);
 	if (!ret && (unsigned)lrand48() % 2)
@@ -286,7 +287,7 @@  static int rand_ipc_ns(void)
 	if (!ret)
 		ret = rand_ipc_sysctl("/proc/sys/kernel/shmall", (unsigned)lrand48());
 	if (!ret)
-		ret = rand_ipc_sysctl("/proc/sys/kernel/shmmni", (unsigned)lrand48());
+		ret = rand_ipc_sysctl("/proc/sys/kernel/shmmni", (unsigned)lrand48() % MAX_MNI);
 	if (!ret)
 		ret = rand_ipc_sysctl("/proc/sys/kernel/shm_rmid_forced", (unsigned)lrand48() & 1);