[4/4] block: don't hold part0's refcount in IO path
diff mbox series

Message ID 20200109062109.2313-5-ming.lei@redhat.com
State New
Headers show
Series
  • block: fix partition use-after-free and optimization
Related show

Commit Message

Ming Lei Jan. 9, 2020, 6:21 a.m. UTC
gendisk can't be gone when there is IO activity, so not hold
part0's refcount in IO path.

Cc: Yufen Yu <yuyufen@huawei.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Hou Tao <houtao1@huawei.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-core.c | 3 ++-
 block/genhd.c    | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/block/blk-core.c b/block/blk-core.c
index 79599f5fd5b7..a1184a59819a 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1345,7 +1345,8 @@  void blk_account_io_done(struct request *req, u64 now)
 		part_stat_add(part, time_in_queue, nsecs_to_jiffies64(now - req->start_time_ns));
 		part_dec_in_flight(req->q, part, rq_data_dir(req));
 
-		hd_struct_put(part);
+		if (part->partno)
+			hd_struct_put(part);
 		part_stat_unlock();
 	}
 }
diff --git a/block/genhd.c b/block/genhd.c
index bfc4148ec341..8c7c32b5dcc0 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -300,7 +300,6 @@  struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
 		}
 	}
  exit:
-	hd_struct_get(&disk->part0);
 	return &disk->part0;
 }
 EXPORT_SYMBOL_GPL(disk_map_sector_rcu);