[PATCH 3/3] jfs: refuse inodes with a negative size
Christian Brauner
brauner at kernel.org
Mon Nov 16 01:28:32 PST 2026
copy_from_dinode() takes di_size as is and a crafted image can store a
size that is negative as a loff_t. For a symlink that passes the signed
i_size >= IDATASIZE test in jfs_iget(), so it's treated as a fast
symlink and i_link[i_size] = '\0' writes out of bounds. Refuse a
negative size when reading the inode like a corrupt dtroot.
Fixes: d69e83d99cf8 ("jfs: ensure symlinks are NUL-terminated")
Cc: stable at vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner at kernel.org>
---
fs/jfs/jfs_imap.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index b84ba4d7dfb44..f88e228d12620 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -3079,6 +3079,10 @@ static int copy_from_dinode(struct dinode * dip, struct inode *ip)
}
ip->i_size = le64_to_cpu(dip->di_size);
+ if (ip->i_size < 0) {
+ jfs_error(ip->i_sb, "Negative inode size\n");
+ return -EIO;
+ }
inode_set_atime(ip, le32_to_cpu(dip->di_atime.tv_sec),
le32_to_cpu(dip->di_atime.tv_nsec));
inode_set_mtime(ip, le32_to_cpu(dip->di_mtime.tv_sec),
--
2.53.0
More information about the linux-mtd
mailing list