Skip to contentSkip to conversation

ext4: Ensure that inode is non-NULL before calling ext4_error_inode

PATCH In review Matthew Wilcox 3 participants 3 messages Apr 2, 2014 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Ensure that inode is non-NULL before calling ext4_error_inode

__ext4_handle_dirty_metadata can be called with a NULL inode, but ext4_error_inode can't. This is supposed to be a "can't happen" path, so we need to find out whether it can legitimately happen or whether there's some other bug that is causing this to happen. This prevents a NULL pointer reference, so it should be included regardless of what the underlying error is.

---
 fs/ext4/ext4_jbd2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/ext4_jbd2.c +2 -1
index 3fe29de..383d586 100644
@@ -259,7 +259,8 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
 		if (WARN_ON_ONCE(err)) {
 			ext4_journal_abort_handle(where, line, __func__, bh,
 						  handle, err);
-			ext4_error_inode(inode, where, line,
+			if (inode)
+				ext4_error_inode(inode, where, line,
 					 bh->b_blocknr,
 					 "journal_dirty_metadata failed: "
 					 "handle type %u started at line %u, "
Signature · 1 line
1.9.0
maintainer
#1 lore raw
Quoted 9 lines · Matthew Wilcox

__ext4_handle_dirty_metadata can be called with a NULL inode, but ext4_error_inode can't. This is supposed to be a "can't happen" path, so we need to find out whether it can legitimately happen or whether there's some other bug that is causing this to happen. This prevents a NULL pointer reference, so it should be included regardless of what the underlying error is.

This was fixed by the following commit which will be shortly pushed to Linus. Admittedly, I should have done a better job noting it in the commit description (sorry about that):

http://git.kernel.org/cgit/linux/kernel/git/tytso/ext4.git/commit/?h=dev&id=0edaa0178ea7142691ae9c10baa42b3e6466d047

In my patch I made sure we printed something so there would be better chance of debugging the problem:

+ if (inode == NULL) {
+ pr_err("EXT4: jbd2_journal_dirty_metadata "

+				       "failed: handle type %u started at "
+				       "line %u, credits %u/%u, errcode %d",
+				       handle->h_type,
+				       handle->h_line_no,
+				       handle->h_requested_credits,
+				       handle->h_buffer_credits, err);

+ return err;
+ }

It turns out this case does happen if we are journalling fs-level metadata, such as block group descriptor.

- Ted

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Matthew Wilcox
Quoted 4 lines · Matthew Wilcox

__ext4_handle_dirty_metadata can be called with a NULL inode, but ext4_error_inode can't. This is supposed to be a "can't happen" path, so we need to find out whether it can legitimately happen or whether

It can legitimately happen - there is metadata (like bitmaps, inode
table, group descriptor) which doesn't belong to any inode. Thus we leave inode argument as NULL for these.

Quoted 3 lines

there's some other bug that is causing this to happen. This prevents a NULL pointer reference, so it should be included regardless of what the underlying error is.

I'd prefer wrapping that several-line error into braces. But whatever.
Feel free to add:

Honza

Quoted 27 lines
---
 fs/ext4/ext4_jbd2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/ext4_jbd2.c +2 -1
index 3fe29de..383d586 100644
@@ -259,7 +259,8 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
 		if (WARN_ON_ONCE(err)) {
 			ext4_journal_abort_handle(where, line, __func__, bh,
 						  handle, err);
-			ext4_error_inode(inode, where, line,
+			if (inode)
+				ext4_error_inode(inode, where, line,
 					 bh->b_blocknr,
 					 "journal_dirty_metadata failed: "
 					 "handle type %u started at line %u, "
Signature · 6 lines
1.9.0

--
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
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR