ns: Rename MAX_PID_NS_LEVEL to MAX_NS_LEVEL, move
Subsystems (6)
PATCH v2 1/1 ns: Rename MAX_PID_NS_LEVEL to MAX_NS_LEVEL, move
Rename MAX_PID_NS_LEVEL to MAX_NS_LEVEL, move it ns_common.h and reuse it in check in user_namespace.c.
---
changes v1->v2:
instead of reusing MAX_PID_NS_LEVEL for user_namespace.c create general constant MAX_NS_LEVEL used in both (Christian)
That leaded to changes on more places.
As value 32 is likely to be used for any namespace it makes sense to have this general variable instead of keeping MAX_PID_NS_LEVEL and creating MAX_USER_NS_LEVEL.
Kind regards,
Petr
include/linux/ns_common.h | 3 ++ include/linux/pid_namespace.h | 3 -- kernel/fork.c | 4 +-- kernel/pid_namespace.c | 4 +-- kernel/user_namespace.c | 2 +- .../clone3/clone3_cap_checkpoint_restore.c | 4 +-- .../testing/selftests/clone3/clone3_set_tid.c | 30 +++++++++---------- 7 files changed, 25 insertions(+), 25 deletions(-)
include/linux/ns_common.h +3 -0
@@ -4,6 +4,9 @@#include <linux/refcount.h> +/* MAX_NS_LEVEL is needed for limiting size of 'struct pid' */ +#define MAX_NS_LEVEL 32 +struct proc_ns_operations ;struct ns_common {
include/linux/pid_namespace.h +0 -3
@@ -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/fork.c +2 -2
@@ -2784,7 +2784,7 @@ noinline static int copy_clone_args_from_user(struct kernel_clone_args *kargs,if (err)return err; -if (unlikely (args.set_tid_size >MAX_PID_NS_LEVEL )) +if (unlikely (args.set_tid_size >MAX_NS_LEVEL ))return -EINVAL ;if (unlikely (!args.set_tid && args.set_tid_size >0 ))
@@ -2900,7 +2900,7 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)int err;struct kernel_clone_args kargs; -pid_t set_tid[MAX_PID_NS_LEVEL ]; +pid_t set_tid[MAX_NS_LEVEL ]; kargs.set_tid = set_tid;
kernel/pid_namespace.c +2 -2
@@ -27,7 +27,7 @@static DEFINE_MUTEX (pid_caches_mutex);static struct kmem_cache *pid_ns_cachep;/* Write once array, filled from the beginning. */ -static struct kmem_cache *pid_cache[MAX_PID_NS_LEVEL ]; +static struct kmem_cache *pid_cache[MAX_NS_LEVEL ];/* * creates the kmem cache to allocate pids from.
@@ -81,7 +81,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns goto out; err = -ENOSPC ; -if (level >MAX_PID_NS_LEVEL ) +if (level >MAX_NS_LEVEL ) goto out; ucounts =inc_pid_namespaces (user_ns);if (!ucounts)
kernel/user_namespace.c +1 -1
@@ -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_NS_LEVEL ) goto fail; ucounts =inc_user_namespaces (parent_ns, owner);
tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c +2 -2
@@ -27,8 +27,8 @@#include "../kselftest_harness.h" #include "clone3_selftests.h" -#ifndef MAX_PID_NS_LEVEL -#define MAX_PID_NS_LEVEL 32 +#ifndef MAX_NS_LEVEL +#define MAX_NS_LEVEL 32#endif static void child_exit (int ret)
tools/testing/selftests/clone3/clone3_set_tid.c +15 -15
@@ -23,8 +23,8 @@#include "../kselftest.h" #include "clone3_selftests.h" -#ifndef MAX_PID_NS_LEVEL -#define MAX_PID_NS_LEVEL 32 +#ifndef MAX_NS_LEVEL +#define MAX_NS_LEVEL 32#endif static int pipe_1[2 ];
@@ -154,7 +154,7 @@ int main(int argc, char *argv[])uid_t uid =getuid ();char proc_path[100 ] = {0 };pid_t pid, ns1, ns2, ns3, ns_pid; -pid_t set_tid[MAX_PID_NS_LEVEL *2 ]; +pid_t set_tid[MAX_NS_LEVEL *2 ];ksft_print_header ();ksft_set_plan (29 );
@@ -174,36 +174,36 @@ int main(int argc, char *argv[])/* Try invalid settings */ memset (&set_tid,0 ,sizeof (set_tid)); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL +1 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL +1 ,0 , -EINVAL ,0 ,0 ); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL *2 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL *2 ,0 , -EINVAL ,0 ,0 ); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL *2 +1 ,0 , +test_clone3_set_tid (set_tid,MAX_NS_LEVEL *2 +1 ,0 , -EINVAL ,0 ,0 ); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL *42 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL *42 ,0 , -EINVAL ,0 ,0 );/* -* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1 +* This can actually work if this test running in a MAX_NS_LEVEL - 1 * nested PID namespace. */ -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL -1 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL -1 ,0 , -EINVAL ,0 ,0 );memset (&set_tid,0xff ,sizeof (set_tid)); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL +1 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL +1 ,0 , -EINVAL ,0 ,0 ); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL *2 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL *2 ,0 , -EINVAL ,0 ,0 ); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL *2 +1 ,0 , +test_clone3_set_tid (set_tid,MAX_NS_LEVEL *2 +1 ,0 , -EINVAL ,0 ,0 ); -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL *42 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL *42 ,0 , -EINVAL ,0 ,0 );/* -* This can actually work if this test running in a MAX_PID_NS_LEVEL - 1 +* This can actually work if this test running in a MAX_NS_LEVEL - 1 * nested PID namespace. */ -test_clone3_set_tid (set_tid,MAX_PID_NS_LEVEL -1 ,0 , -EINVAL ,0 ,0 ); +test_clone3_set_tid (set_tid,MAX_NS_LEVEL -1 ,0 , -EINVAL ,0 ,0 );memset (&set_tid,0 ,sizeof (set_tid));/* Try with an invalid PID */
Signature · 1 line
2.35.1
Hi,
...
include/linux/ns_common.h line 7
Quoted 6 lines
+++
b/include/linux/ns_common.hinclude/linux/ns_common.h +1
-0@@ -4,6 +4,9 @@#include <linux/refcount.h> +/* MAX_NS_LEVEL is needed for limiting size of 'struct pid' */
Hm, I forgot to amend the patch. This was supposed to be:
/* pid and user namespace */
I can send v3 if is patch considered useful.
Review line 8
Quoted 1 line
(quoted diff) +1
-0+#define MAX_NS_LEVEL 32
...
Kind regards,
Petr