From: Matthew Wilcox <willy@infradead.org>
To: caius.zone@icloud.com
Cc: phillip@squashfs.org.uk, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, Caius Zone <zone@ai-sast.com>
Subject: Re: [PATCH] squashfs: fix NULL pointer dereference in bio_alloc_clone failure path
Date: Thu, 15 May 2025 13:41:26 +0100 [thread overview]
Message-ID: <aCXg9t1QWR5jgpqX@casper.infradead.org> (raw)
In-Reply-To: <20250515120154.1658556-1-caius.zone@icloud.com>
On Thu, May 15, 2025 at 08:01:54PM +0800, caius.zone@icloud.com wrote:
> 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);
This is definitely wrong. The check for 'new' being NULL should be
after the submit_bio() otherwise we'll leak the previous bio.
But then we need to not call bio_chain() ... so I think this ends up
looking like:
@@ -115,12 +115,15 @@ static int squashfs_bio_read_cached(struct bio *fullbio,
struct bio *new = bio_alloc_clone(bdev, fullbio,
GFP_NOIO, &fs_bio_set);
+ if (new)
+ bio_chain(bio, new);
if (bio) {
bio_trim(bio, start_idx * PAGE_SECTORS,
(end_idx - start_idx) * PAGE_SECTORS);
- bio_chain(bio, new);
submit_bio(bio);
}
+ if (!new)
+ return -ENOMEM;
bio = new;
start_idx = idx;
... but that might not be right either. We might need to break out of
the loop, rather than returning and do the submit_bio_wait() followed by
the bio_put().
prev parent reply other threads:[~2025-05-15 12:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 12:01 caius.zone
2025-05-15 12:41 ` Matthew Wilcox [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=aCXg9t1QWR5jgpqX@casper.infradead.org \
--to=willy@infradead.org \
--cc=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®