jfs: fix array-index-out-of-bounds
PATCH 1/1 jfs: fix array-index-out-of-bounds
In some cases, dn_numag may be greater than MAXAG which may result in an array-index-out-of-bounds in dbNextAG. Added a check to return an error code before we crash.
--- fs/jfs/jfs_imap.c | 3 +++ 1 file changed, 3 insertions(+)
fs/jfs/jfs_imap.c +3 -0
@@ -1360,6 +1360,9 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)if (agno <0 || agno > dn_numag)return -EIO ; +if (unlikely (dn_numag >MAXAG )) +return -EIO ; +if (atomic_read (&JFS_SBI (pip->i_sb)->bmap->db_active[agno])) {/* * There is an open file actively growing. We want to
Signature · 1 line
2.34.1
Le 22/09/2024 à 13:00, Ghanshyam Agrawal a écrit :
Quoted 16 lines
In some cases,
dn_numagmay be greater than MAXAG which may result in an array-index-out-of-bounds in dbNextAG. Added a check to return an error code before we crash.Reported-by [email protected]Signed-off-by Ghanshyam Agrawal <[email protected]>--- fs/jfs/jfs_imap.c | 3 +++ 1 file changed, 3 insertions(+)fs/jfs/jfs_imap.c +0
-0
fs/jfs/jfs_imap.c int diAlloc(struct inode *pip, bool dir, struct inode *ip) · line 1363
Quoted 4 lines
fs/jfs/jfs_imap.c +1
-0@@ -1360,6 +1360,9 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)if (agno <0 || agno > dn_numag)return -EIO ; +if (unlikely (dn_numag >MAXAG ))
Hi,
looking at other places with checks with MAXAG, I wonder if it should be >=?
CJ
Quoted 5 lines
fs/jfs/jfs_imap.c +2
-0+return -EIO ; +if (atomic_read (&JFS_SBI (pip->i_sb)->bmap->db_active[agno])) {/* * There is an open file actively growing. We want to
Quoted 21 lines · Christophe JAILLET
Quoted 19 lines · Ghanshyam Agrawal
In some cases,
dn_numagmay be greater than MAXAG which may result in an array-index-out-of-bounds in dbNextAG. Added a check to return an error code before we crash.Reported-by [email protected]Signed-off-by Ghanshyam Agrawal <[email protected]>--- fs/jfs/jfs_imap.c | 3 +++ 1 file changed, 3 insertions(+)fs/jfs/jfs_imap.c +0
-0@@ -1360,6 +1360,9 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)if (agno <0 || agno > dn_numag)return -EIO ;
Quoted 14 lines
fs/jfs/jfs_imap.c int diAlloc(struct inode *pip, bool dir, struct inode *ip) · line 1363
Quoted 1 line
fs/jfs/jfs_imap.c +1
-0+if (unlikely (dn_numag >MAXAG ))Hi,
looking at other places with checks with MAXAG, I wonder if it should be >=?
CJ
Quoted 5 lines
fs/jfs/jfs_imap.c +2
-0+return -EIO ; +if (atomic_read (&JFS_SBI (pip->i_sb)->bmap->db_active[agno])) {/* * There is an open file actively growing. We want to
Hello Christophe,
Thanks for reviewing my code. I believe the greater than symbol I have set is correct in this case. Can you please check it thoroughly and let me know wny it should be >= ?
Thanks & Regards,
Ghanshyam Agrawal
Le 23/09/2024 à 05:35, Ghanshyam Agrawal a écrit :
Quoted 38 lines
Quoted 21 lines · Christophe JAILLET
Quoted 19 lines · Ghanshyam Agrawal
In some cases,
dn_numagmay be greater than MAXAG which may result in an array-index-out-of-bounds in dbNextAG. Added a check to return an error code before we crash.Reported-by [email protected]Signed-off-by Ghanshyam Agrawal <[email protected]>--- fs/jfs/jfs_imap.c | 3 +++ 1 file changed, 3 insertions(+)fs/jfs/jfs_imap.c +0
-0@@ -1360,6 +1360,9 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)if (agno <0 || agno > dn_numag)return -EIO ;Quoted 14 lines
fs/jfs/jfs_imap.c int diAlloc(struct inode *pip, bool dir, struct inode *ip) · line 1363
Quoted 1 line
fs/jfs/jfs_imap.c +1
-0+if (unlikely (dn_numag >MAXAG ))Hi,
looking at other places with checks with MAXAG, I wonder if it should be >=?
CJ
Quoted 5 lines
fs/jfs/jfs_imap.c +2
-0+return -EIO ; +if (atomic_read (&JFS_SBI (pip->i_sb)->bmap->db_active[agno])) {/* * There is an open file actively growing. We want to
Quoted 4 lines
Hello Christophe,
Thanks for reviewing my code. I believe the greater than symbol I have set is correct in this case.
I think it's not.
If you have "if (unlikely(dn_numag > MAXAG))", then
- dn_numag can be = MAXAG
- [2] - so, agno can be = MAXAG as well
- [3] - and, accessing memory past the end of the array will happen,
because db_active is atomic_t db_active[MAXAG];
- BUG
Or I miss something obvious?
Quoted 1 line
Can you please check it thoroughly and letme know wny it should be >= ?
Well, usually things don't work that way.
YOU propose to fix something, which is nice. So YOU should explain why it is correct.
If I'm correct, the way to see that your fix is incomplete is just in the 3 or 4 lines just above and below your change.
You've been told what could be wrong, you could have checked yourself. Or explained the reasoning that makes you think it is correct.
Sorry if my answer looks rude, it is not my intend. I just read your answer as "can you do my home work for me", which is certainly not you intend either.
So, no hard felling, but a bit disappointed by the lack of curiosity.
CJ
Quoted 4 lines
Thanks & Regards,
Ghanshyam Agrawal
[1]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1363
[2]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1363
[3]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1366
Quoted 86 lines · Christophe JAILLET
Quoted 38 lines · Ghanshyam Agrawal
Quoted 21 lines · Christophe JAILLET
Quoted 19 lines · Ghanshyam Agrawal
In some cases,
dn_numagmay be greater than MAXAG which may result in an array-index-out-of-bounds in dbNextAG. Added a check to return an error code before we crash.Reported-by [email protected]Signed-off-by Ghanshyam Agrawal <[email protected]>--- fs/jfs/jfs_imap.c | 3 +++ 1 file changed, 3 insertions(+)fs/jfs/jfs_imap.c +0
-0@@ -1360,6 +1360,9 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)if (agno <0 || agno > dn_numag)return -EIO ;Quoted 14 lines
fs/jfs/jfs_imap.c int diAlloc(struct inode *pip, bool dir, struct inode *ip) · line 1363
Quoted 1 line
fs/jfs/jfs_imap.c +1
-0+if (unlikely (dn_numag >MAXAG ))Hi,
looking at other places with checks with MAXAG, I wonder if it should be >=?
CJ
Quoted 5 lines
fs/jfs/jfs_imap.c +2
-0+return -EIO ; +if (atomic_read (&JFS_SBI (pip->i_sb)->bmap->db_active[agno])) {/* * There is an open file actively growing. We want to Quoted 4 lines
Hello Christophe,
Thanks for reviewing my code. I believe the greater than symbol I have set is correct in this case.
I think it's not.
If you have "if (
unlikely(dn_numag > MAXAG))", then-
dn_numagcan be = MAXAG
- [2] - so, agno can be = MAXAG as well
- [3] - and, accessing memory past the end of the array will happen,
becausedb_activeisatomic_tdb_active[MAXAG];
- BUGOr I miss something obvious?
Quoted 1 line
Can you please check it thoroughly and letme know wny it should be >= ?
Well, usually things don't work that way.
YOU propose to fix something, which is nice. So YOU should explain why it is correct.
If I'm correct, the way to see that your fix is incomplete is just in the 3 or 4 lines just above and below your change.
You've been told what could be wrong, you could have checked yourself. Or explained the reasoning that makes you think it is correct.
Sorry if my answer looks rude, it is not my intend. I just read your answer as "can you do my home work for me", which is certainly not you intend either.
So, no hard felling, but a bit disappointed by the lack of curiosity.
CJ
Quoted 4 lines
Thanks & Regards,
Ghanshyam Agrawal
Quoted 6 lines
[1]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1363
[2]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1363
[3]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1366
Hello Christophe,
Thanks for your detailed answer and comments. I had done my research and couldn't find the reason to change the operator and then requested for your clarification. I should have been able to do that. I will work on that.
Thank you for taking time to explain me your thoughts. You are right. The operator should indeed be >=.
I also just found out that someone recently fixed this bug and their patch has gotten accepted. I wonder how I could have found that out before working on my patch. Since they neither sent the patch to syzkaller for testing nor did they include the fixes tag with a syzkaller link, I couldn't find it out. Maybe they found this bug from some other channel and not syzkaller. I will find a way to address this as well.
Thanks again for taking time to review my patch and discuss it with me.
Best Regards,
Ghanshyam Agrawal
Quoted 104 lines · Ghanshyam Agrawal
Quoted 86 lines · Christophe JAILLET
Quoted 38 lines · Ghanshyam Agrawal
Quoted 21 lines · Christophe JAILLET
Quoted 19 lines · Ghanshyam Agrawal
In some cases,
dn_numagmay be greater than MAXAG which may result in an array-index-out-of-bounds in dbNextAG. Added a check to return an error code before we crash.Reported-by [email protected]Signed-off-by Ghanshyam Agrawal <[email protected]>--- fs/jfs/jfs_imap.c | 3 +++ 1 file changed, 3 insertions(+)fs/jfs/jfs_imap.c +0
-0@@ -1360,6 +1360,9 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)if (agno <0 || agno > dn_numag)return -EIO ;Quoted 14 lines
fs/jfs/jfs_imap.c int diAlloc(struct inode *pip, bool dir, struct inode *ip) · line 1363
Quoted 1 line
fs/jfs/jfs_imap.c +1
-0+if (unlikely (dn_numag >MAXAG ))Hi,
looking at other places with checks with MAXAG, I wonder if it should be >=?
CJ
Quoted 5 lines
fs/jfs/jfs_imap.c +2
-0+return -EIO ; +if (atomic_read (&JFS_SBI (pip->i_sb)->bmap->db_active[agno])) {/* * There is an open file actively growing. We want to Quoted 4 lines
Hello Christophe,
Thanks for reviewing my code. I believe the greater than symbol I have set is correct in this case.
I think it's not.
If you have "if (
unlikely(dn_numag > MAXAG))", then-
dn_numagcan be = MAXAG
- [2] - so, agno can be = MAXAG as well
- [3] - and, accessing memory past the end of the array will happen,
becausedb_activeisatomic_tdb_active[MAXAG];
- BUGOr I miss something obvious?
Quoted 1 line
Can you please check it thoroughly and letme know wny it should be >= ?
Well, usually things don't work that way.
YOU propose to fix something, which is nice. So YOU should explain why it is correct.
If I'm correct, the way to see that your fix is incomplete is just in the 3 or 4 lines just above and below your change.
You've been told what could be wrong, you could have checked yourself. Or explained the reasoning that makes you think it is correct.
Sorry if my answer looks rude, it is not my intend. I just read your answer as "can you do my home work for me", which is certainly not you intend either.
So, no hard felling, but a bit disappointed by the lack of curiosity.
CJ
Quoted 4 lines
Thanks & Regards,
Ghanshyam AgrawalQuoted 6 lines
[1]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1363
[2]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1363
[3]: https://elixir.bootlin.com/linux/v6.11/source/fs/jfs/jfs_imap.c#L1366
Hello Christophe,
Thanks for your detailed answer and comments. I had done my research and couldn't find the reason to change the operator and then requested for your clarification. I should have been able to do that. I will work on that.
Thank you for taking time to explain me your thoughts. You are right. The operator should indeed be >=.
Quoted 6 lines
I also just found out that someone recently fixed this bug and their patch has gotten accepted. I wonder how I could have found that out before working on my patch. Since they neither sent the patch to syzkaller for testing nor did they include the fixes tag with a syzkaller link, I couldn't find it out. Maybe they found this bug from some other channel and not syzkaller. I will find a way to address this as well.
Just catching up on this thread.
Thank you for taking the time and effort to fix this and thanks Christophe for catching the >= thing.
The prior patch that fixed this was posted to the jfs-discussion group, which is pretty low-volume. It could be somewhere you can check if you are looking at other problems in jfs in the future. Sorry you had to duplicate that work.
Thanks again,
Shaggy
Quoted 6 lines
Thanks again for taking time to review my patch and discuss it with me.
Best Regards,
Ghanshyam Agrawal