mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Phillip Lougher <phillip@squashfs.org.uk>
To: Zhiyu Zhang <zhiyuzhang999@gmail.com>, akpm@linux-foundation.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] squashfs: Fix invalid pointer dereference in squashfs_cache_delete
Date: Thu, 6 Mar 2025 14:09:40 +0000	[thread overview]
Message-ID: <ae31e0a6-7cea-4f76-824c-d8f5ae97c101@squashfs.org.uk> (raw)
In-Reply-To: <20250306132855.2030-1-zhiyuzhang999@gmail.com>



On 06/03/2025 13:28, Zhiyu Zhang wrote:
> When mounting a squashfs fails, squashfs_cache_init() may return an error
> pointer (e.g., -ENOMEM) instead of NULL. However, squashfs_cache_delete()
> only checks for a NULL cache, and attempts to dereference the invalid
> pointer. This leads to a kernel crash (BUG: unable to handle kernel paging
> request in squashfs_cache_delete).
> 
> This patch fixes the issue by checking IS_ERR(cache) before accessing it.
> 
> Fixes: 49ff29240ebb ("squashfs: make squashfs_cache_init() return ERR_PTR(-ENOMEM)")
> Reported-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
> Closes: https://lore.kernel.org/linux-fsdevel/CALf2hKvaq8B4u5yfrE+BYt7aNguao99mfWxHngA+=o5hwzjdOg@mail.gmail.com/
> Tested-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
> Signed-off-by: Zhiyu Zhang <zhiyuzhang999@gmail.com>
> ---
>   fs/squashfs/cache.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
> index 4db0d2b0aab8..181260e72680 100644
> --- a/fs/squashfs/cache.c
> +++ b/fs/squashfs/cache.c
> @@ -198,7 +198,7 @@ void squashfs_cache_delete(struct squashfs_cache *cache)
>   {
>   	int i, j;
>   
> -	if (cache == NULL)
> +	if (IS_ERR(cache) || cache == NULL)
>   		return;
>   
>   	for (i = 0; i < cache->entries; i++) {

Looks good to me.

Reviewed-by: Phillip Lougher <phillip@squashfs.org.uk>

      reply	other threads:[~2025-03-06 14:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-06 13:28 Zhiyu Zhang
2025-03-06 14:09 ` Phillip Lougher [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae31e0a6-7cea-4f76-824c-d8f5ae97c101@squashfs.org.uk \
    --to=phillip@squashfs.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhiyuzhang999@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®