[CRIU] [PATCH] test/ipc_namespace: set random values less that IPCMNI for *mni sysctls
Andrei Vagin
avagin at gmail.com
Mon Oct 15 19:22:33 MSK 2018
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 at gmail.com>
---
test/zdtm/static/ipc_namespace.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
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);
--
2.14.4
More information about the CRIU
mailing list