Commit 61cc453
locking/lockdep: Avoid potential access of invalid memory in lock_class
It was found that reading /proc/lockdep after a lockdep splat may
potentially cause an access to freed memory if lockdep_unregister_key()
is called after the splat but before access to /proc/lockdep [1]. This
is due to the fact that graph_lock() call in lockdep_unregister_key()
fails after the clearing of debug_locks by the splat process.
After lockdep_unregister_key() is called, the lock_name may be freed
but the corresponding lock_class structure still have a reference to
it. That invalid memory pointer will then be accessed when /proc/lockdep
is read by a user and a use-after-free (UAF) error will be reported if
KASAN is enabled.
To fix this problem, lockdep_unregister_key() is now modified to always
search for a matching key irrespective of the debug_locks state and
zap the corresponding lock class if a matching one is found.
[1] https://lore.kernel.org/lkml/77f05c15-81b6-bddd-9650-80d5f23fe330@i-love.sakura.ne.jp/
Fixes: 8b39adb ("locking/lockdep: Make lockdep_unregister_key() honor 'debug_locks' again")
Reported-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lkml.kernel.org/r/20220103023558.1377055-1-longman@redhat.com1 parent e204193 commit 61cc453
1 file changed
Lines changed: 15 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6287 | 6287 | | |
6288 | 6288 | | |
6289 | 6289 | | |
6290 | | - | |
| 6290 | + | |
| 6291 | + | |
| 6292 | + | |
| 6293 | + | |
| 6294 | + | |
| 6295 | + | |
| 6296 | + | |
6291 | 6297 | | |
6292 | 6298 | | |
6293 | 6299 | | |
| |||
6302 | 6308 | | |
6303 | 6309 | | |
6304 | 6310 | | |
6305 | | - | |
6306 | | - | |
| 6311 | + | |
6307 | 6312 | | |
6308 | | - | |
6309 | 6313 | | |
6310 | 6314 | | |
6311 | 6315 | | |
6312 | 6316 | | |
6313 | 6317 | | |
6314 | 6318 | | |
6315 | 6319 | | |
6316 | | - | |
6317 | | - | |
6318 | | - | |
6319 | | - | |
6320 | | - | |
| 6320 | + | |
| 6321 | + | |
| 6322 | + | |
| 6323 | + | |
| 6324 | + | |
| 6325 | + | |
| 6326 | + | |
6321 | 6327 | | |
6322 | 6328 | | |
6323 | 6329 | | |
| |||
0 commit comments