diff mbox series

mm: validate inode in mapping_set_error

Message ID 20201010000650.750063-1-minchan@kernel.org (mailing list archive)
State New, archived
Headers show
Series mm: validate inode in mapping_set_error | expand

Commit Message

Minchan Kim Oct. 10, 2020, 12:06 a.m. UTC
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
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
 include/linux/pagemap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jeff Layton Oct. 10, 2020, 11:58 a.m. UTC | #1
On Fri, 2020-10-09 at 17:06 -0700, Minchan Kim wrote:
> 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
> Signed-off-by: Minchan Kim <minchan@kernel.org>
> ---
>  include/linux/pagemap.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index 17ba0fe59290..9cf540447e73 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -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.

Acked-by: Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 17ba0fe59290..9cf540447e73 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -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)