ucounts: add missing data type changes
Subsystems (2)
PATCH 1/1 ucounts: add missing data type changes
commit f9c82a4ea89c3 ("Increase size of ucounts to atomic_long_t") changed the data type of ucounts/ucounts_max to long, but missed to adjust a few other places. This is noticeable on big endian platforms from user space because the /proc/sys/user/max_*_names files all contain 0.
--- fs/notify/fanotify/fanotify_user.c | 11 +++++++---- kernel/ucount.c | 18 ++++++++++-------- kernel/user_namespace.c | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-)
fs/notify/fanotify/fanotify_user.c +7 -4
@@ -54,22 +54,25 @@ static int fanotify_max_queued_events __read_mostly;#include <linux/sysctl.h> +static unsigned long long_max =LONG_MAX ;struct ctl_table fanotify_table[] = { { .procname ="max_user_groups" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_GROUPS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_user_marks" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_MARKS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_queued_events" ,
kernel/ucount.c +10 -8
@@ -58,14 +58,16 @@ static struct ctl_table_root set_root = { .permissions = set_permissions, }; -#define UCOUNT_ENTRY (name) \ - { \ - .procname = name, \ - .maxlen = sizeof(int), \ - .mode = 0644, \ - .proc_handler = proc_dointvec_minmax, \ - .extra1 = SYSCTL_ZERO, \ - .extra2 = SYSCTL_INT_MAX, \ +static unsigned long long_max =LONG_MAX ; + +#define UCOUNT_ENTRY (name) \ + { \ + .procname = name, \ + .maxlen = sizeof(long), \ + .mode = 0644, \ + .proc_handler = proc_doulongvec_minmax, \ + .extra1 = SYSCTL_ZERO, \ + .extra2 = &long_max, \ }static struct ctl_table user_table[] = {UCOUNT_ENTRY ("max_user_namespaces" ),
kernel/user_namespace.c +1 -1
@@ -120,7 +120,7 @@ int create_user_ns(struct cred *new) ns->group = group;INIT_WORK (&ns->work, free_user_ns);for (i =0 ; i <MAX_PER_NAMESPACE_UCOUNTS ; i++) { - ns->ucount_max[i] =INT_MAX ; + ns->ucount_max[i] =LONG_MAX ; }set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_NPROC ,rlimit (RLIMIT_NPROC ));set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_MSGQUEUE ,rlimit (RLIMIT_MSGQUEUE ));
Signature · 1 line
2.25.1
Quoted 5 lines · Sven Schnelle
commit
f9c82a4ea89c3("Increase size of ucounts toatomic_long_t") changed the data type of ucounts/ucounts_max to long, but missed to adjust a few other places. This is noticeable on big endian platforms from user space because the/proc/sys/user/max_*_namesfiles all contain 0.
I didn't increase them because I didn't want to increase the maximum number of namespaces.
Your patch not only fixes the described problem, but also increases the maximum number of namespaces.
Quoted 13 lines
Fixes f9c82a4ea89c ("Increase size of ucounts to atomic_long_t")Signed-off-by Sven Schnelle <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 11 +++++++---- kernel/ucount.c | 18 ++++++++++-------- kernel/user_namespace.c | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-)fs/notify/fanotify/fanotify_user.c +0
-0
fs/notify/fanotify/fanotify_user.c static int fanotify_max_queued_events __read_mostly; · line 57
Quoted 4 lines
fs/notify/fanotify/fanotify_user.c +1
-0@@ -54,22 +54,25 @@ static int fanotify_max_queued_events __read_mostly;#include <linux/sysctl.h> +static unsigned long long_max =LONG_MAX ;
I think this should be INT_MAX.
Quoted 70 lines
fs/notify/fanotify/fanotify_user.c +6
-4struct ctl_table fanotify_table[] = { { .procname ="max_user_groups" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_GROUPS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_user_marks" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_MARKS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_queued_events" ,kernel/ucount.c +10
-8@@ -58,14 +58,16 @@ static struct ctl_table_root set_root = { .permissions = set_permissions, }; -#define UCOUNT_ENTRY (name) \ - { \ - .procname = name, \ - .maxlen = sizeof(int), \ - .mode = 0644, \ - .proc_handler = proc_dointvec_minmax, \ - .extra1 = SYSCTL_ZERO, \ - .extra2 = SYSCTL_INT_MAX, \ +static unsigned long long_max =LONG_MAX ; + +#define UCOUNT_ENTRY (name) \ + { \ + .procname = name, \ + .maxlen = sizeof(long), \ + .mode = 0644, \ + .proc_handler = proc_doulongvec_minmax, \ + .extra1 = SYSCTL_ZERO, \ + .extra2 = &long_max, \ }static struct ctl_table user_table[] = {UCOUNT_ENTRY ("max_user_namespaces" ),kernel/user_namespace.c +1
-1@@ -120,7 +120,7 @@ int create_user_ns(struct cred *new) ns->group = group;INIT_WORK (&ns->work, free_user_ns);for (i =0 ; i <MAX_PER_NAMESPACE_UCOUNTS ; i++) { - ns->ucount_max[i] =INT_MAX ; + ns->ucount_max[i] =LONG_MAX ; }set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_NPROC ,rlimit (RLIMIT_NPROC ));set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_MSGQUEUE ,rlimit (RLIMIT_MSGQUEUE ));Signature · 1 line
2.25.1
Signature · 1 line
Rgrds, legion
Quoted 27 lines · Alexey Gladkov
Quoted 5 lines · Sven Schnelle
commit
f9c82a4ea89c3("Increase size of ucounts toatomic_long_t") changed the data type of ucounts/ucounts_max to long, but missed to adjust a few other places. This is noticeable on big endian platforms from user space because the/proc/sys/user/max_*_namesfiles all contain 0.I didn't increase them because I didn't want to increase the maximum number of namespaces.
Your patch not only fixes the described problem, but also increases the maximum number of namespaces.
Quoted 14 lines
Fixes f9c82a4ea89c ("Increase size of ucounts to atomic_long_t")Signed-off-by Sven Schnelle <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 11 +++++++---- kernel/ucount.c | 18 ++++++++++-------- kernel/user_namespace.c | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-)fs/notify/fanotify/fanotify_user.c +0
-0@@ -54,22 +54,25 @@ static int fanotify_max_queued_events __read_mostly;
Quoted 5 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_max_queued_events __read_mostly; · line 57
Quoted 3 lines
fs/notify/fanotify/fanotify_user.c +1
-0#include <linux/sysctl.h> +static unsigned long long_max =LONG_MAX ;I think this should be
INT_MAX.
Thanks. I'll change the code to use SYSCTL_INT_MAX instead and send a v2.
Quoted 56 lines
Quoted 56 lines
fs/notify/fanotify/fanotify_user.c +6
-4struct ctl_table fanotify_table[] = { { .procname ="max_user_groups" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_GROUPS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_user_marks" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_MARKS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_queued_events" ,kernel/ucount.c +10
-8@@ -58,14 +58,16 @@ static struct ctl_table_root set_root = { .permissions = set_permissions, }; -#define UCOUNT_ENTRY (name) \ - { \ - .procname = name, \ - .maxlen = sizeof(int), \ - .mode = 0644, \ - .proc_handler = proc_dointvec_minmax, \ - .extra1 = SYSCTL_ZERO, \ - .extra2 = SYSCTL_INT_MAX, \ +static unsigned long long_max =LONG_MAX ; + +#define UCOUNT_ENTRY (name) \ + { \ + .procname = name, \ + .maxlen = sizeof(long), \ + .mode = 0644, \ + .proc_handler = proc_doulongvec_minmax, \ + .extra1 = SYSCTL_ZERO, \ + .extra2 = &long_max, \ }static struct ctl_table user_table[] = {UCOUNT_ENTRY ("max_user_namespaces" ),kernel/user_namespace.c +0
-0
Quoted 8 lines
kernel/user_namespace.c int create_user_ns(struct cred *new) · line 123
Quoted 8 lines
kernel/user_namespace.c +1
-1@@ -120,7 +120,7 @@ int create_user_ns(struct cred *new) ns->group = group;INIT_WORK (&ns->work, free_user_ns);for (i =0 ; i <MAX_PER_NAMESPACE_UCOUNTS ; i++) { - ns->ucount_max[i] =INT_MAX ; + ns->ucount_max[i] =LONG_MAX ;
Guess this should also stay at INT_MAX?
Quoted 6 lines
Quoted 6 lines
kernel/user_namespace.c +0
-0}set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_NPROC ,rlimit (RLIMIT_NPROC ));set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_MSGQUEUE ,rlimit (RLIMIT_MSGQUEUE ));Signature · 1 line
2.25.1
Quoted 96 lines · Sven Schnelle
Quoted 27 lines · Alexey Gladkov
Quoted 5 lines · Sven Schnelle
commit
f9c82a4ea89c3("Increase size of ucounts toatomic_long_t") changed the data type of ucounts/ucounts_max to long, but missed to adjust a few other places. This is noticeable on big endian platforms from user space because the/proc/sys/user/max_*_namesfiles all contain 0.I didn't increase them because I didn't want to increase the maximum number of namespaces.
Your patch not only fixes the described problem, but also increases the maximum number of namespaces.
Quoted 14 lines
Fixes f9c82a4ea89c ("Increase size of ucounts to atomic_long_t")Signed-off-by Sven Schnelle <[email protected]>--- fs/notify/fanotify/fanotify_user.c | 11 +++++++---- kernel/ucount.c | 18 ++++++++++-------- kernel/user_namespace.c | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-)fs/notify/fanotify/fanotify_user.c +0
-0@@ -54,22 +54,25 @@ static int fanotify_max_queued_events __read_mostly;Quoted 5 lines
fs/notify/fanotify/fanotify_user.c static int fanotify_max_queued_events __read_mostly; · line 57
Quoted 3 lines
fs/notify/fanotify/fanotify_user.c +1
-0#include <linux/sysctl.h> +static unsigned long long_max =LONG_MAX ;I think this should be
INT_MAX.Thanks. I'll change the code to use
SYSCTL_INT_MAXinstead and send a v2.Quoted 58 lines
Quoted 58 lines
fs/notify/fanotify/fanotify_user.c +6
-4struct ctl_table fanotify_table[] = { { .procname ="max_user_groups" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_GROUPS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_user_marks" , .data = &init_user_ns.ucount_max[UCOUNT_FANOTIFY_MARKS ], - .maxlen =sizeof (int ), + .maxlen =sizeof (long ), .mode =0644 , - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_doulongvec_minmax, .extra1 =SYSCTL_ZERO , + .extra2 = &long_max, }, { .procname ="max_queued_events" ,kernel/ucount.c +10
-8@@ -58,14 +58,16 @@ static struct ctl_table_root set_root = { .permissions = set_permissions, }; -#define UCOUNT_ENTRY (name) \ - { \ - .procname = name, \ - .maxlen = sizeof(int), \ - .mode = 0644, \ - .proc_handler = proc_dointvec_minmax, \ - .extra1 = SYSCTL_ZERO, \ - .extra2 = SYSCTL_INT_MAX, \ +static unsigned long long_max =LONG_MAX ; + +#define UCOUNT_ENTRY (name) \ + { \ + .procname = name, \ + .maxlen = sizeof(long), \ + .mode = 0644, \ + .proc_handler = proc_doulongvec_minmax, \ + .extra1 = SYSCTL_ZERO, \ + .extra2 = &long_max, \ }static struct ctl_table user_table[] = {UCOUNT_ENTRY ("max_user_namespaces" ),kernel/user_namespace.c +0
-0
Quoted 8 lines
Quoted 6 lines
kernel/user_namespace.c int create_user_ns(struct cred *new) · line 123
Quoted 6 lines
kernel/user_namespace.c +1
-1@@ -120,7 +120,7 @@ int create_user_ns(struct cred *new) ns->group = group;INIT_WORK (&ns->work, free_user_ns);for (i =0 ; i <MAX_PER_NAMESPACE_UCOUNTS ; i++) { - ns->ucount_max[i] =INT_MAX ; + ns->ucount_max[i] =LONG_MAX ;Guess this should also stay at
INT_MAX?
Yes.
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
kernel/user_namespace.c +0
-0}set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_NPROC ,rlimit (RLIMIT_NPROC ));set_rlimit_ucount_max (ns,UCOUNT_RLIMIT_MSGQUEUE ,rlimit (RLIMIT_MSGQUEUE ));Signature · 1 line
2.25.1
Signature · 1 line
Rgrds, legion