diff mbox

[v4,2/6] proc/sysctl: Check for invalid flags bits

Message ID 1520885744-1546-3-git-send-email-longman@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Waiman Long March 12, 2018, 8:15 p.m. UTC
Checking code is added to check for invalid flags in the ctl_table
and return error if an unknown flag is used.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 fs/proc/proc_sysctl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Luis Chamberlain March 12, 2018, 8:46 p.m. UTC | #1
On Mon, Mar 12, 2018 at 04:15:40PM -0400, Waiman Long wrote:
> Checking code is added to check for invalid flags in the ctl_table
> and return error if an unknown flag is used.

This should be merged with the first patch otherwise there are atomic
points in time on the commit log history where invalid values are allowed
and that makes no sense.

This can probably be expanded to verify semantics further. Details
below.
> 
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  fs/proc/proc_sysctl.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> index 493c975..67c0c82 100644
> --- a/fs/proc/proc_sysctl.c
> +++ b/fs/proc/proc_sysctl.c
> @@ -1092,6 +1092,16 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
>  	return err;
>  }
>  
> +static int sysctl_check_flags(const char *path, struct ctl_table *table)
> +{
> +	int err = 0;
> +
> +	if (table->flags & ~CTL_TABLE_FLAGS_ALL)
> +		err = sysctl_err(path, table, "invalid flags");

What if a range for the upper limit is set but not the lower limit and
the user goes over the lower limit?

How about the inverse?

Do we need both ranges set?

  Luis
Andrew Morton March 12, 2018, 8:52 p.m. UTC | #2
On Mon, 12 Mar 2018 16:15:40 -0400 Waiman Long <longman@redhat.com> wrote:

> Checking code is added to check for invalid flags in the ctl_table
> and return error if an unknown flag is used.

Why?  What's wrong with the old code, what value does this change add,
etc.
Waiman Long March 12, 2018, 8:54 p.m. UTC | #3
On 03/12/2018 04:46 PM, Luis R. Rodriguez wrote:
> On Mon, Mar 12, 2018 at 04:15:40PM -0400, Waiman Long wrote:
>> Checking code is added to check for invalid flags in the ctl_table
>> and return error if an unknown flag is used.
> This should be merged with the first patch otherwise there are atomic
> points in time on the commit log history where invalid values are allowed
> and that makes no sense.
>
> This can probably be expanded to verify semantics further. Details
> below.
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> ---
>>  fs/proc/proc_sysctl.c | 12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>>
>> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
>> index 493c975..67c0c82 100644
>> --- a/fs/proc/proc_sysctl.c
>> +++ b/fs/proc/proc_sysctl.c
>> @@ -1092,6 +1092,16 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
>>  	return err;
>>  }
>>  
>> +static int sysctl_check_flags(const char *path, struct ctl_table *table)
>> +{
>> +	int err = 0;
>> +
>> +	if (table->flags & ~CTL_TABLE_FLAGS_ALL)
>> +		err = sysctl_err(path, table, "invalid flags");
> What if a range for the upper limit is set but not the lower limit and
> the user goes over the lower limit?
>
> How about the inverse?
>
> Do we need both ranges set?
>
>   Luis

This check is just to make sure that no invalid flag bit is set. Range
clamping is just one of flag bits, though this is the only one currently
supported. In fact, it is allowed that the minimum or maximum can be
left unspecified. In this case, no minimum or maximum checking will be
done. So I don't see anything related to range checking should be put here.

Cheers,
Longman
Luis Chamberlain March 12, 2018, 8:59 p.m. UTC | #4
On Mon, Mar 12, 2018 at 04:54:51PM -0400, Waiman Long wrote:
> On 03/12/2018 04:46 PM, Luis R. Rodriguez wrote:
> > On Mon, Mar 12, 2018 at 04:15:40PM -0400, Waiman Long wrote:
> >> Checking code is added to check for invalid flags in the ctl_table
> >> and return error if an unknown flag is used.
> > This should be merged with the first patch otherwise there are atomic
> > points in time on the commit log history where invalid values are allowed
> > and that makes no sense.
> >
> > This can probably be expanded to verify semantics further. Details
> > below.
> >> Signed-off-by: Waiman Long <longman@redhat.com>
> >> ---
> >>  fs/proc/proc_sysctl.c | 12 ++++++++++++
> >>  1 file changed, 12 insertions(+)
> >>
> >> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> >> index 493c975..67c0c82 100644
> >> --- a/fs/proc/proc_sysctl.c
> >> +++ b/fs/proc/proc_sysctl.c
> >> @@ -1092,6 +1092,16 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
> >>  	return err;
> >>  }
> >>  
> >> +static int sysctl_check_flags(const char *path, struct ctl_table *table)
> >> +{
> >> +	int err = 0;
> >> +
> >> +	if (table->flags & ~CTL_TABLE_FLAGS_ALL)
> >> +		err = sysctl_err(path, table, "invalid flags");
> > What if a range for the upper limit is set but not the lower limit and
> > the user goes over the lower limit?
> >
> > How about the inverse?
> >
> > Do we need both ranges set?
> >
> >   Luis
> 
> This check is just to make sure that no invalid flag bit is set. Range
> clamping is just one of flag bits, though this is the only one currently
> supported. In fact, it is allowed that the minimum or maximum can be
> left unspecified. In this case, no minimum or maximum checking will be
> done. So I don't see anything related to range checking should be put here.

What if minimum is greater than maximum?

  Luis
Waiman Long March 12, 2018, 9:02 p.m. UTC | #5
On 03/12/2018 04:59 PM, Luis R. Rodriguez wrote:
> On Mon, Mar 12, 2018 at 04:54:51PM -0400, Waiman Long wrote:
>> On 03/12/2018 04:46 PM, Luis R. Rodriguez wrote:
>>> On Mon, Mar 12, 2018 at 04:15:40PM -0400, Waiman Long wrote:
>>>> Checking code is added to check for invalid flags in the ctl_table
>>>> and return error if an unknown flag is used.
>>> This should be merged with the first patch otherwise there are atomic
>>> points in time on the commit log history where invalid values are allowed
>>> and that makes no sense.
>>>
>>> This can probably be expanded to verify semantics further. Details
>>> below.
>>>> Signed-off-by: Waiman Long <longman@redhat.com>
>>>> ---
>>>>  fs/proc/proc_sysctl.c | 12 ++++++++++++
>>>>  1 file changed, 12 insertions(+)
>>>>
>>>> diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
>>>> index 493c975..67c0c82 100644
>>>> --- a/fs/proc/proc_sysctl.c
>>>> +++ b/fs/proc/proc_sysctl.c
>>>> @@ -1092,6 +1092,16 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
>>>>  	return err;
>>>>  }
>>>>  
>>>> +static int sysctl_check_flags(const char *path, struct ctl_table *table)
>>>> +{
>>>> +	int err = 0;
>>>> +
>>>> +	if (table->flags & ~CTL_TABLE_FLAGS_ALL)
>>>> +		err = sysctl_err(path, table, "invalid flags");
>>> What if a range for the upper limit is set but not the lower limit and
>>> the user goes over the lower limit?
>>>
>>> How about the inverse?
>>>
>>> Do we need both ranges set?
>>>
>>>   Luis
>> This check is just to make sure that no invalid flag bit is set. Range
>> clamping is just one of flag bits, though this is the only one currently
>> supported. In fact, it is allowed that the minimum or maximum can be
>> left unspecified. In this case, no minimum or maximum checking will be
>> done. So I don't see anything related to range checking should be put here.
> What if minimum is greater than maximum?
>
>   Luis

Yes, you are right. That is a valid check. I am going to add that in the
next patch.

Cheers,
Longman
Waiman Long March 12, 2018, 10:12 p.m. UTC | #6
On 03/12/2018 04:52 PM, Andrew Morton wrote:
> On Mon, 12 Mar 2018 16:15:40 -0400 Waiman Long <longman@redhat.com> wrote:
>
>> Checking code is added to check for invalid flags in the ctl_table
>> and return error if an unknown flag is used.
> Why?  What's wrong with the old code, what value does this change add,
> etc.

This is an additional checking code requested by Luis.

Cheers,
Longman
Andrew Morton March 12, 2018, 10:42 p.m. UTC | #7
On Mon, 12 Mar 2018 18:12:47 -0400 Waiman Long <longman@redhat.com> wrote:

> On 03/12/2018 04:52 PM, Andrew Morton wrote:
> > On Mon, 12 Mar 2018 16:15:40 -0400 Waiman Long <longman@redhat.com> wrote:
> >
> >> Checking code is added to check for invalid flags in the ctl_table
> >> and return error if an unknown flag is used.
> > Why?  What's wrong with the old code, what value does this change add,
> > etc.
> 
> This is an additional checking code requested by Luis.

Readers of this patch will wish to know why it exists.  That doesn't
tell us!
diff mbox

Patch

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 493c975..67c0c82 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -1092,6 +1092,16 @@  static int sysctl_check_table_array(const char *path, struct ctl_table *table)
 	return err;
 }
 
+static int sysctl_check_flags(const char *path, struct ctl_table *table)
+{
+	int err = 0;
+
+	if (table->flags & ~CTL_TABLE_FLAGS_ALL)
+		err = sysctl_err(path, table, "invalid flags");
+
+	return err;
+}
+
 static int sysctl_check_table(const char *path, struct ctl_table *table)
 {
 	int err = 0;
@@ -1111,6 +1121,8 @@  static int sysctl_check_table(const char *path, struct ctl_table *table)
 		    (table->proc_handler == proc_doulongvec_ms_jiffies_minmax)) {
 			if (!table->data)
 				err |= sysctl_err(path, table, "No data");
+			if (table->flags)
+				err |= sysctl_check_flags(path, table);
 			if (!table->maxlen)
 				err |= sysctl_err(path, table, "No maxlen");
 			else