Skip to contentSkip to conversation

ext4: fix potential use after free in __ext4_journal_stop

PATCH Applied Lukas Czerner 3 participants 4 messages Sep 2, 2015 – Oct 18, 2015 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: fix potential use after free in __ext4_journal_stop

There is a use-after-free possibility in __ext4_journal_stop() in the case that we free the handle in the first jbd2_journal_stop() because we're referencing handle->h_err afterwards. This was introduced in 9705acd63b125dee8b15c705216d7186daea4625 and it is wrong. Fix it by storing the handle->h_err value beforehand and avoid referencing potentially freed handle.

---
 fs/ext4/ext4_jbd2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ext4/ext4_jbd2.c +3 -3
index d418431..e770c1ee 100644
@@ -88,13 +88,13 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
 		return 0;
 	}
 
+	err = handle->h_err;
 	if (!handle->h_transaction) {
-		err = jbd2_journal_stop(handle);
-		return handle->h_err ? handle->h_err : err;
+		rc = jbd2_journal_stop(handle);
+		return err ? err : rc;
 	}
 
 	sb = handle->h_transaction->t_journal->j_private;
-	err = handle->h_err;
 	rc = jbd2_journal_stop(handle);
 
 	if (!err)
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Lukas Czerner

Date: Wed, 2 Sep 2015 16:45:54 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: Lukas Czerner <[email protected]>
Subject: [PATCH] ext4: fix potential use after free in __ext4_journal_stop

Quoted 6 lines

There is a use-after-free possibility in __ext4_journal_stop() in the case that we free the handle in the first jbd2_journal_stop() because we're referencing handle->h_err afterwards. This was introduced in 9705acd63b125dee8b15c705216d7186daea4625 and it is wrong. Fix it by storing the handle->h_err value beforehand and avoid referencing potentially freed handle.

ping

-Lukas

Quoted 28 lines
---
 fs/ext4/ext4_jbd2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ext4/ext4_jbd2.c +3 -3
index d418431..e770c1ee 100644
@@ -88,13 +88,13 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
 		return 0;
 	}
 
+	err = handle->h_err;
 	if (!handle->h_transaction) {
-		err = jbd2_journal_stop(handle);
-		return handle->h_err ? handle->h_err : err;
+		rc = jbd2_journal_stop(handle);
+		return err ? err : rc;
 	}
 
 	sb = handle->h_transaction->t_journal->j_private;
-	err = handle->h_err;
 	rc = jbd2_journal_stop(handle);
 
 	if (!err)
Reviewed-by
#2 lore raw
Quoted 11 lines · Lukáš Czerner
Quoted 6 lines · Lukas Czerner

Date: Wed, 2 Sep 2015 16:45:54 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: Lukas Czerner <[email protected]>
Subject: [PATCH] ext4: fix potential use after free in __ext4_journal_stop

Quoted 10 lines
Quoted 6 lines

There is a use-after-free possibility in __ext4_journal_stop() in the case that we free the handle in the first jbd2_journal_stop() because we're referencing handle->h_err afterwards. This was introduced in 9705acd63b125dee8b15c705216d7186daea4625 and it is wrong. Fix it by storing the handle->h_err value beforehand and avoid referencing potentially freed handle.

ping

Quoted 2 lines
Quoted 24 lines
Quoted 24 lines

---
fs/ext4/ext4_jbd2.c | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-)
fs/ext4/ext4_jbd2.c +3 -3
index d418431..e770c1ee 100644
@@ -88,13 +88,13 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
 		return 0;
 	}
 
+	err = handle->h_err;
 	if (!handle->h_transaction) {
-		err = jbd2_journal_stop(handle);
-		return handle->h_err ? handle->h_err : err;
+		rc = jbd2_journal_stop(handle);
+		return err ? err : rc;
 	}
 
 	sb = handle->h_transaction->t_journal->j_private;
-	err = handle->h_err;
 	rc = jbd2_journal_stop(handle);
 
Quoted 6 lines

fs/ext4/ext4_jbd2.c int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle) · line 100

Quoted 2 lines
fs/ext4/ext4_jbd2.c +0 -0
 	if (!err)

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Cheers, Andreas

maintainer Applied
#3 lore raw
Quoted 16 lines · Andreas Dilger
Quoted 16 lines · Lukáš Czerner
Quoted 12 lines · Lukas Czerner

Date: Wed, 2 Sep 2015 16:45:54 +0200
From: Lukas Czerner <[email protected]>
To: [email protected]
Cc: Lukas Czerner <[email protected]>
Subject: [PATCH] ext4: fix potential use after free in __ext4_journal_stop

There is a use-after-free possibility in __ext4_journal_stop() in the case that we free the handle in the first jbd2_journal_stop() because we're referencing handle->h_err afterwards. This was introduced in 9705acd63b125dee8b15c705216d7186daea4625 and it is wrong. Fix it by storing the handle->h_err value beforehand and avoid referencing potentially freed handle.

Quoted 5 lines
Quoted 3 lines

ping

Quoted 2 lines

Applied, thanks.

- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html