Skip to contentSkip to conversation

mm: validate inode in mapping_set_error

PATCH Applied Minchan Kim 2 participants 2 messages Oct 10, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: validate inode in mapping_set_error

The swap address_space doesn't have host. Thus, it makes kernel crash once swap write meets error. Fix it.

[1] 735e4ae5ba28, vfs: track per-sb writeback errors and report them to syncfs

---
 include/linux/pagemap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/pagemap.h +2 -1
index 17ba0fe59290..9cf540447e73 100644
@@ -55,7 +55,8 @@ static inline void mapping_set_error(struct address_space *mapping, int error)
 	__filemap_set_wb_err(mapping, error);
 
 	/* Record it in superblock */
-	errseq_set(&mapping->host->i_sb->s_wb_err, error);
+	if (mapping->host)
+		errseq_set(&mapping->host->i_sb->s_wb_err, error);
 
 	/* Record it in flags for now, for legacy callers */
 	if (error == -ENOSPC)
Signature · 1 line
2.28.0.1011.ga647a8990f-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Minchan Kim

The swap address_space doesn't have host. Thus, it makes kernel crash once swap write meets error. Fix it.

[1] 735e4ae5ba28, vfs: track per-sb writeback errors and report them to syncfs

---
 include/linux/pagemap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/pagemap.h +0 -0
index 17ba0fe59290..9cf540447e73 100644

include/linux/pagemap.h static inline void mapping_set_error(struct address_space *mapping, int error) · line 62

Quoted 9 lines
include/linux/pagemap.h +2 -1
@@ -55,7 +55,8 @@ static inline void mapping_set_error(struct address_space *mapping, int error)
 	__filemap_set_wb_err(mapping, error);
 
 	/* Record it in superblock */
-	errseq_set(&mapping->host->i_sb->s_wb_err, error);
+	if (mapping->host)
+		errseq_set(&mapping->host->i_sb->s_wb_err, error);
 
 	/* Record it in flags for now, for legacy callers */
 	if (error == -ENOSPC)

Good catch.