lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <6dc540e0-7cae-44a5-995e-65a4a457b50d@squashfs.org.uk>
Date: Sat, 1 Feb 2025 00:30:36 +0000
From: Phillip Lougher <phillip@...ashfs.org.uk>
To: Jiasheng Jiang <jiashengjiangcool@...il.com>
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH] Squashfs: Add check for cache->entry to avoid NULL
 pointer dereference



On 1/31/25 20:24, Jiasheng Jiang wrote:
> Add a check for "cache->entry". Otherwise, if the allocation for
> "cache->entry" fails, "cache->entry[i].data" will cause a NULL pointer
> dereference.

NACK.

You're ignoring the i < cache->entries loop condition.

If cache->entries is > 0, then cache->entry is non-NULL.

If cache->entry is NULL, then cache->entries == 0, and the code is skipped.

In squashfs_cache_init() the cache structure is kzalloc'ed (all 0s).  If
allocation of cache->entry fails, then cache->entries is 0.

Phillip

> 
> Fixes: f400e12656ab ("Squashfs: cache operations")
> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@...il.com>
> ---
>   fs/squashfs/cache.c | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
> index 4db0d2b0aab8..5a3081583ea9 100644
> --- a/fs/squashfs/cache.c
> +++ b/fs/squashfs/cache.c
> @@ -201,16 +201,19 @@ void squashfs_cache_delete(struct squashfs_cache *cache)
>   	if (cache == NULL)
>   		return;
>   
> -	for (i = 0; i < cache->entries; i++) {
> -		if (cache->entry[i].data) {
> -			for (j = 0; j < cache->pages; j++)
> -				kfree(cache->entry[i].data[j]);
> -			kfree(cache->entry[i].data);
> +	if (cache->entry) {
> +		for (i = 0; i < cache->entries; i++) {
> +			if (cache->entry[i].data) {
> +				for (j = 0; j < cache->pages; j++)
> +					kfree(cache->entry[i].data[j]);
> +				kfree(cache->entry[i].data);
> +			}
> +			kfree(cache->entry[i].actor);
>   		}
> -		kfree(cache->entry[i].actor);
> +
> +		kfree(cache->entry);
>   	}
>   
> -	kfree(cache->entry);
>   	kfree(cache);
>   }
>   

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ