Commit e2a9f73
md: fix mddev uaf while iterating all_mddevs list
commit 8542870 upstream.
While iterating all_mddevs list from md_notify_reboot() and md_exit(),
list_for_each_entry_safe is used, and this can race with deletint the
next mddev, causing UAF:
t1:
spin_lock
//list_for_each_entry_safe(mddev, n, ...)
mddev_get(mddev1)
// assume mddev2 is the next entry
spin_unlock
t2:
//remove mddev2
...
mddev_free
spin_lock
list_del
spin_unlock
kfree(mddev2)
mddev_put(mddev1)
spin_lock
//continue dereference mddev2->all_mddevs
The old helper for_each_mddev() actually grab the reference of mddev2
while holding the lock, to prevent from being freed. This problem can be
fixed the same way, however, the code will be complex.
Hence switch to use list_for_each_entry, in this case mddev_put() can free
the mddev1 and it's not safe as well. Refer to md_seq_show(), also factor
out a helper mddev_put_locked() to fix this problem.
Cc: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/linux-raid/[email protected]
Fixes: f265143 ("md: stop using for_each_mddev in md_notify_reboot")
Fixes: 16648ba ("md: stop using for_each_mddev in md_exit")
Reported-and-tested-by: Guillaume Morin <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Yu Kuai <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Cc: Salvatore Bonaccorso <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>1 parent 6ea2e87 commit e2a9f73
1 file changed
+13
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
629 | 629 | | |
630 | 630 | | |
631 | 631 | | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
632 | 638 | | |
633 | 639 | | |
634 | 640 | | |
| |||
8461 | 8467 | | |
8462 | 8468 | | |
8463 | 8469 | | |
8464 | | - | |
8465 | | - | |
8466 | | - | |
| 8470 | + | |
8467 | 8471 | | |
8468 | 8472 | | |
8469 | 8473 | | |
| |||
9886 | 9890 | | |
9887 | 9891 | | |
9888 | 9892 | | |
9889 | | - | |
| 9893 | + | |
9890 | 9894 | | |
9891 | 9895 | | |
9892 | 9896 | | |
9893 | | - | |
| 9897 | + | |
9894 | 9898 | | |
9895 | 9899 | | |
9896 | 9900 | | |
| |||
9902 | 9906 | | |
9903 | 9907 | | |
9904 | 9908 | | |
9905 | | - | |
9906 | 9909 | | |
| 9910 | + | |
9907 | 9911 | | |
9908 | 9912 | | |
9909 | 9913 | | |
| |||
10236 | 10240 | | |
10237 | 10241 | | |
10238 | 10242 | | |
10239 | | - | |
| 10243 | + | |
10240 | 10244 | | |
10241 | 10245 | | |
10242 | 10246 | | |
| |||
10257 | 10261 | | |
10258 | 10262 | | |
10259 | 10263 | | |
10260 | | - | |
| 10264 | + | |
10261 | 10265 | | |
10262 | 10266 | | |
10263 | 10267 | | |
| |||
10269 | 10273 | | |
10270 | 10274 | | |
10271 | 10275 | | |
10272 | | - | |
10273 | 10276 | | |
| 10277 | + | |
10274 | 10278 | | |
10275 | 10279 | | |
10276 | 10280 | | |
| |||
0 commit comments