]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
locking/lockdep: Avoid potential access of invalid memory in lock_class
authorWaiman Long <longman@redhat.com>
Mon, 3 Jan 2022 02:35:58 +0000 (21:35 -0500)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:37:18 +0000 (14:37 +0200)
commitb8da17a0c04b2d7ef40ef2ad568aa3e427eb7253
treed18b84665b332e17e5f11b6e4bfffecba861a1c7
parentec97f2d817477d35fbdb295280d00739dc477b50
locking/lockdep: Avoid potential access of invalid memory in lock_class

BugLink: https://bugs.launchpad.net/bugs/1969110
commit 61cc4534b6550997c97a03759ab46b29d44c0017 upstream.

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: 8b39adbee805 ("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>
Cc: Cheng-Jui Wang <cheng-jui.wang@mediatek.com>
Link: https://lkml.kernel.org/r/20220103023558.1377055-1-longman@redhat.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 03f836fcb655417693aef350dcb830451ab7d388)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
kernel/locking/lockdep.c