mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: caius.zone@icloud.com
To: phillip@squashfs.org.uk
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Caius Zone <zone@ai-sast.com>
Subject: [PATCH] squashfs: fix NULL pointer dereference in bio_alloc_clone failure path
Date: Thu, 15 May 2025 20:01:54 +0800	[thread overview]
Message-ID: <20250515120154.1658556-1-caius.zone@icloud.com> (raw)

From: Caius Zone <zone@ai-sast.com>

bio_alloc_clone() may return NULL under memory pressure. The current code
does not check its return value, which may lead to a NULL pointer dereference
in bio_chain() or other bio operations.

Add a NULL check and return -ENOMEM if allocation fails.

Signed-off-by: Caius Zone <zone@ai-sast.com>
---
 fs/squashfs/block.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index 2dc730800f44..b00a71f8933c 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -115,6 +115,9 @@ static int squashfs_bio_read_cached(struct bio *fullbio,
 			struct bio *new = bio_alloc_clone(bdev, fullbio,
 							  GFP_NOIO, &fs_bio_set);
 
+			if (!new)
+				return -ENOMEM;
+
 			if (bio) {
 				bio_trim(bio, start_idx * PAGE_SECTORS,
 					 (end_idx - start_idx) * PAGE_SECTORS);
-- 
2.25.1


             reply	other threads:[~2025-05-15 12:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15 12:01 caius.zone [this message]
2025-05-15 12:41 ` Matthew Wilcox

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=20250515120154.1658556-1-caius.zone@icloud.com \
    --to=caius.zone@icloud.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip@squashfs.org.uk \
    --cc=zone@ai-sast.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®