All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH]  fs/squashfs: handle possible null pointer
@ 2021-12-21  2:03 Peng Hao
  2021-12-22  1:38 ` Phillip Lougher
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Hao @ 2021-12-21  2:03 UTC (permalink / raw)
  To: phillip; +Cc: linux-kernel

 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.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 fs/squashfs/decompressor_single.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/squashfs/decompressor_single.c b/fs/squashfs/decompressor_single.c
index 4eb3d083d45e..a155452bbc54 100644
--- a/fs/squashfs/decompressor_single.c
+++ b/fs/squashfs/decompressor_single.c
@@ -54,7 +54,8 @@ void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
 	struct squashfs_stream *stream = msblk->stream;
 
 	if (stream) {
-		msblk->decompressor->free(stream->stream);
+		if (msblk->decompressor)
+			msblk->decompressor->free(stream->stream);
 		kfree(stream);
 	}
 }
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fs/squashfs: handle possible null pointer
  2021-12-21  2:03 [PATCH] fs/squashfs: handle possible null pointer Peng Hao
@ 2021-12-22  1:38 ` Phillip Lougher
  0 siblings, 0 replies; 2+ messages in thread
From: Phillip Lougher @ 2021-12-22  1:38 UTC (permalink / raw)
  To: Peng Hao; +Cc: linux-kernel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-22  1:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-21  2:03 [PATCH] fs/squashfs: handle possible null pointer Peng Hao
2021-12-22  1:38 ` Phillip Lougher

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.