From: Kyle Zeng <kylebot@openai.com>
To: jfs-discussion@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>,
Dave Kleikamp <shaggy@kernel.org>,
outbounddisclosures@openai.com, Kyle Zeng <kylebot@openai.com>,
stable@vger.kernel.org
Subject: [PATCH] jfs: validate active AG before updating db_active
Date: Thu, 11 Jun 2026 14:29:56 -0700 [thread overview]
Message-ID: <20260611212956.10206-1-kylebot@openai.com> (raw)
When an empty regular file is opened for write, jfs_open() tracks a
single active file per allocation group. The allocation group is derived
from ji->ixpxd, which is copied from the on-disk inode in
copy_from_dinode().
A corrupted image can set di_ixpxd to an address that maps beyond the
mounted bmap's db_numag. The existing code stores that unchecked result
in signed char active_ag and then uses it to index db_active[]. For
example, an AG value of 249 wraps to -7 before the atomic increment,
causing a write before db_active and corrupting adjacent struct bmap
state.
Compute the AG in an unsigned type and reject values outside db_numag
before storing active_ag or indexing db_active[]. dbMount() already
validates db_numag <= MAXAG, so accepted values fit in active_ag and in
the db_active[] array.
Fixes: d31b53e3cd06 ("JFS: Don't save agno in the inode")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.5
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
fs/jfs/file.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/fs/jfs/file.c b/fs/jfs/file.c
index 81556da507b9..6d5f336b7a19 100644
--- a/fs/jfs/file.c
+++ b/fs/jfs/file.c
@@ -38,6 +38,24 @@ int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
return rc ? -EIO : 0;
}
+static int jfs_get_active_ag(struct inode *inode, int *agp)
+{
+ struct jfs_inode_info *ji = JFS_IP(inode);
+ struct jfs_sb_info *sbi = JFS_SBI(inode->i_sb);
+ struct bmap *bmap = sbi->bmap;
+ u64 ag = BLKTOAG(addressPXD(&ji->ixpxd), sbi);
+
+ if (ag >= bmap->db_numag) {
+ jfs_error(inode->i_sb,
+ "inode %lu has invalid active ag %llu\n",
+ inode->i_ino, (unsigned long long)ag);
+ return -EIO;
+ }
+
+ *agp = ag;
+ return 0;
+}
+
static int jfs_open(struct inode *inode, struct file *file)
{
int rc;
@@ -63,11 +81,18 @@ static int jfs_open(struct inode *inode, struct file *file)
if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
(inode->i_size == 0)) {
struct jfs_inode_info *ji = JFS_IP(inode);
+ struct bmap *bmap;
+ int active_ag;
+
+ rc = jfs_get_active_ag(inode, &active_ag);
+ if (rc)
+ return rc;
+
spin_lock_irq(&ji->ag_lock);
if (ji->active_ag == -1) {
- struct jfs_sb_info *jfs_sb = JFS_SBI(inode->i_sb);
- ji->active_ag = BLKTOAG(addressPXD(&ji->ixpxd), jfs_sb);
- atomic_inc(&jfs_sb->bmap->db_active[ji->active_ag]);
+ bmap = JFS_SBI(inode->i_sb)->bmap;
+ ji->active_ag = active_ag;
+ atomic_inc(&bmap->db_active[active_ag]);
}
spin_unlock_irq(&ji->ag_lock);
}
--
2.43.0
next reply other threads:[~2026-06-11 21:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 21:29 Kyle Zeng [this message]
2026-06-12 9:45 ` kernel test robot
2026-06-12 10:51 ` kernel test robot
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=20260611212956.10206-1-kylebot@openai.com \
--to=kylebot@openai.com \
--cc=brauner@kernel.org \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=outbounddisclosures@openai.com \
--cc=shaggy@kernel.org \
--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
all inboxes | Powered by JetHome®