Skip to contentSkip to conversation

jfs: fix array-index-out-of-bounds in diAlloc

PATCH Superseded Manas Ghandat 2 participants 3 messages Sep 26, 2023 – Oct 3, 2023 JFS filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jfs: fix array-index-out-of-bounds in diAlloc

Currently there is not check against the agno of the iag while allocating new inodes to avoid fragmentation problem. Added the check which is required.

---
 fs/jfs/jfs_imap.c | 2 ++
 1 file changed, 2 insertions(+)
fs/jfs/jfs_imap.c +2 -0
index 799d3837e7c2..ace8a1506380 100644
@@ -1355,6 +1355,8 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)
 
 	/* get the ag number of this iag */
 	agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb));
+	if (agno < 0)
+		return -EIO;
 
 	if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {
 		/*
Signature · 6 lines
2.37.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw

just a friendly ping

Quoted 14 lines · Manas Ghandat

Currently there is not check against the agno of the iag while allocating new inodes to avoid fragmentation problem. Added the check which is required.

---
  fs/jfs/jfs_imap.c | 2 ++
  1 file changed, 2 insertions(+)
fs/jfs/jfs_imap.c +0 -0
index 799d3837e7c2..ace8a1506380 100644

fs/jfs/jfs_imap.c int diAlloc(struct inode *pip, bool dir, struct inode *ip) · line 1362

Quoted 8 lines
fs/jfs/jfs_imap.c +2 -0
@@ -1355,6 +1355,8 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)
 
  	/* get the ag number of this iag */
  	agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb));
+	if (agno < 0)
+		return -EIO;
 
  	if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {
  		/*

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#2 lore raw
In reply to Manas Ghandat
Quoted 3 lines · Manas Ghandat

Currently there is not check against the agno of the iag while allocating new inodes to avoid fragmentation problem. Added the check which is required.

Does this fix an observed problem? It seems reasonable and if we add this we may also want to make sure that agno doesn't exceed db_numag, (JFS_SBI(pip->i_sb)->bmap->db_numag) (yuck).

Quoted 11 lines
---
  fs/jfs/jfs_imap.c | 2 ++
  1 file changed, 2 insertions(+)
fs/jfs/jfs_imap.c +0 -0
index 799d3837e7c2..ace8a1506380 100644

fs/jfs/jfs_imap.c int diAlloc(struct inode *pip, bool dir, struct inode *ip) · line 1362

Quoted 8 lines
fs/jfs/jfs_imap.c +2 -0
@@ -1355,6 +1355,8 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)
 
  	/* get the ag number of this iag */
  	agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb));
+	if (agno < 0)
+		return -EIO;
 
  	if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {
  		/*

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees