History

blk-mq: always free hctx after request queue is freed

In normal queue cleanup path, hctx is released after request queue is freed, see blk_mq_release(). However, in __blk_mq_update_nr_hw_queues(), hctx may be freed because of hw queues shrinking. This way is easy to cause use-after-free, because: one implicit rule is that it is safe to call almost all block layer APIs if the request queue is alive; and one hctx may be retrieved by one API, then the hctx can be freed by blk_mq_update_nr_hw_queues(); finally use-after-free is triggered. Fixes this issue by always freeing hctx after releasing request queue. If some hctxs are removed in blk_mq_update_nr_hw_queues(), introduce a per-queue list to hold them, then try to resuse these hctxs if numa node is matched.

Ming Lei committed 7 years ago

Commit 2f8f1331 parent 7c6c5b73 files · +42 −13Browse files

Showing the changes to include/linux (2 of 3 files). Show all

Unified · Split

2 files
  1. include/linux/blk-mq.h +2 −0
  2. include/linux/blkdev.h +7 −0
include/linux/blk-mq.h+2−0
@@ -70,6 +70,8 @@ struct blk_mq_hw_ctx { · 69 unmodified lines
70 struct dentry *sched_debugfs_dir;70 struct dentry *sched_debugfs_dir;
71#endif71#endif
72 72
73 struct list_head hctx_list;
74
73 /* Must be the last member - see also blk_mq_hw_ctx_size(). */75 /* Must be the last member - see also blk_mq_hw_ctx_size(). */
74 struct srcu_struct srcu[0];76 struct srcu_struct srcu[0];
75};77};
include/linux/blkdev.h+7−0
@@ -535,6 +535,13 @@ struct request_queue { · 534 unmodified lines
535 535
536 struct mutex sysfs_lock;536 struct mutex sysfs_lock;
537 537
538 /*
539 * for reusing dead hctx instance in case of updating
540 * nr_hw_queues
541 */
542 struct list_head unused_hctx_list;
543 spinlock_t unused_hctx_lock;
544
538 atomic_t mq_freeze_depth;545 atomic_t mq_freeze_depth;
539 546
540#if defined(CONFIG_BLK_DEV_BSG)547#if defined(CONFIG_BLK_DEV_BSG)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t