Skip to content

Commit 853322a

Browse files
Matthew Wilcox (Oracle)torvalds
authored andcommitted
mm/debug.c: do not dereference i_ino blindly
__dump_page() checks i_dentry is fetchable and i_ino is earlier in the struct than i_ino, so it ought to work fine, but it's possible that struct randomisation has reordered i_ino after i_dentry and the pointer is just wild enough that i_dentry is fetchable and i_ino isn't. Also print the inode number if the dentry is invalid. Reported-by: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> Link: https://lkml.kernel.org/r/20200819185710.28180-1-willy@infradead.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8490e2e commit 853322a

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎mm/debug.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ void __dump_page(struct page *page, const char *reason)
120120
struct hlist_node *dentry_first;
121121
struct dentry *dentry_ptr;
122122
struct dentry dentry;
123+
unsigned long ino;
123124

124125
/*
125126
* mapping can be invalid pointer and we don't want to crash
@@ -136,29 +137,30 @@ void __dump_page(struct page *page, const char *reason)
136137
goto out_mapping;
137138
}
138139

139-
if (get_kernel_nofault(dentry_first, &host->i_dentry.first)) {
140+
if (get_kernel_nofault(dentry_first, &host->i_dentry.first) ||
141+
get_kernel_nofault(ino, &host->i_ino)) {
140142
pr_warn("aops:%ps with invalid host inode %px\n",
141143
a_ops, host);
142144
goto out_mapping;
143145
}
144146

145147
if (!dentry_first) {
146-
pr_warn("aops:%ps ino:%lx\n", a_ops, host->i_ino);
148+
pr_warn("aops:%ps ino:%lx\n", a_ops, ino);
147149
goto out_mapping;
148150
}
149151

150152
dentry_ptr = container_of(dentry_first, struct dentry, d_u.d_alias);
151153
if (get_kernel_nofault(dentry, dentry_ptr)) {
152-
pr_warn("aops:%ps with invalid dentry %px\n", a_ops,
153-
dentry_ptr);
154+
pr_warn("aops:%ps ino:%lx with invalid dentry %px\n",
155+
a_ops, ino, dentry_ptr);
154156
} else {
155157
/*
156158
* if dentry is corrupted, the %pd handler may still
157159
* crash, but it's unlikely that we reach here with a
158160
* corrupted struct page
159161
*/
160162
pr_warn("aops:%ps ino:%lx dentry name:\"%pd\"\n",
161-
a_ops, host->i_ino, &dentry);
163+
a_ops, ino, &dentry);
162164
}
163165
}
164166
out_mapping:

0 commit comments

Comments
 (0)