Commit 3e45352
md: Free resources in __md_stop
If md_run() fails after ->active_io is initialized, then percpu_ref_exit
is called in error path. However, later md_free_disk will call
percpu_ref_exit again which leads to a panic because of null pointer
dereference. It can also trigger this bug when resources are initialized
but are freed in error path, then will be freed again in md_free_disk.
BUG: kernel NULL pointer dereference, address: 0000000000000038
Oops: 0000 [#1] PREEMPT SMP
Workqueue: md_misc mddev_delayed_delete
RIP: 0010:free_percpu+0x110/0x630
Call Trace:
<TASK>
__percpu_ref_exit+0x44/0x70
percpu_ref_exit+0x16/0x90
md_free_disk+0x2f/0x80
disk_release+0x101/0x180
device_release+0x84/0x110
kobject_put+0x12a/0x380
kobject_put+0x160/0x380
mddev_delayed_delete+0x19/0x30
process_one_work+0x269/0x680
worker_thread+0x266/0x640
kthread+0x151/0x1b0
ret_from_fork+0x1f/0x30
For creating raid device, md raid calls do_md_run->md_run, dm raid calls
md_run. We alloc those memory in md_run. For stopping raid device, md raid
calls do_md_stop->__md_stop, dm raid calls md_stop->__md_stop. So we can
free those memory resources in __md_stop.
Fixes: 72adae2 ("md: Change active_io to percpu")
Reported-and-tested-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Song Liu <song@kernel.org>1 parent 49d2439 commit 3e45352
1 file changed
+5
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6256 | 6256 | | |
6257 | 6257 | | |
6258 | 6258 | | |
| 6259 | + | |
| 6260 | + | |
| 6261 | + | |
| 6262 | + | |
| 6263 | + | |
6259 | 6264 | | |
6260 | 6265 | | |
6261 | 6266 | | |
| |||
6265 | 6270 | | |
6266 | 6271 | | |
6267 | 6272 | | |
6268 | | - | |
6269 | | - | |
6270 | | - | |
6271 | | - | |
6272 | 6273 | | |
6273 | 6274 | | |
6274 | 6275 | | |
| |||
7839 | 7840 | | |
7840 | 7841 | | |
7841 | 7842 | | |
7842 | | - | |
7843 | | - | |
7844 | | - | |
7845 | | - | |
7846 | | - | |
7847 | 7843 | | |
7848 | 7844 | | |
7849 | 7845 | | |
| |||
0 commit comments