Skip to contentSkip to conversation

userns/userns08.c: Enable userns in max_user_namespaces file

PATCH New Yang Xu 2 participants 5 messages Aug 5, 2021 – Aug 31, 2021

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

PATCH 1/1 userns/userns08.c: Enable userns in max_user_namespaces file

On old distros ie centos7, the default value of max_user_namespaces is set to 0. Enable it by increasing this value.

---
 testcases/kernel/containers/userns/userns08.c | 9 +++++++++
 1 file changed, 9 insertions(+)
testcases/kernel/containers/userns/userns08.c +9 -0
index aedfc6c4e..0910ea7d4 100644
@@ -120,6 +120,11 @@ static void setup(void)
 
 	SAFE_WRITE(fd, 1, "\n", 1);
 	SAFE_CLOSE(fd);
+
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
 }
 
 static struct tst_test test = {
@@ -133,6 +138,10 @@ static struct tst_test test = {
 		"CONFIG_USER_NS",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d2f007dbe7e4"},
 		{"CVE", "CVE-2018-18955"},
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/1 userns/userns08.c: Enable userns in max_user_namespaces file

Hi!

My machine's time is wrong, so I sent this patch today but the email's date is 8.5(It may lose your attention).

Best Regards
Yang Xu

Quoted 35 lines

On old distros ie centos7, the default value of max_user_namespaces is set to 0. Enable it by increasing this value.

---
  testcases/kernel/containers/userns/userns08.c | 9 +++++++++
  1 file changed, 9 insertions(+)
testcases/kernel/containers/userns/userns08.c +9 -0
index aedfc6c4e..0910ea7d4 100644
@@ -120,6 +120,11 @@ static void setup(void)
 
  	SAFE_WRITE(fd, 1, "\n", 1);
  	SAFE_CLOSE(fd);
+
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
  }
 
  static struct tst_test test = {
@@ -133,6 +138,10 @@ static struct tst_test test = {
  		"CONFIG_USER_NS",
  		NULL
  	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
  	.tags = (const struct tst_tag[]) {
  		{"linux-git", "d2f007dbe7e4"},
  		{"CVE", "CVE-2018-18955"},
author
#2 lore raw

PATCH v2 1/1 testcases: Enable userns in max_user_namespaces file

In reply to Yang Xu

On old distros ie centos7, the default value of max_user_namespaces is set to 0. Enable it by increasing this value.

---
 testcases/cve/icmp_rate_limit01.c                   | 9 +++++++++
 testcases/kernel/containers/userns/userns08.c       | 9 +++++++++
 testcases/kernel/syscalls/bind/bind06.c             | 9 +++++++++
 testcases/kernel/syscalls/sendto/sendto03.c         | 9 +++++++++
 testcases/kernel/syscalls/setsockopt/setsockopt05.c | 9 +++++++++
 testcases/kernel/syscalls/setsockopt/setsockopt06.c | 9 +++++++++
 testcases/kernel/syscalls/setsockopt/setsockopt07.c | 9 +++++++++
 testcases/kernel/syscalls/setsockopt/setsockopt08.c | 9 +++++++++
 8 files changed, 72 insertions(+)
testcases/cve/icmp_rate_limit01.c +9 -0
index f24ea5bf9..f5ec77d6f 100644
@@ -58,6 +58,11 @@ static void setup(void)
 	for (i = 0; i < SRCADDR_COUNT; i++)
 		fds[i] = -1;
 
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -265,6 +270,10 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "b38e7819cae9"},
 		{"CVE", "2020-25705"},
testcases/kernel/containers/userns/userns08.c +9 -0
index aedfc6c4e..429fcf235 100644
@@ -120,6 +120,11 @@ static void setup(void)
 
 	SAFE_WRITE(fd, 1, "\n", 1);
 	SAFE_CLOSE(fd);
+
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
 }
 
 static struct tst_test test = {
@@ -133,6 +138,10 @@ static struct tst_test test = {
 		"CONFIG_USER_NS",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d2f007dbe7e4"},
 		{"CVE", "CVE-2018-18955"},
testcases/kernel/syscalls/bind/bind06.c +9 -0
index 017e0fc89..390af76a1 100644
@@ -34,6 +34,11 @@ static void setup(void)
 	int real_gid = getgid();
 	struct ifreq ifr;
 
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -107,6 +112,10 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "15fe076edea7"},
 		{"CVE", "2018-18559"},
testcases/kernel/syscalls/sendto/sendto03.c +9 -0
index 3ecb574a1..700ad24ca 100644
@@ -43,6 +43,11 @@ static void setup(void)
 	int real_gid = getgid();
 	struct ifreq ifr;
 
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -215,6 +220,10 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "bcc5364bdcfe"},
 		{"linux-git", "acf69c946233"},
testcases/kernel/syscalls/setsockopt/setsockopt05.c +9 -0
index 0b7ff39d2..9adb2f0d2 100644
@@ -40,6 +40,11 @@ static void setup(void)
 	struct ifreq ifr;
 	socklen_t addrlen = sizeof(addr);
 
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -99,6 +104,10 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "85f1bd9a7b5a"},
 		{"CVE", "2017-1000112"},
testcases/kernel/syscalls/setsockopt/setsockopt06.c +9 -0
index 33284e5a6..9ea5985ba 100644
@@ -35,6 +35,11 @@ static void setup(void)
 	int real_uid = getuid();
 	int real_gid = getgid();
 
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -125,6 +130,10 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "84ac7260236a"},
 		{"CVE", "2016-8655"},
testcases/kernel/syscalls/setsockopt/setsockopt07.c +9 -0
index b00286989..051b1bb70 100644
@@ -38,6 +38,11 @@ static void setup(void)
 	int real_uid = getuid();
 	int real_gid = getgid();
 
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -137,6 +142,10 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "c27927e372f0"},
 		{"CVE", "2017-1000111"},
testcases/kernel/syscalls/setsockopt/setsockopt08.c +9 -0
index a7c0ace20..aef9bdcb6 100644
@@ -95,6 +95,11 @@ void setup(void)
 			"The vulnerability was only present in 32-bit compat mode");
 	}
 
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */
+	SAFE_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 }
@@ -156,6 +161,10 @@ static struct tst_test test = {
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const char * const[]) {
+		"?/proc/sys/user/max_user_namespaces",
+		NULL,
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "b29c457a6511"},
 		{"CVE", "2021-22555"},
Signature · 1 line
2.23.0
#3 lore raw

PATCH 1/1 userns/userns08.c: Enable userns in max_user_namespaces file

In reply to Yang Xu

Hello Yang,

Quoted 4 lines · Yang Xu

On old distros ie centos7, the default value of max_user_namespaces is set to 0. Enable it by increasing this value.

Looks good, except for very minor point below.

Quoted 9 lines
---
 testcases/kernel/containers/userns/userns08.c | 9 +++++++++
 1 file changed, 9 insertions(+)
testcases/kernel/containers/userns/userns08.c +0 -0
index aedfc6c4e..0910ea7d4 100644

testcases/kernel/containers/userns/userns08.c static void setup(void) · line 126

Quoted 7 lines
testcases/kernel/containers/userns/userns08.c +4 -0
@@ -120,6 +120,11 @@ static void setup(void)
 
 	SAFE_WRITE(fd, 1, "\n", 1);
 	SAFE_CLOSE(fd);
+
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */

We don't need inline comments like this. In this case the commit message and git-blame is fine. Other times the style guide requests it goes in the comment at the top.

Signature · 2 lines
Thank you,
Richard.
#4 lore raw

PATCH 1/1 userns/userns08.c: Enable userns in max_user_namespaces file

Hi Richard

Quoted 23 lines

Hello Yang,

Quoted 4 lines · Yang Xu

On old distros ie centos7, the default value of max_user_namespaces is set to 0. Enable it by increasing this value.

Looks good, except for very minor point below.

Quoted 10 lines
---
  testcases/kernel/containers/userns/userns08.c | 9 +++++++++
  1 file changed, 9 insertions(+)
testcases/kernel/containers/userns/userns08.c +0 -0
index aedfc6c4e..0910ea7d4 100644
@@ -120,6 +120,11 @@ static void setup(void)
 
Quoted 10 lines

testcases/kernel/containers/userns/userns08.c static void setup(void) · line 126

Quoted 6 lines
testcases/kernel/containers/userns/userns08.c +4 -0
  	SAFE_WRITE(fd, 1, "\n", 1);
  	SAFE_CLOSE(fd);
+
+	/* The default value of max_user_namespaces is set to 0 on some distros,
+	 * We need to change the default value to call clone().
+	 */

We don't need inline comments like this. In this case the commit message and git-blame is fine. Other times the style guide requests it goes in the comment at the top.

Thanks for your review. I have pushed the v2 patch with your reviewed-by(increase this value in more userns cases.)

Best Regards
Yang Xu

Quoted 1 line