Skip to contentSkip to conversation

fs: ext4: Fix journal overrun issue reported by Coverity

PATCH In review Tom Rini 2 participants 3 messages Aug 21, 2017 – Aug 26, 2017 ext4 file system

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 fs: ext4: Fix journal overrun issue reported by Coverity

While &p_jdb[fs->blksz] is a valid expression (it points *one* char sized element past the end of the array, e.g. &p_jdb[fs->blksz + 1] is invalid (according to the C standard (C99/C11)).

Changing this to tag = (struct ext3_journal_block_tag *)(p_jdb + ofs);

Cc Stefan Brüns <[email protected]>
Reported-by Coverity (CID: 165117, 165110)

---
Stefan, since this is your suggestion and message, if you want me to v2 with you as Author, I'd be quite happy to, thanks again!

---
 fs/ext4/ext4_journal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/ext4_journal.c +2 -2
index 5a25be4c8ac2..fed6287eac45 100644
@@ -355,7 +355,7 @@ void recover_transaction(int prev_desc_logical_no)
 	ofs = sizeof(struct journal_header_t);
 
 	do {
-		tag = (struct ext3_journal_block_tag *)&p_jdb[ofs];
+		tag = (struct ext3_journal_block_tag *)(p_jdb + ofs);
 		ofs += sizeof(struct ext3_journal_block_tag);
 
 		if (ofs > fs->blksz)
@@ -466,7 +466,7 @@ int ext4fs_check_journal_state(int recovery_flag)
 			ofs = sizeof(struct journal_header_t);
 			do {
 				tag = (struct ext3_journal_block_tag *)
-				    &p_jdb[ofs];
+				    (p_jdb + ofs);
 				ofs += sizeof(struct ext3_journal_block_tag);
 				if (ofs > fs->blksz)
 					break;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 fs: ext4: Fix journal overrun issue reported by Coverity

Quoted 6 lines · On Montag, 21. August 2017 04:30:15 CEST Tom Rini wrote:

While &p_jdb[fs->blksz] is a valid expression (it points *one* char sized element past the end of the array, e.g. &p_jdb[fs->blksz + 1] is invalid (according to the C standard (C99/C11)).

Changing this to tag = (struct ext3_journal_block_tag *)(p_jdb + ofs);

Quoted 7 lines
Cc Stefan Brüns <[email protected]>
Reported-by Coverity (CID: 165117, 165110)

---
Stefan, since this is your suggestion and message, if you want me to v2 with you as Author, I'd be quite happy to, thanks again!

Hi Tom,

whatever you like, both is fine with me.

Kind regards,

Stefan

PS:

Quoted 26 lines
---
 fs/ext4/ext4_journal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/ext4_journal.c +2 -2
index 5a25be4c8ac2..fed6287eac45 100644
@@ -355,7 +355,7 @@ void recover_transaction(int prev_desc_logical_no)
 	ofs = sizeof(struct journal_header_t);
 
 	do {
-		tag = (struct ext3_journal_block_tag *)&p_jdb[ofs];
+		tag = (struct ext3_journal_block_tag *)(p_jdb + ofs);
 		ofs += sizeof(struct ext3_journal_block_tag);
 
 		if (ofs > fs->blksz)
@@ -466,7 +466,7 @@ int ext4fs_check_journal_state(int recovery_flag)
 			ofs = sizeof(struct journal_header_t);
 			do {
 				tag = (struct ext3_journal_block_tag *)
-				    &p_jdb[ofs];
+				    (p_jdb + ofs);
 				ofs += sizeof(struct ext3_journal_block_tag);
 				if (ofs > fs->blksz)
 					break;
author
#2 lore raw
In reply to Tom Rini
Quoted 11 lines · Tom Rini

While &p_jdb[fs->blksz] is a valid expression (it points *one* char sized element past the end of the array, e.g. &p_jdb[fs->blksz + 1] is invalid (according to the C standard (C99/C11)).

Changing this to tag = (struct ext3_journal_block_tag *)(p_jdb + ofs);

Cc Stefan Brüns <[email protected]>
Reported-by Coverity (CID: 165117, 165110)

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170826/fc4cd986/attachment.sig>