Skip to contentSkip to conversation

ext4: Fix check for block being out of directory size

PATCH Applied Jan Kara 4 participants 4 messages Aug 22, 2022 – Sep 29, 2022

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 ext4: Fix check for block being out of directory size

The check in __ext4_read_dirblock() for block being outside of directory size was wrong because it compared block number against directory size in bytes. Fix it.

Fixes 65f8ea4cd57d ("ext4: check if directory block is within i_size")

CVE: CVE-2022-1184

---
 fs/ext4/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/namei.c +1 -1
index 3a31b662f661..bc2e0612ec32 100644
@@ -126,7 +126,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
 	struct ext4_dir_entry *dirent;
 	int is_dx_block = 0;
 
-	if (block >= inode->i_size) {
+	if (block >= inode->i_size >> inode->i_blkbits) {
 		ext4_error_inode(inode, func, line, block,
 		       "Attempting to read directory block (%u) that is past i_size (%llu)",
 		       block, inode->i_size);
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Jan Kara

The check in __ext4_read_dirblock() for block being outside of directory size was wrong because it compared block number against directory size in bytes. Fix it.

Good catch, thanks!

Quoted 25 lines
Fixes 65f8ea4cd57d ("ext4: check if directory block is within i_size")

CVE: CVE-2022-1184

---
 fs/ext4/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/namei.c +1 -1
index 3a31b662f661..bc2e0612ec32 100644
@@ -126,7 +126,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
 	struct ext4_dir_entry *dirent;
 	int is_dx_block = 0;
 
-	if (block >= inode->i_size) {
+	if (block >= inode->i_size >> inode->i_blkbits) {
 		ext4_error_inode(inode, func, line, block,
 		       "Attempting to read directory block (%u) that is past i_size (%llu)",
 		       block, inode->i_size);
Signature · 1 line
2.35.3
#2 lore raw

Hi,

Quoted 26 lines · Lukas Czerner
Quoted 3 lines · Jan Kara

The check in __ext4_read_dirblock() for block being outside of directory size was wrong because it compared block number against directory size in bytes. Fix it.

Good catch, thanks!

Quoted 17 lines
Fixes 65f8ea4cd57d ("ext4: check if directory block is within i_size")

CVE: CVE-2022-1184

---
 fs/ext4/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/namei.c +0 -0
index 3a31b662f661..bc2e0612ec32 100644
@@ -126,7 +126,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
 	struct ext4_dir_entry *dirent;
 	int is_dx_block = 0;
 
Quoted 5 lines

fs/ext4/namei.c static struct buffer_head *__ext4_read_dirblock(struct inode *inode, · line 132

Quoted 5 lines
fs/ext4/namei.c +1 -1
-	if (block >= inode->i_size) {
+	if (block >= inode->i_size >> inode->i_blkbits) {
 		ext4_error_inode(inode, func, line, block,
 		       "Attempting to read directory block (%u) that is past i_size (%llu)",
 		       block, inode->i_size);

Ted, is this on your radar to get applied for mainline and to the stable trees?

Regards,
Salvatore

maintainer Applied
#3 lore raw
In reply to Jan Kara
Quoted 5 lines · Jan Kara

The check in __ext4_read_dirblock() for block being outside of directory size was wrong because it compared block number against directory size in bytes. Fix it.

Applied, thanks!

[1/1] ext4: Fix check for block being out of directory size

      commit: 013c07e4705fb994e5e56530af0bc6272884b5c1

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>