linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Lougher <phillip@squashfs.org.uk>
To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Cc: hsinyi@chromium.org, regressions@leemhuis.info,
	regressions@lists.linux.dev, dimitri.ledkov@canonical.com,
	michael.vogt@canonical.com, phillip.lougher@gmail.com,
	ogra@ubuntu.com, olivier.tilloy@canonical.com,
	Phillip Lougher <phillip@squashfs.org.uk>,
	stable@vger.kernel.org
Subject: [PATCH 3/3] squashfs: fix buffer release race condition in readahead code
Date: Thu, 20 Oct 2022 23:36:16 +0100	[thread overview]
Message-ID: <20221020223616.7571-4-phillip@squashfs.org.uk> (raw)
In-Reply-To: <20221020223616.7571-1-phillip@squashfs.org.uk>

Fix a buffer release race condition, where the error value was
used after release.

Fixes: b09a7a036d20 ("squashfs: support reading fragments in readahead call")
Cc: <stable@vger.kernel.org>
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
---
 fs/squashfs/file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c
index f0afd4d6fd30..8ba8c4c50770 100644
--- a/fs/squashfs/file.c
+++ b/fs/squashfs/file.c
@@ -506,8 +506,9 @@ static int squashfs_readahead_fragment(struct page **page,
 		squashfs_i(inode)->fragment_size);
 	struct squashfs_sb_info *msblk = inode->i_sb->s_fs_info;
 	unsigned int n, mask = (1 << (msblk->block_log - PAGE_SHIFT)) - 1;
+	int error = buffer->error;
 
-	if (buffer->error)
+	if (error)
 		goto out;
 
 	expected += squashfs_i(inode)->fragment_offset;
@@ -529,7 +530,7 @@ static int squashfs_readahead_fragment(struct page **page,
 
 out:
 	squashfs_cache_put(buffer);
-	return buffer->error;
+	return error;
 }
 
 static void squashfs_readahead(struct readahead_control *ractl)
-- 
2.35.1


  parent reply	other threads:[~2022-10-20 22:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20 22:36 [0/3] squashfs: fix some regressions introduced in the readahead code Phillip Lougher
2022-10-20 22:36 ` [PATCH 1/3] squashfs: fix read regression introduced in " Phillip Lougher
2022-10-20 22:36 ` [PATCH 2/3] squashfs: fix extending readahead beyond end of file Phillip Lougher
2022-10-20 22:36 ` Phillip Lougher [this message]
2022-10-21 12:42 ` [0/3] squashfs: fix some regressions introduced in the readahead code Bagas Sanjaya
     [not found] ` <4493e774-ff23-e2a1-4aa7-28b190eb909d@alu.unizg.hr>
2022-10-22 22:56   ` Andrew Morton

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=20221020223616.7571-4-phillip@squashfs.org.uk \
    --to=phillip@squashfs.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=dimitri.ledkov@canonical.com \
    --cc=hsinyi@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.vogt@canonical.com \
    --cc=ogra@ubuntu.com \
    --cc=olivier.tilloy@canonical.com \
    --cc=phillip.lougher@gmail.com \
    --cc=regressions@leemhuis.info \
    --cc=regressions@lists.linux.dev \
    --cc=stable@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;
as well as URLs for NNTP newsgroup(s).