linux-stable/fs/nilfs2
Ryusuke Konishi 5402e2d021 nilfs2: fix null pointer dereference at nilfs_segctor_do_construct()
commit 8301c719a2 upstream.

After commit c3aab9a0bd ("mm/filemap.c: don't initiate writeback if
mapping has no dirty pages"), the following null pointer dereference has
been reported on nilfs2:

  BUG: kernel NULL pointer dereference, address: 00000000000000a8
  #PF: supervisor read access in kernel mode
  #PF: error_code(0x0000) - not-present page
  PGD 0 P4D 0
  Oops: 0000 [#1] SMP PTI
  ...
  RIP: 0010:percpu_counter_add_batch+0xa/0x60
  ...
  Call Trace:
    __test_set_page_writeback+0x2d3/0x330
    nilfs_segctor_do_construct+0x10d3/0x2110 [nilfs2]
    nilfs_segctor_construct+0x168/0x260 [nilfs2]
    nilfs_segctor_thread+0x127/0x3b0 [nilfs2]
    kthread+0xf8/0x130
    ...

This crash turned out to be caused by set_page_writeback() call for
segment summary buffers at nilfs_segctor_prepare_write().

set_page_writeback() can call inc_wb_stat(inode_to_wb(inode),
WB_WRITEBACK) where inode_to_wb(inode) is NULL if the inode of
underlying block device does not have an associated wb.

This fixes the issue by calling inode_attach_wb() in advance to ensure
to associate the bdev inode with its wb.

Fixes: c3aab9a0bd ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages")
Reported-by: Walton Hoops <me@waltonhoops.com>
Reported-by: Tomas Hlavaty <tom@logand.com>
Reported-by: ARAI Shun-ichi <hermes@ceres.dti.ne.jp>
Reported-by: Hideki EIRAKU <hdk1983@gmail.com>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>	[5.4+]
Link: http://lkml.kernel.org/r/20200608.011819.1399059588922299158.konishi.ryusuke@gmail.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-06-20 10:25:01 +02:00
..
alloc.c nilfs2: use i_blocksize() 2017-02-27 18:43:46 -08:00
alloc.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
bmap.c nilfs2: hide function name argument from nilfs_error() 2016-08-02 19:35:16 -04:00
bmap.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
btnode.c fs: add i_blocksize() 2017-02-27 18:43:46 -08:00
btnode.h fs: have submit_bh users pass in op and flags separately 2016-06-07 13:41:38 -06:00
btree.c nilfs2: use i_blocksize() 2017-02-27 18:43:46 -08:00
btree.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
cpfile.c nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
cpfile.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
dat.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
dat.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
dir.c fs: Replace CURRENT_TIME with current_time() for inode timestamps 2016-09-27 21:06:21 -04:00
direct.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
direct.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
export.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
file.c mm, fs: reduce fault, page_mkwrite, and pfn_mkwrite to take only vmf 2017-02-24 17:46:54 -08:00
gcinode.c nilfs2: emit error message when I/O error is detected 2016-08-02 19:35:19 -04:00
ifile.c nilfs2: replace nilfs_warning() with nilfs_msg() 2016-08-02 19:35:18 -04:00
ifile.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
inode.c VFS: Convert sb->s_flags & MS_RDONLY to sb_rdonly(sb) 2017-07-17 08:45:34 +01:00
ioctl.c fs: Replace CURRENT_TIME with current_time() for inode timestamps 2016-09-27 21:06:21 -04:00
Kconfig
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mdt.c VFS: Convert sb->s_flags & MS_RDONLY to sb_rdonly(sb) 2017-07-17 08:45:34 +01:00
mdt.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
namei.c do d_instantiate/unlock_new_inode combinations safely 2018-05-30 07:51:47 +02:00
nilfs.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
page.c mm: remove nr_pages argument from pagevec_lookup{,_range}() 2017-09-06 17:27:27 -07:00
page.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
recovery.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
segbuf.c block: replace bi_bdev with a gendisk pointer and partitions index 2017-08-23 12:49:55 -06:00
segbuf.h nilfs2: avoid bare use of 'unsigned' 2016-05-23 17:04:14 -07:00
segment.c nilfs2: fix null pointer dereference at nilfs_segctor_do_construct() 2020-06-20 10:25:01 +02:00
segment.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
sufile.c nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
sufile.h nilfs2: move ioctl interface and disk layout to uapi separately 2016-08-02 19:35:21 -04:00
super.c VFS: Convert sb->s_flags & MS_RDONLY to sb_rdonly(sb) 2017-07-17 08:45:34 +01:00
sysfs.c nilfs2: fix misuse of a semaphore in sysfs code 2016-08-02 19:35:20 -04:00
sysfs.h nilfs2: clean trailing semicolons in macros 2016-05-23 17:04:14 -07:00
the_nilfs.c nilfs2: reduce bare use of printk() with nilfs_msg() 2016-08-02 19:35:17 -04:00
the_nilfs.h nilfs2: fix misuse of a semaphore in sysfs code 2016-08-02 19:35:20 -04:00