All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: + sysctl-return-einval-if-val-violates-minmax.patch added to -mm tree
       [not found] <20190211210632.Nfd0f%akpm@linux-foundation.org>
@ 2019-02-11 21:17 ` Alexey Dobriyan
  2019-02-11 21:19   ` Christian Brauner
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Dobriyan @ 2019-02-11 21:17 UTC (permalink / raw)
  To: akpm
  Cc: linux-kernel, viro, mcgrof, longman, linux, keescook,
	joe.lawrence, ebiederm, christian

On Mon, Feb 11, 2019 at 01:06:32PM -0800, akpm@linux-foundation.org wrote:

> @@ -2848,8 +2848,10 @@ static int __do_proc_doulongvec_minmax(v

> -			if ((min && val < *min) || (max && val > *max))
> -				continue;
> +			if ((min && val < *min) || (max && val > *max)) {
> +				err = -EINVAL;

I was asked to return ERANGE in kstrto*().
If nothing, it gives better error message:

	$ ./a.out
	foo: Numerical result out of range

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: + sysctl-return-einval-if-val-violates-minmax.patch added to -mm tree
  2019-02-11 21:17 ` + sysctl-return-einval-if-val-violates-minmax.patch added to -mm tree Alexey Dobriyan
@ 2019-02-11 21:19   ` Christian Brauner
  2019-02-11 21:25     ` Luis Chamberlain
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Brauner @ 2019-02-11 21:19 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: akpm, linux-kernel, viro, mcgrof, longman, linux, keescook,
	joe.lawrence, ebiederm

On Tue, Feb 12, 2019 at 12:17:16AM +0300, Alexey Dobriyan wrote:
> On Mon, Feb 11, 2019 at 01:06:32PM -0800, akpm@linux-foundation.org wrote:
> 
> > @@ -2848,8 +2848,10 @@ static int __do_proc_doulongvec_minmax(v
> 
> > -			if ((min && val < *min) || (max && val > *max))
> > -				continue;
> > +			if ((min && val < *min) || (max && val > *max)) {
> > +				err = -EINVAL;
> 
> I was asked to return ERANGE in kstrto*().

I think we discussed ERANGE vs EINVAL and decided EINVAL because there
was precedence for other sysctls already.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: + sysctl-return-einval-if-val-violates-minmax.patch added to -mm tree
  2019-02-11 21:19   ` Christian Brauner
@ 2019-02-11 21:25     ` Luis Chamberlain
  2019-02-11 21:32       ` Christian Brauner
  0 siblings, 1 reply; 5+ messages in thread
From: Luis Chamberlain @ 2019-02-11 21:25 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Alexey Dobriyan, akpm, linux-kernel, viro, longman, linux,
	keescook, joe.lawrence, ebiederm, linux-api

On Mon, Feb 11, 2019 at 10:19:19PM +0100, Christian Brauner wrote:
> On Tue, Feb 12, 2019 at 12:17:16AM +0300, Alexey Dobriyan wrote:
> > On Mon, Feb 11, 2019 at 01:06:32PM -0800, akpm@linux-foundation.org wrote:
> > 
> > > @@ -2848,8 +2848,10 @@ static int __do_proc_doulongvec_minmax(v
> > 
> > > -			if ((min && val < *min) || (max && val > *max))
> > > -				continue;
> > > +			if ((min && val < *min) || (max && val > *max)) {
> > > +				err = -EINVAL;
> > 
> > I was asked to return ERANGE in kstrto*().
> 
> I think we discussed ERANGE vs EINVAL and decided EINVAL because there
> was precedence for other sysctls already.

Can you do a proper audit and see?

linux-api folks may care.

 Luis

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: + sysctl-return-einval-if-val-violates-minmax.patch added to -mm tree
  2019-02-11 21:25     ` Luis Chamberlain
@ 2019-02-11 21:32       ` Christian Brauner
  2019-02-11 21:41         ` Luis Chamberlain
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Brauner @ 2019-02-11 21:32 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: Alexey Dobriyan, akpm, linux-kernel, viro, longman, linux,
	keescook, joe.lawrence, ebiederm, linux-api

On Mon, Feb 11, 2019 at 01:25:23PM -0800, Luis Chamberlain wrote:
> On Mon, Feb 11, 2019 at 10:19:19PM +0100, Christian Brauner wrote:
> > On Tue, Feb 12, 2019 at 12:17:16AM +0300, Alexey Dobriyan wrote:
> > > On Mon, Feb 11, 2019 at 01:06:32PM -0800, akpm@linux-foundation.org wrote:
> > > 
> > > > @@ -2848,8 +2848,10 @@ static int __do_proc_doulongvec_minmax(v
> > > 
> > > > -			if ((min && val < *min) || (max && val > *max))
> > > > -				continue;
> > > > +			if ((min && val < *min) || (max && val > *max)) {
> > > > +				err = -EINVAL;
> > > 
> > > I was asked to return ERANGE in kstrto*().
> > 
> > I think we discussed ERANGE vs EINVAL and decided EINVAL because there
> > was precedence for other sysctls already.
> 
> Can you do a proper audit and see?

If you look at proc_get_long() right now you can see that when the
buffer we use to parse the number is exceeded we return EINVAL. In short
if you do right now:

echo 1844674407370955161600000 > /proc/sys/fs/file-max

that would exceed the buffer in proc_get_long() and you already get
EINVAL for all such cases. If we now change this to ERANGE we would
return:

echo 18446744073709551616      > /proc/sys/fs/file-max -> ERANGE
echo 1844674407370955161600000 > /proc/sys/fs/file-max -> EINVAL

which would be very confusing. For consistency we should use EINVAL.

See kernel/sysctl.c:

/* We don't know if the next char is whitespace thus we may accept
 * invalid integers (e.g. 1234...a) or two integers instead of one
 * (e.g. 123...1). So lets not allow such large numbers. */
if (len == TMPBUFLEN - 1)
        return -EINVAL;

Christian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: + sysctl-return-einval-if-val-violates-minmax.patch added to -mm tree
  2019-02-11 21:32       ` Christian Brauner
@ 2019-02-11 21:41         ` Luis Chamberlain
  0 siblings, 0 replies; 5+ messages in thread
From: Luis Chamberlain @ 2019-02-11 21:41 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Alexey Dobriyan, akpm, linux-kernel, viro, longman, linux,
	keescook, joe.lawrence, ebiederm, linux-api

On Mon, Feb 11, 2019 at 10:32:50PM +0100, Christian Brauner wrote:
> On Mon, Feb 11, 2019 at 01:25:23PM -0800, Luis Chamberlain wrote:
> > On Mon, Feb 11, 2019 at 10:19:19PM +0100, Christian Brauner wrote:
> > > On Tue, Feb 12, 2019 at 12:17:16AM +0300, Alexey Dobriyan wrote:
> > > > On Mon, Feb 11, 2019 at 01:06:32PM -0800, akpm@linux-foundation.org wrote:
> > > > 
> > > > > @@ -2848,8 +2848,10 @@ static int __do_proc_doulongvec_minmax(v
> > > > 
> > > > > -			if ((min && val < *min) || (max && val > *max))
> > > > > -				continue;
> > > > > +			if ((min && val < *min) || (max && val > *max)) {
> > > > > +				err = -EINVAL;
> > > > 
> > > > I was asked to return ERANGE in kstrto*().
> > > 
> > > I think we discussed ERANGE vs EINVAL and decided EINVAL because there
> > > was precedence for other sysctls already.
> > 
> > Can you do a proper audit and see?
> 
> If you look at proc_get_long() right now you can see that when the
> buffer we use to parse the number is exceeded we return EINVAL. In short
> if you do right now:
> 
> echo 1844674407370955161600000 > /proc/sys/fs/file-max
> 
> that would exceed the buffer in proc_get_long() and you already get
> EINVAL for all such cases. If we now change this to ERANGE we would
> return:
> 
> echo 18446744073709551616      > /proc/sys/fs/file-max -> ERANGE
> echo 1844674407370955161600000 > /proc/sys/fs/file-max -> EINVAL
> 
> which would be very confusing. For consistency we should use EINVAL.
> 
> See kernel/sysctl.c:
> 
> /* We don't know if the next char is whitespace thus we may accept
>  * invalid integers (e.g. 1234...a) or two integers instead of one
>  * (e.g. 123...1). So lets not allow such large numbers. */
> if (len == TMPBUFLEN - 1)
>         return -EINVAL;

Thanks this works for me.

  Luis

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-11 21:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20190211210632.Nfd0f%akpm@linux-foundation.org>
2019-02-11 21:17 ` + sysctl-return-einval-if-val-violates-minmax.patch added to -mm tree Alexey Dobriyan
2019-02-11 21:19   ` Christian Brauner
2019-02-11 21:25     ` Luis Chamberlain
2019-02-11 21:32       ` Christian Brauner
2019-02-11 21:41         ` Luis Chamberlain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.