* [PATCH] jfs: fix out-of-bounds in dbNextAG() and diAlloc()
@ 2024-08-19 4:05 Jeongjun Park
2024-08-23 19:18 ` Dave Kleikamp
0 siblings, 1 reply; 2+ messages in thread
From: Jeongjun Park @ 2024-08-19 4:05 UTC (permalink / raw)
To: shaggy, dave.kleikamp; +Cc: jfs-discussion, linux-kernel, Jeongjun Park
In dbNextAG() , there is no check for the case where bmp->db_numag is
greater or same than MAXAG due to a polluted image, which causes an
out-of-bounds. Therefore, a bounds check should be added in dbMount().
And in dbNextAG(), a check for the case where agpref is greater than
bmp->db_numag should be added, so an out-of-bounds exception should be
prevented.
Additionally, a check for the case where agno is greater or same than
MAXAG should be added in diAlloc() to prevent out-of-bounds.
Reported-by: Jeongjun Park <aha310510@gmail.com>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
fs/jfs/jfs_dmap.c | 4 ++--
fs/jfs/jfs_imap.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 5713994328cb..0625d1c0d064 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -187,7 +187,7 @@ int dbMount(struct inode *ipbmap)
}
bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
- if (!bmp->db_numag) {
+ if (!bmp->db_numag || bmp->db_numag >= MAXAG) {
err = -EINVAL;
goto err_release_metapage;
}
@@ -652,7 +652,7 @@ int dbNextAG(struct inode *ipbmap)
* average free space.
*/
for (i = 0 ; i < bmp->db_numag; i++, agpref++) {
- if (agpref == bmp->db_numag)
+ if (agpref >= bmp->db_numag)
agpref = 0;
if (atomic_read(&bmp->db_active[agpref]))
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index 1407feccbc2d..a360b24ed320 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -1360,7 +1360,7 @@ 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));
dn_numag = JFS_SBI(pip->i_sb)->bmap->db_numag;
- if (agno < 0 || agno > dn_numag)
+ if (agno < 0 || agno > dn_numag || agno >= MAXAG)
return -EIO;
if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {
--
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] jfs: fix out-of-bounds in dbNextAG() and diAlloc()
2024-08-19 4:05 [PATCH] jfs: fix out-of-bounds in dbNextAG() and diAlloc() Jeongjun Park
@ 2024-08-23 19:18 ` Dave Kleikamp
0 siblings, 0 replies; 2+ messages in thread
From: Dave Kleikamp @ 2024-08-23 19:18 UTC (permalink / raw)
To: Jeongjun Park; +Cc: jfs-discussion, linux-kernel
On 8/18/24 11:05PM, Jeongjun Park wrote:
> In dbNextAG() , there is no check for the case where bmp->db_numag is
> greater or same than MAXAG due to a polluted image, which causes an
> out-of-bounds. Therefore, a bounds check should be added in dbMount().
>
> And in dbNextAG(), a check for the case where agpref is greater than
> bmp->db_numag should be added, so an out-of-bounds exception should be
> prevented.
>
> Additionally, a check for the case where agno is greater or same than
> MAXAG should be added in diAlloc() to prevent out-of-bounds.
Looks good. Applied.
Shaggy
>
> Reported-by: Jeongjun Park <aha310510@gmail.com>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> ---
> fs/jfs/jfs_dmap.c | 4 ++--
> fs/jfs/jfs_imap.c | 2 +-
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
> index 5713994328cb..0625d1c0d064 100644
> --- a/fs/jfs/jfs_dmap.c
> +++ b/fs/jfs/jfs_dmap.c
> @@ -187,7 +187,7 @@ int dbMount(struct inode *ipbmap)
> }
>
> bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
> - if (!bmp->db_numag) {
> + if (!bmp->db_numag || bmp->db_numag >= MAXAG) {
> err = -EINVAL;
> goto err_release_metapage;
> }
> @@ -652,7 +652,7 @@ int dbNextAG(struct inode *ipbmap)
> * average free space.
> */
> for (i = 0 ; i < bmp->db_numag; i++, agpref++) {
> - if (agpref == bmp->db_numag)
> + if (agpref >= bmp->db_numag)
> agpref = 0;
>
> if (atomic_read(&bmp->db_active[agpref]))
> diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
> index 1407feccbc2d..a360b24ed320 100644
> --- a/fs/jfs/jfs_imap.c
> +++ b/fs/jfs/jfs_imap.c
> @@ -1360,7 +1360,7 @@ 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));
> dn_numag = JFS_SBI(pip->i_sb)->bmap->db_numag;
> - if (agno < 0 || agno > dn_numag)
> + if (agno < 0 || agno > dn_numag || agno >= MAXAG)
> return -EIO;
>
> if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {
> --
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-23 19:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-19 4:05 [PATCH] jfs: fix out-of-bounds in dbNextAG() and diAlloc() Jeongjun Park
2024-08-23 19:18 ` Dave Kleikamp
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®