Re: [PATCH] kernel/sysctl-test: Fix potential null dereference in sysctl-test
From: Joel Granados
Date: Mon Jan 13 2025 - 08:47:51 EST
On Fri, Jan 10, 2025 at 06:07:48PM +0800, Charles Han wrote:
> kunit_kzalloc() may return a NULL pointer, dereferencing it without
> NULL check may lead to NULL dereference.
> Add a NULL check for buffer.
Please address the 0-day comments.
>
> Fixes: 2cb80dbbbaba ("kernel/sysctl-test: Add null pointer test for sysctl.c:proc_dointvec()")
> Signed-off-by: Charles Han <hanchunchao@xxxxxxxxxx>
> ---
...
> unsigned long abs_of_less_than_min = (unsigned long)INT_MAX
> - (INT_MAX + INT_MIN) + 1;
> @@ -354,6 +363,7 @@ static void sysctl_test_api_dointvec_write_single_greater_int_max(
> size_t max_len = 32, len = max_len;
> loff_t pos = 0;
> char *buffer = kunit_kzalloc(test, max_len, GFP_USER);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buffer);
> char __user *user_buffer = (char __user *)buffer;
> unsigned long greater_than_max = (unsigned long)INT_MAX + 1;
>
> --
> 2.45.2
>
best
--
Joel Granados