mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* + mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk.patch added to -mm tree
@ 2016-11-29 23:08 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2016-11-29 23:08 UTC (permalink / raw)
  To: fangwei1, hannes, hch, jack, stable, viro, mm-commits


The patch titled
     Subject: mm/filemap.c: fix a NULL dereference crash while accessing bdev->bd_disk
has been added to the -mm tree.  Its filename is
     mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Wei Fang <fangwei1@huawei.com>
Subject: mm/filemap.c: fix a NULL dereference crash while accessing bdev->bd_disk

->bd_disk is assigned to NULL in __blkdev_put() when no one is holding the
bdev.  After that, ->bd_inode still can be touched in the
blockdev_superblock->s_inodes list before the final iput.  So
iterate_bdevs() can still get this inode, and start writeback on mapping
dirty pages.  ->bd_disk will be dereferenced in
mapping_cap_writeback_dirty() in this case, and a NULL dereference crash
will be triggered:

Unable to handle kernel NULL pointer dereference at virtual address 00000388
...
[<ffff8000004cb1e4>] blk_get_backing_dev_info+0x1c/0x28
[<ffff8000001c879c>] __filemap_fdatawrite_range+0x54/0x98
[<ffff8000001c8804>] filemap_fdatawrite+0x24/0x2c
[<ffff80000027e7a4>] fdatawrite_one_bdev+0x20/0x28
[<ffff800000288b44>] iterate_bdevs+0xec/0x144
[<ffff80000027eb50>] sys_sync+0x84/0xd0

Since mapping_cap_writeback_dirty() is always return true about block
device inodes, no need to check it if the inode is a block device inode.

Link: http://lkml.kernel.org/r/1480125982-8497-1-git-send-email-fangwei1@huawei.com
Signed-off-by: Wei Fang <fangwei1@huawei.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/filemap.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff -puN mm/filemap.c~mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk mm/filemap.c
--- a/mm/filemap.c~mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk
+++ a/mm/filemap.c
@@ -383,8 +383,9 @@ int __filemap_fdatawrite_range(struct ad
 		.range_end = end,
 	};
 
-	if (!mapping_cap_writeback_dirty(mapping))
-		return 0;
+	if (!sb_is_blkdev_sb(mapping->host->i_sb))
+		if (!mapping_cap_writeback_dirty(mapping))
+			return 0;
 
 	wbc_attach_fdatawrite_inode(&wbc, mapping->host);
 	ret = do_writepages(mapping, &wbc);
_

Patches currently in -mm which might be from fangwei1@huawei.com are

mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk.patch


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-11-29 23:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-29 23:08 + mm-fix-a-null-dereference-crash-while-accessing-bdev-bd_disk.patch added to -mm tree akpm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).