Skip to contentSkip to conversation

fs: ext4fs: Fix: Data abort in ext4fs_log_gdt()

PATCH In review Tony Dinh 2 participants 3 messages Jun 3, 2025 – Jun 25, 2025 ext4 file system

lore
Share & tools
lore

Tony Dinh

author
#0 lore raw

cover fs: ext4fs: Fix: Data abort in ext4fs_log_gdt()

Currently, the number of EXT4 journal entries is defined as a constant, MAX_JOURNAL_ENTRIES = 100. When the HDD is greater than 2TB in capacity, the number of blocks per gdt (no_blk_pergdt) is a lot larger than 100. So the function ext4fs_log_gdt causes an array index out-of-bound in the journal log (journal_ptr[MAX_JOURNAL_ENTRIES]), and results in a data abort.

This was tested with the Synology DS116 (32-bit Armada 385 SoC) board, and a 4TB Seagate HDD.

Tony Dinh (1):
fs: ext4fs: Fix: Data abort in ext4fs_log_gdt()

 fs/ext4/ext4_journal.c | 7 +++++++
 1 file changed, 7 insertions(+)
Signature · 4 lines
2.39.5

base-commit: e9f852f7fd2481579bb3521c13663d33a7f22eef
branch: master
author
#1 lore raw

PATCH 1/1 fs: ext4fs: Fix: Data abort in ext4fs_log_gdt()

Return ENOMEM in ext4fs_log_gdt when number of blocks per gdt is more than number of allocated journal entries.

---

 fs/ext4/ext4_journal.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ext4/ext4_journal.c +7 -0
index 02c4ac2cb93..868a2c1804a 100644
@@ -131,6 +131,13 @@ int ext4fs_log_gdt(char *gd_table)
 	struct ext_filesystem *fs = get_fs();
 	short i;
 	long int var = fs->gdtable_blkno;
+
+	/* Make sure there is enough journal entries */
+	if (fs->no_blk_pergdt > MAX_JOURNAL_ENTRIES) {
+		log_err("*** Not enough journal entries allocated\n");
+		return -ENOMEM;
+	}
+
 	for (i = 0; i < fs->no_blk_pergdt; i++) {
 		journal_ptr[gindex]->buf = zalloc(fs->blksz);
 		if (!journal_ptr[gindex]->buf)
Signature · 1 line
2.39.5
#2 lore raw
Quoted 4 lines · Tony Dinh

Return ENOMEM in ext4fs_log_gdt when number of blocks per gdt is more than number of allocated journal entries.

Applied to u-boot/next, thanks!

[1/1] fs: ext4fs: Fix: Data abort in ext4fs_log_gdt()

      commit: 29cb98d515f96c2330455af4b8cace0220abd00c
Signature · 1 line
Tom