diff options
author | Liu Bo <bo.li.liu@oracle.com> | 2017-04-05 17:04:19 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2017-04-11 12:49:08 -0400 |
commit | 2e949b0a5592664f8b3eb3e2e48213f514892561 (patch) | |
tree | 1c43f7ca722cb55cca12418e618cf56bbabf3209 | |
parent | 951e7966398b0fd6bacebec2d87ffd61c3f68b18 (diff) |
Btrfs: fix invalid dereference in btrfs_retry_endio
When doing directIO repair, we have this oops:
[ 1458.532816] general protection fault: 0000 [#1] SMP
...
[ 1458.536291] Workqueue: btrfs-endio-repair btrfs_endio_repair_helper [btrfs]
[ 1458.536893] task: ffff88082a42d100 task.stack: ffffc90002b3c000
[ 1458.537499] RIP: 0010:btrfs_retry_endio+0x7e/0x1a0 [btrfs]
...
[ 1458.543261] Call Trace:
[ 1458.543958] ? rcu_read_lock_sched_held+0xc4/0xd0
[ 1458.544374] bio_endio+0xed/0x100
[ 1458.544750] end_workqueue_fn+0x3c/0x40 [btrfs]
[ 1458.545257] normal_work_helper+0x9f/0x900 [btrfs]
[ 1458.545762] btrfs_endio_repair_helper+0x12/0x20 [btrfs]
[ 1458.546224] process_one_work+0x34d/0xb70
[ 1458.546570] ? process_one_work+0x29e/0xb70
[ 1458.546938] worker_thread+0x1cf/0x960
[ 1458.547263] ? process_one_work+0xb70/0xb70
[ 1458.547624] kthread+0x17d/0x180
[ 1458.547909] ? kthread_create_on_node+0x70/0x70
[ 1458.548300] ret_from_fork+0x31/0x40
It turns out that btrfs_retry_endio is trying to get inode from a directIO
page.
This fixes the problem by using the saved inode pointer, done->inode.
btrfs_retry_endio_nocsum has the same problem, and it's fixed as well.
Also cleanup unused @start (which is too trivial for a separate patch).
Cc: David Sterba <dsterba@suse.cz>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/inode.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 876f1d36030c..388c6ce069de 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -7910,7 +7910,6 @@ struct btrfs_retry_complete { | |||
7910 | static void btrfs_retry_endio_nocsum(struct bio *bio) | 7910 | static void btrfs_retry_endio_nocsum(struct bio *bio) |
7911 | { | 7911 | { |
7912 | struct btrfs_retry_complete *done = bio->bi_private; | 7912 | struct btrfs_retry_complete *done = bio->bi_private; |
7913 | struct inode *inode; | ||
7914 | struct bio_vec *bvec; | 7913 | struct bio_vec *bvec; |
7915 | int i; | 7914 | int i; |
7916 | 7915 | ||
@@ -7918,12 +7917,12 @@ static void btrfs_retry_endio_nocsum(struct bio *bio) | |||
7918 | goto end; | 7917 | goto end; |
7919 | 7918 | ||
7920 | ASSERT(bio->bi_vcnt == 1); | 7919 | ASSERT(bio->bi_vcnt == 1); |
7921 | inode = bio->bi_io_vec->bv_page->mapping->host; | 7920 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(done->inode)); |
7922 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(inode)); | ||
7923 | 7921 | ||
7924 | done->uptodate = 1; | 7922 | done->uptodate = 1; |
7925 | bio_for_each_segment_all(bvec, bio, i) | 7923 | bio_for_each_segment_all(bvec, bio, i) |
7926 | clean_io_failure(BTRFS_I(done->inode), done->start, bvec->bv_page, 0); | 7924 | clean_io_failure(BTRFS_I(done->inode), done->start, |
7925 | bvec->bv_page, 0); | ||
7927 | end: | 7926 | end: |
7928 | complete(&done->done); | 7927 | complete(&done->done); |
7929 | bio_put(bio); | 7928 | bio_put(bio); |
@@ -7986,9 +7985,7 @@ static void btrfs_retry_endio(struct bio *bio) | |||
7986 | { | 7985 | { |
7987 | struct btrfs_retry_complete *done = bio->bi_private; | 7986 | struct btrfs_retry_complete *done = bio->bi_private; |
7988 | struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); | 7987 | struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); |
7989 | struct inode *inode; | ||
7990 | struct bio_vec *bvec; | 7988 | struct bio_vec *bvec; |
7991 | u64 start; | ||
7992 | int uptodate; | 7989 | int uptodate; |
7993 | int ret; | 7990 | int ret; |
7994 | int i; | 7991 | int i; |
@@ -7998,11 +7995,8 @@ static void btrfs_retry_endio(struct bio *bio) | |||
7998 | 7995 | ||
7999 | uptodate = 1; | 7996 | uptodate = 1; |
8000 | 7997 | ||
8001 | start = done->start; | ||
8002 | |||
8003 | ASSERT(bio->bi_vcnt == 1); | 7998 | ASSERT(bio->bi_vcnt == 1); |
8004 | inode = bio->bi_io_vec->bv_page->mapping->host; | 7999 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(done->inode)); |
8005 | ASSERT(bio->bi_io_vec->bv_len == btrfs_inode_sectorsize(inode)); | ||
8006 | 8000 | ||
8007 | bio_for_each_segment_all(bvec, bio, i) { | 8001 | bio_for_each_segment_all(bvec, bio, i) { |
8008 | ret = __readpage_endio_check(done->inode, io_bio, i, | 8002 | ret = __readpage_endio_check(done->inode, io_bio, i, |