Skip to contentSkip to conversation

sysctl: Restore minmax check for proc_do{int,ulong}vec_ms_jiffies_minmax().

PATCH In review Kuniyuki Iwashima 2 participants 14 messages Sep 5 – Sep 11 VFS

lore
Share & tools
lore
#0 lore raw

cover sysctl: Restore minmax check for proc_do{int,ulong}vec_ms_jiffies_minmax().

The recent refactoring accidentally removed the minmax check from proc_dointvec_ms_jiffies_minmax() and proc_doulongvec_ms_jiffies_minmax().

The series restores the validation, and patch 2 adds the INT_MAX limit for proc_doulongvec_ms_jiffies_minmax() to avoid silent truncation.

Kuniyuki Iwashima (2):
sysctl: Make proc_dointvec_ms_jiffies_minmax() enforce minmax again.
sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

 kernel/time/jiffies.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#1 lore raw

PATCH 1/2 sysctl: Make proc_dointvec_ms_jiffies_minmax() enforce minmax again.

When the cited commit converted the SYSCTL_INT_CONV_CUSTOM macro to functions, it accidentally changed do_proc_int_conv_ms_jiffies_minmax() to pass false for k_ptr_range_check.

Since then, net.ipv[46].neigh.${dev}.interval_probe_time_ms no longer enforces the lower bound.

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  net.ipv4.neigh.bond0.interval_probe_time_ms = 0

Let's restore the minmax check.

With this:

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  sysctl: setting key "net.ipv4.neigh.bond0.interval_probe_time_ms": Invalid argument
Fixes d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions")
---
 kernel/time/jiffies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/jiffies.c +1 -1
index 213ae1d6a014..70926b73905a 100644
@@ -181,7 +181,7 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
 					      int *k_ptr, int dir,
 					      const struct ctl_table *tbl)
 {
-	return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, false,
+	return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, true,
 			     sysctl_u2k_int_conv_ms, sysctl_k2u_int_conv_ms);
 }
 
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#2 lore raw

Re: [PATCH 1/2] sysctl: Make proc_dointvec_ms_jiffies_minmax() enforce minmax again.

Quoted 28 lines · Kuniyuki Iwashima

When the cited commit converted the SYSCTL_INT_CONV_CUSTOM macro to functions, it accidentally changed do_proc_int_conv_ms_jiffies_minmax() to pass false for k_ptr_range_check.

Since then, net.ipv[46].neigh.${dev}.interval_probe_time_ms no longer enforces the lower bound.

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  net.ipv4.neigh.bond0.interval_probe_time_ms = 0

Let's restore the minmax check.

With this:

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  sysctl: setting key "net.ipv4.neigh.bond0.interval_probe_time_ms": Invalid argument
Fixes d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions")
---
 kernel/time/jiffies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/jiffies.c +0 -0
index 213ae1d6a014..70926b73905a 100644

kernel/time/jiffies.c static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, · line 185

Quoted 6 lines
kernel/time/jiffies.c +1 -1
@@ -181,7 +181,7 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
 					      int *k_ptr, int dir,
 					      const struct ctl_table *tbl)
 {
-	return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, false,
+	return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, true,
 			     sysctl_u2k_int_conv_ms, sysctl_k2u_int_conv_ms);

oops!!!! Very good catch.

I can see that this needs to be fixed, but your commit message needs work. Please re-write like this:

Add the range check to do_proc_int_conv_ms_jiffies_minmax that commit d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions") incorrectly removed.

Fixes d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions")

Signed....

Why is that info about net is relevant here? I would remove it.

Quoted 5 lines
kernel/time/jiffies.c +0 -0
 }
 
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#3 lore raw

Re: [PATCH 1/2] sysctl: Make proc_dointvec_ms_jiffies_minmax() enforce minmax again.

Quoted 43 lines · Joel Granados
Quoted 28 lines · Kuniyuki Iwashima

When the cited commit converted the SYSCTL_INT_CONV_CUSTOM macro to functions, it accidentally changed do_proc_int_conv_ms_jiffies_minmax() to pass false for k_ptr_range_check.

Since then, net.ipv[46].neigh.${dev}.interval_probe_time_ms no longer enforces the lower bound.

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  net.ipv4.neigh.bond0.interval_probe_time_ms = 0

Let's restore the minmax check.

With this:

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  sysctl: setting key "net.ipv4.neigh.bond0.interval_probe_time_ms": Invalid argument
Fixes d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions")
---
 kernel/time/jiffies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/jiffies.c +0 -0
index 213ae1d6a014..70926b73905a 100644

kernel/time/jiffies.c static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, · line 185

Quoted 6 lines
kernel/time/jiffies.c +1 -1
@@ -181,7 +181,7 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
                                            int *k_ptr, int dir,
                                            const struct ctl_table *tbl)
 {
-     return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, false,
+     return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, true,
                           sysctl_u2k_int_conv_ms, sysctl_k2u_int_conv_ms);

oops!!!! Very good catch.

I can see that this needs to be fixed, but your commit message needs work. Please re-write like this:

Quoted 8 lines

Add the range check to do_proc_int_conv_ms_jiffies_minmax that commit d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions") incorrectly removed.

Fixes d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions")

Signed....

Why is that info about net is relevant here? I would remove it.

Because it's the only relevant user.

$ grep -rnI proc_dointvec_ms_jiffies_minmax
include/linux/jiffies.h:649:int proc_dointvec_ms_jiffies_minmax(const
struct ctl_table *table, int dir,
net/core/neighbour.c:3679: ret = proc_dointvec_ms_jiffies_minmax(&tmp,
write, buffer, lenp, ppos);
kernel/time/jiffies.c:311:int proc_dointvec_ms_jiffies_minmax(const
struct ctl_table *table, int dir,
Quoted 6 lines
Quoted 6 lines
kernel/time/jiffies.c +0 -1
 }
 
--

2.55.0.1003.g10538fe699-goog

#4 lore raw

Re: [PATCH 1/2] sysctl: Make proc_dointvec_ms_jiffies_minmax() enforce minmax again.

Quoted 48 lines · Kuniyuki Iwashima
Quoted 47 lines · Joel Granados
Quoted 28 lines · Kuniyuki Iwashima

When the cited commit converted the SYSCTL_INT_CONV_CUSTOM macro to functions, it accidentally changed do_proc_int_conv_ms_jiffies_minmax() to pass false for k_ptr_range_check.

Since then, net.ipv[46].neigh.${dev}.interval_probe_time_ms no longer enforces the lower bound.

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  net.ipv4.neigh.bond0.interval_probe_time_ms = 0

Let's restore the minmax check.

With this:

  # sysctl net.ipv4.neigh.bond0.interval_probe_time_ms=0
  sysctl: setting key "net.ipv4.neigh.bond0.interval_probe_time_ms": Invalid argument
Fixes d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions")
---
 kernel/time/jiffies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/jiffies.c +0 -0
index 213ae1d6a014..70926b73905a 100644

kernel/time/jiffies.c static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, · line 185

Quoted 6 lines
kernel/time/jiffies.c +1 -1
@@ -181,7 +181,7 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
                                            int *k_ptr, int dir,
                                            const struct ctl_table *tbl)
 {
-     return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, false,
+     return proc_int_conv(negp, u_ptr, k_ptr, dir, tbl, true,
                           sysctl_u2k_int_conv_ms, sysctl_k2u_int_conv_ms);

oops!!!! Very good catch.

I can see that this needs to be fixed, but your commit message needs work. Please re-write like this:

Add the range check to do_proc_int_conv_ms_jiffies_minmax that commit d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions") incorrectly removed.

Quoted 6 lines
Quoted 4 lines
Fixes d174174c6776 ("sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions")

Signed....

Why is that info about net is relevant here? I would remove it.

Because it's the only relevant user.

I can see that, but the range check was removed because of a oversight in d174174c6776, not because of anything happening in the caller. I would just drop that info from the commit message.

Quoted 15 lines
$ grep -rnI proc_dointvec_ms_jiffies_minmax
include/linux/jiffies.h:649:int proc_dointvec_ms_jiffies_minmax(const
struct ctl_table *table, int dir,
net/core/neighbour.c:3679: ret = proc_dointvec_ms_jiffies_minmax(&tmp,
write, buffer, lenp, ppos);
kernel/time/jiffies.c:311:int proc_dointvec_ms_jiffies_minmax(const
struct ctl_table *table, int dir,
Quoted 6 lines
Quoted 6 lines
kernel/time/jiffies.c +0 -1
 }
 
--

2.55.0.1003.g10538fe699-goog

Please let me know if you will send a V2. Else I'll just push them at the beginning of next week.

Best

#5 lore raw

PATCH 2/2 sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

In reply to Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

Let's rename do_proc_ulong_conv_ms_jiffies(), pass true to k_ptr_range_check, and limit the max user input to INT_MAX in sysctl_u2k_ulong_conv_ms() to avoid truncation and clamping to MAX_JIFFY_OFFSET. (INT_MAX ms ~= 24 days is more than enough)

Fixes b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec")
---
 kernel/time/jiffies.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/time/jiffies.c +9 -6
index 70926b73905a..4737431fdb16 100644
@@ -187,6 +187,9 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
 
 static int sysctl_u2k_ulong_conv_ms(const ulong *u_ptr, ulong *k_ptr)
 {
+	if (*u_ptr > INT_MAX)
+		return -EINVAL;
+
 	return proc_ulong_u2k_conv_uop(u_ptr, k_ptr, sysctl_msecs_to_jiffies);
 }
 
@@ -195,10 +198,10 @@ static int sysctl_k2u_ulong_conv_ms(ulong *u_ptr, const ulong *k_ptr)
 	return proc_ulong_k2u_conv_kop(u_ptr, k_ptr, sysctl_jiffies_to_msecs);
 }
 
-static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
-					 int dir, const struct ctl_table *tbl)
+static int do_proc_ulong_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, ulong *k_ptr,
+						int dir, const struct ctl_table *tbl)
 {
-	return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, false,
+	return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, true,
 			       sysctl_u2k_ulong_conv_ms, sysctl_k2u_ulong_conv_ms);
 }
 
@@ -229,8 +232,8 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
 	return -ENOSYS;
 }
 
-static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
-					 int dir, const struct ctl_table *tbl)
+static int do_proc_ulong_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, ulong *k_ptr,
+						int dir, const struct ctl_table *tbl)
 {
 	return -ENOSYS;
 }
@@ -333,7 +336,7 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir,
 				      void *buffer, size_t *lenp, loff_t *ppos)
 {
 	return proc_doulongvec_conv(table, dir, buffer, lenp, ppos,
-				    do_proc_ulong_conv_ms_jiffies);
+				    do_proc_ulong_conv_ms_jiffies_minmax);
 }
 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
 
Signature · 1 line
2.55.0.1003.g10538fe699-goog
#6 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 9 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

Quoted 17 lines

Let's rename do_proc_ulong_conv_ms_jiffies(), pass true to k_ptr_range_check, and limit the max user input to INT_MAX in sysctl_u2k_ulong_conv_ms() to avoid truncation and clamping to MAX_JIFFY_OFFSET. (INT_MAX ms ~= 24 days is more than enough)

Fixes b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec")
---
 kernel/time/jiffies.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/time/jiffies.c +0 -0
index 70926b73905a..4737431fdb16 100644

kernel/time/jiffies.c static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, · line 192

Quoted 6 lines
kernel/time/jiffies.c +3 -0
@@ -187,6 +187,9 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
 
 static int sysctl_u2k_ulong_conv_ms(const ulong *u_ptr, ulong *k_ptr)
 {
+	if (*u_ptr > INT_MAX)
+		return -EINVAL;
+

Create a commit for this on its own.

Quoted 29 lines
kernel/time/jiffies.c +5 -5
 	return proc_ulong_u2k_conv_uop(u_ptr, k_ptr, sysctl_msecs_to_jiffies);
 }
 
@@ -195,10 +198,10 @@ static int sysctl_k2u_ulong_conv_ms(ulong *u_ptr, const ulong *k_ptr)
 	return proc_ulong_k2u_conv_kop(u_ptr, k_ptr, sysctl_jiffies_to_msecs);
 }
 
-static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
-					 int dir, const struct ctl_table *tbl)
+static int do_proc_ulong_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, ulong *k_ptr,
+						int dir, const struct ctl_table *tbl)
 {
-	return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, false,
+	return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, true,
 			       sysctl_u2k_ulong_conv_ms, sysctl_k2u_ulong_conv_ms);
 }
 
@@ -229,8 +232,8 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
 	return -ENOSYS;
 }
 
-static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
-					 int dir, const struct ctl_table *tbl)
+static int do_proc_ulong_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, ulong *k_ptr,
+						int dir, const struct ctl_table *tbl)
 {
 	return -ENOSYS;
 }

kernel/time/jiffies.c int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir, · line 341

Quoted 7 lines
kernel/time/jiffies.c +1 -1
@@ -333,7 +336,7 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir,
 				      void *buffer, size_t *lenp, loff_t *ppos)
 {
 	return proc_doulongvec_conv(table, dir, buffer, lenp, ppos,
-				    do_proc_ulong_conv_ms_jiffies);
+				    do_proc_ulong_conv_ms_jiffies_minmax);
 }
 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);

Good catch, but the commit wording is off. Please change to something like

Add the range check back to do_proc_ulong_conv_ms_jiffies that commit b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec") incorrectlry removed. Append "_minmax" to the end of the do_proc_ulong_conv_ms_jiffies so it is clear that there should be a range check.

Fixes b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec")

Signed...

Quoted 4 lines
Signature · 2 lines
-- 
2.55.0.1003.g10538fe699-goog
#7 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 9 lines · Joel Granados
Quoted 7 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

Quoted 7 lines
Quoted 2 lines

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

I guess people wanted to use ulong just because jiffies is unsigned long.

Looking at these users, none of them need the ulong range and it can be u32 actually.

net/rds/sysctl.c:58: .proc_handler = proc_doulongvec_ms_jiffies_minmax,
net/rds/sysctl.c:67: .proc_handler = proc_doulongvec_ms_jiffies_minmax,
net/rxrpc/sysctl.c:59: .proc_handler = proc_doulongvec_ms_jiffies_minmax, net/rxrpc/sysctl.c:68: .proc_handler = proc_doulongvec_ms_jiffies_minmax, drivers/parport/procfs.c:369: .proc_handler = proc_doulongvec_ms_jiffies_minmax, drivers/parport/procfs.c:399: .proc_handler = proc_doulongvec_ms_jiffies_minmax,

Quoted 83 lines
Quoted 18 lines

Let's rename do_proc_ulong_conv_ms_jiffies(), pass true to k_ptr_range_check, and limit the max user input to INT_MAX in sysctl_u2k_ulong_conv_ms() to avoid truncation and clamping to MAX_JIFFY_OFFSET. (INT_MAX ms ~= 24 days is more than enough)

Fixes b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec")
---
 kernel/time/jiffies.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/time/jiffies.c +0 -0
index 70926b73905a..4737431fdb16 100644

kernel/time/jiffies.c static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, · line 192

Quoted 6 lines
kernel/time/jiffies.c +3 -0
@@ -187,6 +187,9 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
 
 static int sysctl_u2k_ulong_conv_ms(const ulong *u_ptr, ulong *k_ptr)
 {
+     if (*u_ptr > INT_MAX)
+             return -EINVAL;
+

Create a commit for this on its own.

Quoted 29 lines
kernel/time/jiffies.c +5 -5
      return proc_ulong_u2k_conv_uop(u_ptr, k_ptr, sysctl_msecs_to_jiffies);
 }
 
@@ -195,10 +198,10 @@ static int sysctl_k2u_ulong_conv_ms(ulong *u_ptr, const ulong *k_ptr)
      return proc_ulong_k2u_conv_kop(u_ptr, k_ptr, sysctl_jiffies_to_msecs);
 }
 
-static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
-                                      int dir, const struct ctl_table *tbl)
+static int do_proc_ulong_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, ulong *k_ptr,
+                                             int dir, const struct ctl_table *tbl)
 {
-     return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, false,
+     return proc_ulong_conv(u_ptr, k_ptr, dir, tbl, true,
                             sysctl_u2k_ulong_conv_ms, sysctl_k2u_ulong_conv_ms);
 }
 
@@ -229,8 +232,8 @@ static int do_proc_int_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr,
      return -ENOSYS;
 }
 
-static int do_proc_ulong_conv_ms_jiffies(bool *negp, ulong *u_ptr, ulong *k_ptr,
-                                      int dir, const struct ctl_table *tbl)
+static int do_proc_ulong_conv_ms_jiffies_minmax(bool *negp, ulong *u_ptr, ulong *k_ptr,
+                                             int dir, const struct ctl_table *tbl)
 {
      return -ENOSYS;
 }

kernel/time/jiffies.c int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir, · line 341

Quoted 7 lines
kernel/time/jiffies.c +1 -1
@@ -333,7 +336,7 @@ int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int dir,
                                    void *buffer, size_t *lenp, loff_t *ppos)
 {
      return proc_doulongvec_conv(table, dir, buffer, lenp, ppos,
-                                 do_proc_ulong_conv_ms_jiffies);
+                                 do_proc_ulong_conv_ms_jiffies_minmax);
 }
 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);

Good catch, but the commit wording is off. Please change to something like

Add the range check back to do_proc_ulong_conv_ms_jiffies that commit b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec") incorrectlry removed. Append "_minmax" to the end of the do_proc_ulong_conv_ms_jiffies so it is clear that there should be a range check.

Fixes b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec")

Signed...

Quoted 4 lines
kernel/time/jiffies.c +0 -1
--

2.55.0.1003.g10538fe699-goog

#8 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 15 lines · Kuniyuki Iwashima
Quoted 14 lines · Joel Granados
Quoted 9 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

Quoted 8 lines
Quoted 2 lines

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

I guess people wanted to use ulong just because jiffies is unsigned long.

Looking at these users, none of them need the ulong range and it can be u32 actually.

Exactly. But changing those calls from ulong to uint is up to net and parport. I'm more interested in defining the behavior in sysctl_u2k_ulong_conv_ms.

Here is my train of thought:
1. u64 values will get truncated when they pass through msecs_to_jiffies

2. The range of msecs_to_jiffies is:
[0, INT_MAX] ---> ceil(m × HZ / 1000)
[INT_MAX+1, UINT_MAX] ---> MAX_JIFFY_OFFSET

Which I interpret as whatever that falls out of [0, INT_MAX] milliseconds is just infinite jiffies (MAX_JIFFY_OFFSET).

3. All but one users of do_proc_ulong_conv_ms_jiffies are bound to values under MAX_JIFFY_OFFSET. The exception is net/rds/sysctl.c:67 that has a max of ~0UL (is this too high?).

4. Since milliseconds to jiffies should be capped at MAX_JIFFY_OFFSET for big values. Should we just return MAX_JIFFY_OFFSET? Like this:

    diff --git i/kernel/time/jiffies.c w/kernel/time/jiffies.c
    index 213ae1d6a014..400353b0d6f9 100644
    --- i/kernel/time/jiffies.c
    +++ w/kernel/time/jiffies.c
    @@ -136,6 +136,8 @@ static int sysctl_k2u_int_conv_userhz(bool *negp, ulong *u_ptr, const int *k_ptr

     static ulong sysctl_msecs_to_jiffies(const ulong val)
     {
    +       if (val > UINT_MAX)
    +               return MAX_JIFFY_OFFSET;
            return msecs_to_jiffies(val);
     }
Quoted 9 lines

net/rds/sysctl.c:58: .proc_handler = proc_doulongvec_ms_jiffies_minmax,
net/rds/sysctl.c:67: .proc_handler = proc_doulongvec_ms_jiffies_minmax,
net/rxrpc/sysctl.c:59: .proc_handler = proc_doulongvec_ms_jiffies_minmax, net/rxrpc/sysctl.c:68: .proc_handler = proc_doulongvec_ms_jiffies_minmax, drivers/parport/procfs.c:369: .proc_handler = proc_doulongvec_ms_jiffies_minmax, drivers/parport/procfs.c:399: .proc_handler = proc_doulongvec_ms_jiffies_minmax,

<...snip...>

Quoted 11 lines
Quoted 11 lines

do_proc_vec") incorrectlry removed. Append "_minmax" to the end of the do_proc_ulong_conv_ms_jiffies so it is clear that there should be a range check.

Fixes b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec")

Signed...

Quoted 1 line
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

--
2.55.0.1003.g10538fe699-goog

Best

Joel

#9 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 20 lines · Joel Granados
Quoted 18 lines · Kuniyuki Iwashima
Quoted 16 lines · Joel Granados
Quoted 9 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

Quoted 8 lines
Quoted 5 lines

I guess people wanted to use ulong just because jiffies is unsigned long.

Looking at these users, none of them need the ulong range and it can be u32 actually.

Exactly. But changing those calls from ulong to uint is up to net and parport.

Agreed, it should be done in the -next branch of each subsystem.

And later, we can remove do_proc_ulong_conv_ms_jiffies().

Quoted 6 lines

I'm more interested in defining the behavior in
sysctl_u2k_ulong_conv_ms.

Here is my train of thought:
1. u64 values will get truncated when they pass through msecs_to_jiffies

Quoted 6 lines

2. The range of msecs_to_jiffies is:
[0, INT_MAX] ---> ceil(m × HZ / 1000)
[INT_MAX+1, UINT_MAX] ---> MAX_JIFFY_OFFSET

Which I interpret as whatever that falls out of [0, INT_MAX] milliseconds is just infinite jiffies (MAX_JIFFY_OFFSET).

nit: for HZ > 1000 (IIRC up to 1200 ?), the max of the range gets a little bit smaller.

Quoted 4 lines

3. All but one users of do_proc_ulong_conv_ms_jiffies are bound to values under MAX_JIFFY_OFFSET. The exception is net/rds/sysctl.c:67 that has a max of ~0UL (is this too high?).

I think this is just set as the theoretical max of @jiffies, but not specifically for the knob.

The default of the knob is 1 sec (HZ), and even INT_MAX (24 days) is too high for RDS reconnect.

Quoted 5 lines

4. Since milliseconds to jiffies should be capped at MAX_JIFFY_OFFSET for big values. Should we just return MAX_JIFFY_OFFSET? Like this:

Quoted 10 lines
    diff --git i/kernel/time/jiffies.c w/kernel/time/jiffies.c
    index 213ae1d6a014..400353b0d6f9 100644
    --- i/kernel/time/jiffies.c
    +++ w/kernel/time/jiffies.c
    @@ -136,6 +136,8 @@ static int sysctl_k2u_int_conv_userhz(bool *negp, ulong *u_ptr, const int *k_ptr

     static ulong sysctl_msecs_to_jiffies(const ulong val)
     {
    +       if (val > UINT_MAX)
    +               return MAX_JIFFY_OFFSET;

Given the nit at 2., it should be like this

if (val > jiffies_to_msecs(MAX_JIFFY_OFFSET))

    return MAX_JIFFY_OFFSET;

as done in _msecs_to_jiffies().

Quoted 32 lines
            return msecs_to_jiffies(val);
     }
Quoted 9 lines

net/rds/sysctl.c:58: .proc_handler = proc_doulongvec_ms_jiffies_minmax,
net/rds/sysctl.c:67: .proc_handler = proc_doulongvec_ms_jiffies_minmax,
net/rxrpc/sysctl.c:59: .proc_handler = proc_doulongvec_ms_jiffies_minmax, net/rxrpc/sysctl.c:68: .proc_handler = proc_doulongvec_ms_jiffies_minmax, drivers/parport/procfs.c:369: .proc_handler = proc_doulongvec_ms_jiffies_minmax, drivers/parport/procfs.c:399: .proc_handler = proc_doulongvec_ms_jiffies_minmax,

<...snip...>

Quoted 11 lines
Quoted 11 lines

do_proc_vec") incorrectlry removed. Append "_minmax" to the end of the do_proc_ulong_conv_ms_jiffies so it is clear that there should be a range check.

Fixes b96b5c6708ea ("sysctl: Replace do_proc_do{int,ulong,uint}vec with do_proc_vec")

Signed...

Quoted 1 line
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

--
2.55.0.1003.g10538fe699-goog

Best

Joel

#10 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 80 lines · Kuniyuki Iwashima
Quoted 20 lines · Joel Granados
Quoted 18 lines · Kuniyuki Iwashima
Quoted 16 lines · Joel Granados
Quoted 9 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

Quoted 8 lines
Quoted 5 lines

I guess people wanted to use ulong just because jiffies is unsigned long.

Looking at these users, none of them need the ulong range and it can be u32 actually.

Exactly. But changing those calls from ulong to uint is up to net and parport.

Agreed, it should be done in the -next branch of each subsystem.

And later, we can remove do_proc_ulong_conv_ms_jiffies().

Quoted 6 lines

I'm more interested in defining the behavior in
sysctl_u2k_ulong_conv_ms.

Here is my train of thought:
1. u64 values will get truncated when they pass through msecs_to_jiffies

Quoted 6 lines

2. The range of msecs_to_jiffies is:
[0, INT_MAX] ---> ceil(m × HZ / 1000)
[INT_MAX+1, UINT_MAX] ---> MAX_JIFFY_OFFSET

Which I interpret as whatever that falls out of [0, INT_MAX] milliseconds is just infinite jiffies (MAX_JIFFY_OFFSET).

nit: for HZ > 1000 (IIRC up to 1200 ?), the max of the range gets a little bit smaller.

Quoted 4 lines

3. All but one users of do_proc_ulong_conv_ms_jiffies are bound to values under MAX_JIFFY_OFFSET. The exception is net/rds/sysctl.c:67 that has a max of ~0UL (is this too high?).

I think this is just set as the theoretical max of @jiffies, but not specifically for the knob.

The default of the knob is 1 sec (HZ), and even INT_MAX (24 days) is too high for RDS reconnect.

Quoted 5 lines

4. Since milliseconds to jiffies should be capped at MAX_JIFFY_OFFSET for big values. Should we just return MAX_JIFFY_OFFSET? Like this:

Quoted 10 lines
    diff --git i/kernel/time/jiffies.c w/kernel/time/jiffies.c
    index 213ae1d6a014..400353b0d6f9 100644
    --- i/kernel/time/jiffies.c
    +++ w/kernel/time/jiffies.c
    @@ -136,6 +136,8 @@ static int sysctl_k2u_int_conv_userhz(bool *negp, ulong *u_ptr, const int *k_ptr

     static ulong sysctl_msecs_to_jiffies(const ulong val)
     {
    +       if (val > UINT_MAX)
    +               return MAX_JIFFY_OFFSET;
Quoted 6 lines

Given the nit at 2., it should be like this

if (val > jiffies_to_msecs(MAX_JIFFY_OFFSET))

    return MAX_JIFFY_OFFSET;

as done in _msecs_to_jiffies().

That is even better.

Please send a V2 of the 3 fixes discussed and I'll push them through next week.

Best

#11 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 86 lines · Joel Granados
Quoted 85 lines · Kuniyuki Iwashima
Quoted 20 lines · Joel Granados
Quoted 18 lines · Kuniyuki Iwashima
Quoted 16 lines · Joel Granados
Quoted 9 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

Quoted 8 lines
Quoted 5 lines

I guess people wanted to use ulong just because jiffies is unsigned long.

Looking at these users, none of them need the ulong range and it can be u32 actually.

Exactly. But changing those calls from ulong to uint is up to net and parport.

Agreed, it should be done in the -next branch of each subsystem.

And later, we can remove do_proc_ulong_conv_ms_jiffies().

Quoted 6 lines

I'm more interested in defining the behavior in
sysctl_u2k_ulong_conv_ms.

Here is my train of thought:
1. u64 values will get truncated when they pass through msecs_to_jiffies

Quoted 6 lines

2. The range of msecs_to_jiffies is:
[0, INT_MAX] ---> ceil(m × HZ / 1000)
[INT_MAX+1, UINT_MAX] ---> MAX_JIFFY_OFFSET

Which I interpret as whatever that falls out of [0, INT_MAX] milliseconds is just infinite jiffies (MAX_JIFFY_OFFSET).

nit: for HZ > 1000 (IIRC up to 1200 ?), the max of the range gets a little bit smaller.

Quoted 4 lines

3. All but one users of do_proc_ulong_conv_ms_jiffies are bound to values under MAX_JIFFY_OFFSET. The exception is net/rds/sysctl.c:67 that has a max of ~0UL (is this too high?).

I think this is just set as the theoretical max of @jiffies, but not specifically for the knob.

The default of the knob is 1 sec (HZ), and even INT_MAX (24 days) is too high for RDS reconnect.

Quoted 5 lines

4. Since milliseconds to jiffies should be capped at MAX_JIFFY_OFFSET for big values. Should we just return MAX_JIFFY_OFFSET? Like this:

Quoted 10 lines
    diff --git i/kernel/time/jiffies.c w/kernel/time/jiffies.c
    index 213ae1d6a014..400353b0d6f9 100644
    --- i/kernel/time/jiffies.c
    +++ w/kernel/time/jiffies.c
    @@ -136,6 +136,8 @@ static int sysctl_k2u_int_conv_userhz(bool *negp, ulong *u_ptr, const int *k_ptr

     static ulong sysctl_msecs_to_jiffies(const ulong val)
     {
    +       if (val > UINT_MAX)
    +               return MAX_JIFFY_OFFSET;

Given the nit at 2., it should be like this

if (val > jiffies_to_msecs(MAX_JIFFY_OFFSET))

    return MAX_JIFFY_OFFSET;
Quoted 6 lines
Quoted 1 line

as done in _msecs_to_jiffies().

That is even better.

Please send a V2 of the 3 fixes discussed and I'll push them through next week.

I have created [1] to test the fixes before pushing it upstream. If you are ok with all my changes contained in [1], there is no need to send V2. But if you want to change something, do send it out.

Best

[1] https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/log/?h=jag/sysctl-fixes

#12 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 90 lines · Joel Granados
Quoted 88 lines · Joel Granados
Quoted 86 lines · Kuniyuki Iwashima
Quoted 20 lines · Joel Granados
Quoted 18 lines · Kuniyuki Iwashima
Quoted 16 lines · Joel Granados
Quoted 9 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

Quoted 8 lines
Quoted 5 lines

I guess people wanted to use ulong just because jiffies is unsigned long.

Looking at these users, none of them need the ulong range and it can be u32 actually.

Exactly. But changing those calls from ulong to uint is up to net and parport.

Agreed, it should be done in the -next branch of each subsystem.

And later, we can remove do_proc_ulong_conv_ms_jiffies().

Quoted 6 lines

I'm more interested in defining the behavior in
sysctl_u2k_ulong_conv_ms.

Here is my train of thought:
1. u64 values will get truncated when they pass through msecs_to_jiffies

Quoted 6 lines

2. The range of msecs_to_jiffies is:
[0, INT_MAX] ---> ceil(m × HZ / 1000)
[INT_MAX+1, UINT_MAX] ---> MAX_JIFFY_OFFSET

Which I interpret as whatever that falls out of [0, INT_MAX] milliseconds is just infinite jiffies (MAX_JIFFY_OFFSET).

nit: for HZ > 1000 (IIRC up to 1200 ?), the max of the range gets a little bit smaller.

Quoted 4 lines

3. All but one users of do_proc_ulong_conv_ms_jiffies are bound to values under MAX_JIFFY_OFFSET. The exception is net/rds/sysctl.c:67 that has a max of ~0UL (is this too high?).

I think this is just set as the theoretical max of @jiffies, but not specifically for the knob.

The default of the knob is 1 sec (HZ), and even INT_MAX (24 days) is too high for RDS reconnect.

Quoted 5 lines

4. Since milliseconds to jiffies should be capped at MAX_JIFFY_OFFSET for big values. Should we just return MAX_JIFFY_OFFSET? Like this:

Quoted 10 lines
    diff --git i/kernel/time/jiffies.c w/kernel/time/jiffies.c
    index 213ae1d6a014..400353b0d6f9 100644
    --- i/kernel/time/jiffies.c
    +++ w/kernel/time/jiffies.c
    @@ -136,6 +136,8 @@ static int sysctl_k2u_int_conv_userhz(bool *negp, ulong *u_ptr, const int *k_ptr

     static ulong sysctl_msecs_to_jiffies(const ulong val)
     {
    +       if (val > UINT_MAX)
    +               return MAX_JIFFY_OFFSET;

Given the nit at 2., it should be like this

if (val > jiffies_to_msecs(MAX_JIFFY_OFFSET))

    return MAX_JIFFY_OFFSET;

as done in _msecs_to_jiffies().

Quoted 8 lines
Quoted 4 lines

That is even better.

Please send a V2 of the 3 fixes discussed and I'll push them through next week.

I have created [1] to test the fixes before pushing it upstream. If you are ok with all my changes contained in [1], there is no need to send V2. But if you want to change something, do send it out.

Patch 2 has a typo "incorrectlry", but otherwise looks good to me. Feel free to push them with it fixed.

Thanks !

Quoted 6 lines

Best

[1] https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/log/?h=jag/sysctl-fixes

#13 lore raw

Re: [PATCH 2/2] sysctl: Make proc_doulongvec_ms_jiffies_minmax() enforce minmax again.

Quoted 93 lines · Kuniyuki Iwashima
Quoted 92 lines · Joel Granados
Quoted 90 lines · Joel Granados
Quoted 80 lines · Kuniyuki Iwashima
Quoted 20 lines · Joel Granados
Quoted 18 lines · Kuniyuki Iwashima
Quoted 16 lines · Joel Granados
Quoted 9 lines · Kuniyuki Iwashima

Since the cited commit changed proc_doulongvec_ms_jiffies_minmax() to use proc_ulong_conv(), proc_doulongvec_ms_jiffies_minmax() no longer applies the range check.

It happened probably because do_proc_ulong_conv_ms_jiffies() does not have the _minmax suffix.

In addition, sysctl_msecs_to_jiffies() casts u64 user input to u32, and a truncated value could bypass the max check.

This is something that is orthogonal to changing to true in the proc_ulong_conv call. Please put this in its own commit.

This also begs the question: why not just use an int converter if the range of the values is going to be u32?

Quoted 8 lines
Quoted 5 lines

I guess people wanted to use ulong just because jiffies is unsigned long.

Looking at these users, none of them need the ulong range and it can be u32 actually.

Exactly. But changing those calls from ulong to uint is up to net and parport.

Agreed, it should be done in the -next branch of each subsystem.

And later, we can remove do_proc_ulong_conv_ms_jiffies().

Quoted 6 lines

I'm more interested in defining the behavior in
sysctl_u2k_ulong_conv_ms.

Here is my train of thought:
1. u64 values will get truncated when they pass through msecs_to_jiffies

Quoted 6 lines

2. The range of msecs_to_jiffies is:
[0, INT_MAX] ---> ceil(m × HZ / 1000)
[INT_MAX+1, UINT_MAX] ---> MAX_JIFFY_OFFSET

Which I interpret as whatever that falls out of [0, INT_MAX] milliseconds is just infinite jiffies (MAX_JIFFY_OFFSET).

nit: for HZ > 1000 (IIRC up to 1200 ?), the max of the range gets a little bit smaller.

Quoted 4 lines

3. All but one users of do_proc_ulong_conv_ms_jiffies are bound to values under MAX_JIFFY_OFFSET. The exception is net/rds/sysctl.c:67 that has a max of ~0UL (is this too high?).

I think this is just set as the theoretical max of @jiffies, but not specifically for the knob.

The default of the knob is 1 sec (HZ), and even INT_MAX (24 days) is too high for RDS reconnect.

Quoted 5 lines

4. Since milliseconds to jiffies should be capped at MAX_JIFFY_OFFSET for big values. Should we just return MAX_JIFFY_OFFSET? Like this:

Quoted 10 lines
    diff --git i/kernel/time/jiffies.c w/kernel/time/jiffies.c
    index 213ae1d6a014..400353b0d6f9 100644
    --- i/kernel/time/jiffies.c
    +++ w/kernel/time/jiffies.c
    @@ -136,6 +136,8 @@ static int sysctl_k2u_int_conv_userhz(bool *negp, ulong *u_ptr, const int *k_ptr

     static ulong sysctl_msecs_to_jiffies(const ulong val)
     {
    +       if (val > UINT_MAX)
    +               return MAX_JIFFY_OFFSET;
Quoted 6 lines

Given the nit at 2., it should be like this

if (val > jiffies_to_msecs(MAX_JIFFY_OFFSET))

    return MAX_JIFFY_OFFSET;

as done in _msecs_to_jiffies().

That is even better.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Please send a V2 of the 3 fixes discussed and I'll push them through next week.

I have created [1] to test the fixes before pushing it upstream. If you are ok with all my changes contained in [1], there is no need to send V2. But if you want to change something, do send it out.

Patch 2 has a typo "incorrectlry", but otherwise looks good to me.

Will adjust

Quoted 1 line

Feel free to push them with it fixed.

Thx for the bugfixes!!