mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Phillip Lougher <phillip@squashfs.org.uk>
To: Peng Hao <flyingpenghao@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] fs/squashfs: handle possible null pointer
Date: Wed, 22 Dec 2021 01:38:28 +0000	[thread overview]
Message-ID: <91a4bb22-0144-f8d8-86be-62c593e77cb6@squashfs.org.uk> (raw)
In-Reply-To: <20211221020347.46021-1-flyingpeng@tencent.com>

On 21/12/2021 02:03, Peng Hao wrote:
>   in squashfs_fill_super:
> 
>          msblk->decompressor = supported_squashfs_filesystem(
>                          fc,
>                          le16_to_cpu(sblk->s_major),
>                          le16_to_cpu(sblk->s_minor),
>                          le16_to_cpu(sblk->compression));
>          if (msblk->decompressor == NULL)
>                  goto failed_mount;
>          ...
> 
> failed_mount:
> 	...
> 	squashfs_decompressor_destroy(msblk);
> 
> in squashfs_decompressor_destroy:
> 	if (stream) {
>          	msblk->decompressor->free(stream->stream);
> msblk->decompressor is NULL.
> 
> so add a judgment whether a null pointer.

NACK.

The NULL pointer dereference (msblk->decompressor) will not happen 
because stream (msblk->stream) is NULL (thus the code in question will 
not be executed).

At the start of the initialisation phase msblk is zeroed out

	sb->s_fs_info = kzalloc(sizeof(*msblk), GFP_KERNEL);
	if (sb->s_fs_info == NULL) {
		ERROR("Failed to allocate squashfs_sb_info\n");
		return -ENOMEM;
	}
	msblk = sb->s_fs_info;

Making msblk->decompressor and msblk->stream NULL.

msblk->decompressor is allocated first

	msblk->decompressor = supported_squashfs_filesystem(
			fc,
			le16_to_cpu(sblk->s_major),
			le16_to_cpu(sblk->s_minor),
			le16_to_cpu(sblk->compression));
	if (msblk->decompressor == NULL)
		goto failed_mount;

If that succeeds (msblk->decompressor != NULL), then msblk->stream is 
allocated

	msblk->stream = squashfs_decompressor_setup(sb, flags);
	if (IS_ERR(msblk->stream)) {
		err = PTR_ERR(msblk->stream);
		msblk->stream = NULL;
		goto insanity;
	}

Thus, in squashfs_decompressor_destroy() if stream (msblk->stream) is 
not NULL, then msblk->decompressor is also guaranteed to be not NULL.

Likewise if msblk->decompressor is NULL, then msblk->stream will also be 
NULL.

Or to put it another way, the decompressor is only destroyed if it was 
previously created (msblk->stream != NULL), and it will only have been 
created if msblk->decompressor is != NULL.

Phillip


      reply	other threads:[~2021-12-22  1:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21  2:03 Peng Hao
2021-12-22  1:38 ` 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=91a4bb22-0144-f8d8-86be-62c593e77cb6@squashfs.org.uk \
    --to=phillip@squashfs.org.uk \
    --cc=flyingpenghao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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®