Skip to contentSkip to conversation

ns: Move MAX_PID_NS_LEVEL to ns_common.h, reuse it

PATCH In review Petr Vorel 3 participants 5 messages Mar 25, 2022

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 ns: Move MAX_PID_NS_LEVEL to ns_common.h, reuse it

Move MAX_PID_NS_LEVEL to ns_common.h and reuse it in check in user_namespace.c.

---
Hi Christian, all,

I don't see putting MAX_PID_NS_LEVEL into ns_common.h as an elegant solution but IMHO better than use a hardwired number or redefinition in user_namespace.h.

Kind regards,
Petr

 include/linux/ns_common.h     | 3 +++
 include/linux/pid_namespace.h | 3 ---
 kernel/user_namespace.c       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
include/linux/ns_common.h +3 -0
index 0f1d024bd958..173fab9dadf7 100644
@@ -4,6 +4,9 @@
 
 #include <linux/refcount.h>
 
+/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
+#define MAX_PID_NS_LEVEL 32
+
 struct proc_ns_operations;
 
 struct ns_common {
include/linux/pid_namespace.h +0 -3
index 07481bb87d4e..f814068012d0 100644
@@ -11,9 +11,6 @@
 #include <linux/ns_common.h>
 #include <linux/idr.h>
 
-/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
-#define MAX_PID_NS_LEVEL 32
-
 struct fs_pin;
 
 struct pid_namespace {
kernel/user_namespace.c +1 -1
index 5481ba44a8d6..6ea6e263403d 100644
@@ -87,7 +87,7 @@ int create_user_ns(struct cred *new)
 	int ret, i;
 
 	ret = -ENOSPC;
-	if (parent_ns->level > 32)
+	if (parent_ns->level > MAX_PID_NS_LEVEL)
 		goto fail;
 
 	ucounts = inc_user_namespaces(parent_ns, owner);
Signature · 1 line
2.35.1
#1 lore raw
Quoted 2 lines · Petr Vorel

Move MAX_PID_NS_LEVEL to ns_common.h and reuse it in check in user_namespace.c.

What is the motivation for this change?

Is it just that there is a bare number in create_user_ns and that is a little ugly? Or is there something more motivating this?

Eric

Quoted 58 lines

---
Hi Christian, all,

I don't see putting MAX_PID_NS_LEVEL into ns_common.h as an elegant solution but IMHO better than use a hardwired number or redefinition in user_namespace.h.

Kind regards,
Petr

 include/linux/ns_common.h     | 3 +++
 include/linux/pid_namespace.h | 3 ---
 kernel/user_namespace.c       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
include/linux/ns_common.h +3 -0
index 0f1d024bd958..173fab9dadf7 100644
@@ -4,6 +4,9 @@
 
 #include <linux/refcount.h>
 
+/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
+#define MAX_PID_NS_LEVEL 32
+
 struct proc_ns_operations;
 
 struct ns_common {
include/linux/pid_namespace.h +0 -3
index 07481bb87d4e..f814068012d0 100644
@@ -11,9 +11,6 @@
 #include <linux/ns_common.h>
 #include <linux/idr.h>
 
-/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
-#define MAX_PID_NS_LEVEL 32
-
 struct fs_pin;
 
 struct pid_namespace {
kernel/user_namespace.c +1 -1
index 5481ba44a8d6..6ea6e263403d 100644
@@ -87,7 +87,7 @@ int create_user_ns(struct cred *new)
 	int ret, i;
 
 	ret = -ENOSPC;
-	if (parent_ns->level > 32)
+	if (parent_ns->level > MAX_PID_NS_LEVEL)
 		goto fail;
 
 	ucounts = inc_user_namespaces(parent_ns, owner);
author
#2 lore raw
Quoted 9 lines
Quoted 2 lines · Petr Vorel

Move MAX_PID_NS_LEVEL to ns_common.h and reuse it in check in user_namespace.c.

What is the motivation for this change?

Is it just that there is a bare number in create_user_ns and that is a little ugly? Or is there something more motivating this?

Well, nothing more than to have constant which gives some description.

Kind regards,
Petr

Quoted 60 lines

Eric

Quoted 57 lines

---
Hi Christian, all,

I don't see putting MAX_PID_NS_LEVEL into ns_common.h as an elegant solution but IMHO better than use a hardwired number or redefinition in user_namespace.h.

Kind regards,
Petr

 include/linux/ns_common.h     | 3 +++
 include/linux/pid_namespace.h | 3 ---
 kernel/user_namespace.c       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
include/linux/ns_common.h +3 -0
index 0f1d024bd958..173fab9dadf7 100644
@@ -4,6 +4,9 @@
 
 #include <linux/refcount.h>
 
+/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
+#define MAX_PID_NS_LEVEL 32
+
 struct proc_ns_operations;
 
 struct ns_common {
include/linux/pid_namespace.h +0 -3
index 07481bb87d4e..f814068012d0 100644
@@ -11,9 +11,6 @@
 #include <linux/ns_common.h>
 #include <linux/idr.h>
 
-/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
-#define MAX_PID_NS_LEVEL 32
-
 struct fs_pin;
 
 struct pid_namespace {
kernel/user_namespace.c +1 -1
index 5481ba44a8d6..6ea6e263403d 100644
@@ -87,7 +87,7 @@ int create_user_ns(struct cred *new)
 	int ret, i;
 
 	ret = -ENOSPC;
-	if (parent_ns->level > 32)
+	if (parent_ns->level > MAX_PID_NS_LEVEL)
 		goto fail;
 
 	ucounts = inc_user_namespaces(parent_ns, owner);
#3 lore raw
In reply to Petr Vorel
Quoted 10 lines · Petr Vorel

Move MAX_PID_NS_LEVEL to ns_common.h and reuse it in check in user_namespace.c.

---
Hi Christian, all,

I don't see putting MAX_PID_NS_LEVEL into ns_common.h as an elegant solution but IMHO better than use a hardwired number or redefinition in user_namespace.h.

Hey Petr,

Weird I either deleted that message by accident or didn't get it.

Quoted 14 lines

Kind regards,
Petr

 include/linux/ns_common.h     | 3 +++
 include/linux/pid_namespace.h | 3 ---
 kernel/user_namespace.c       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
include/linux/ns_common.h +0 -0
index 0f1d024bd958..173fab9dadf7 100644

include/linux/ns_common.h line 8

Quoted 5 lines
include/linux/ns_common.h +2 -0
@@ -4,6 +4,9 @@
 
 #include <linux/refcount.h>
 
+/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
+#define MAX_PID_NS_LEVEL 32

The only two namespaces where this applies to have the same hard-coded limit. If you want to get rid of the raw number you should just introduce a generic define that expresses the limit for both pidns and userns. Using "MAX_PID_NS_LEVEL" in the userns case is very confusing. So if you wanted to do this introducing something like #define MAX_NS_LEVEL 32
and using it in both places makes more sense.

Christian

author
#4 lore raw

Hi all,

Quoted 8 lines · Petr Vorel
Quoted 6 lines

Move MAX_PID_NS_LEVEL to ns_common.h and reuse it in check in user_namespace.c.

---
Hi Christian, all,

Quoted 7 lines
Quoted 3 lines

I don't see putting MAX_PID_NS_LEVEL into ns_common.h as an elegant solution but IMHO better than use a hardwired number or redefinition in user_namespace.h.

Hey Petr,

Weird I either deleted that message by accident or didn't get it.

Interesting. BTW I didn't get any bounce suggesting mail to you didn't arrive.

Quoted 16 lines
Quoted 15 lines

Kind regards,
Petr

 include/linux/ns_common.h     | 3 +++
 include/linux/pid_namespace.h | 3 ---
 kernel/user_namespace.c       | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
include/linux/ns_common.h +0 -0
index 0f1d024bd958..173fab9dadf7 100644
@@ -4,6 +4,9 @@
 
 #include <linux/refcount.h>
Quoted 10 lines

include/linux/ns_common.h line 8

Quoted 2 lines
include/linux/ns_common.h +2 -0
+/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
+#define MAX_PID_NS_LEVEL 32

The only two namespaces where this applies to have the same hard-coded limit. If you want to get rid of the raw number you should just introduce a generic define that expresses the limit for both pidns and userns. Using "MAX_PID_NS_LEVEL" in the userns case is very confusing. So if you wanted to do this introducing something like #define MAX_NS_LEVEL 32
and using it in both places makes more sense.

Thanks a lot, I overlooked they aren't related.

I wonder if there should be just one constant for both (i.e. MAX_NS_LEVEL) as you suggest, 2 constants, i.e keep MAX_PID_NS_LEVEL and add MAX_USER_NS_LEVEL (which happen to be both 32).

Also understand if you prefer just to keep the raw number (MAX_PID_NS_LEVEL has more use than just a single place, but user namespaces need it just on single place).

Kind regards,
Petr

Quoted 1 line

Christian