Re: [PATCH v4] sysctl: move the extra1/2 boundary check of u8 to sysctl_check_table_array

From: Joel Granados
Date: Fri May 03 2024 - 09:20:14 EST


On Fri, Apr 19, 2024 at 11:36:39AM +0800, Wen Yang wrote:
> Move boundary checking for proc_dou8ved_minmax into module loading, thereby
> reporting errors in advance. And add a kunit test case ensuring the
> boundary check is done correctly.
>
...
> + KUNIT_CASE(sysctl_test_register_sysctl_sz_invalid_extra_value),
> {}
> };
>
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index e0b917328cf9..c0a1164eaf59 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -977,16 +977,10 @@ int proc_dou8vec_minmax(struct ctl_table *table, int write,
> if (table->maxlen != sizeof(u8))
> return -EINVAL;
>
> - if (table->extra1) {
> + if (table->extra1)
> min = *(unsigned int *) table->extra1;
> - if (min > 255U)
> - return -EINVAL;
> - }
> - if (table->extra2) {
> + if (table->extra2)
> max = *(unsigned int *) table->extra2;
> - if (max > 255U)
> - return -EINVAL;
> - }
>
> tmp = *table;
>
> --
> 2.25.1
>

Queueing this up for 6.11. I'll put it into sysclt-testing.

Reviewed-by: Joel Granados <j.granados@xxxxxxxxxxx>
--

Joel Granados

Attachment: signature.asc
Description: PGP signature