From: Muhammad Mahdi Amirpour <ampr.mhd@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Muhammad Mahdi Amirpour <ampr.mhd@gmail.com>
Subject: [PATCH] fs/ufs: return early from ufs_free_fragments on invalid input
Date: Wed, 7 Oct 2026 14:52:25 +0330 [thread overview]
Message-ID: <20261007112225.91127-1-ampr.mhd@gmail.com> (raw)
The check for an out-of-range fragment count in ufs_free_fragments()
only calls ufs_error(), which marks the filesystem read-only but does
not return. Execution then continues with the invalid fragment and
count values.
The sibling function ufs_free_blocks() performs an equivalent check
and bails out via goto failed. Mirror that behaviour here so that a
corrupt image cannot push the code past the check into paths that
assume the invariant holds.
No functional change for valid inputs.
Signed-off-by: Muhammad Mahdi Amirpour <ampr.mhd@gmail.com>
---
fs/ufs/balloc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 628edfde3..377ba77fb 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -73,8 +73,12 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
UFSD("ENTER, fragment %llu, count %u\n",
(unsigned long long)fragment, count);
- if (ufs_fragnum(fragment) + count > uspi->s_fpb)
- ufs_error (sb, "ufs_free_fragments", "internal error");
+ if (ufs_fragnum(fragment) + count > uspi->s_fpb) {
+ ufs_error(sb, "ufs_free_fragments",
+ "invalid fragment %llu, count %u",
+ (unsigned long long)fragment, count);
+ return;
+ }
mutex_lock(&UFS_SB(sb)->s_lock);
--
2.55.0
reply other threads:[~2026-10-07 11:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261007112225.91127-1-ampr.mhd@gmail.com \
--to=ampr.mhd@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--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®