summaryrefslogtreecommitdiff
path: root/kernel/locking/rtmutex.c
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2021-02-04 17:29:03 +0000
committerPanwar Vijay Kumar <pvijayku@codeaurora.org>2021-09-28 11:34:39 +0530
commit7075ca6a22b3097b96e0167f9a62619ee64d0a12 (patch)
tree78531b53516fb90f0979201b489a5cac9c3983f5 /kernel/locking/rtmutex.c
parenta436b73e9032cdc9731255d950bb524739db037e (diff)
futex: Handle faults correctly for PI futexes
From: Thomas Gleixner <tglx@linutronix.de> fixup_pi_state_owner() tries to ensure that the state of the rtmutex, pi_state and the user space value related to the PI futex are consistent before returning to user space. In case that the user space value update faults and the fault cannot be resolved by faulting the page in via fault_in_user_writeable() the function returns with -EFAULT and leaves the rtmutex and pi_state owner state inconsistent. A subsequent futex_unlock_pi() operates on the inconsistent pi_state and releases the rtmutex despite not owning it which can corrupt the RB tree of the rtmutex and cause a subsequent kernel stack use after free. It was suggested to loop forever in fixup_pi_state_owner() if the fault cannot be resolved, but that results in runaway tasks which is especially undesired when the problem happens due to a programming error and not due to malice. As the user space value cannot be fixed up, the proper solution is to make the rtmutex and the pi_state consistent so both have the same owner. This leaves the user space value out of sync. Any subsequent operation on the futex will fail because the 10th rule of PI futexes (pi_state owner and user space value are consistent) has been violated. As a consequence this removes the inept attempts of 'fixing' the situation in case that the current task owns the rtmutex when returning with an unresolvable fault by unlocking the rtmutex which left pi_state::owner and rtmutex::owner out of sync in a different and only slightly less dangerous way. Fixes: 1b7558e457ed ("futexes: fix fault handling in futex_lock_pi") Reported-by: gzobqq@gmail.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: stable@vger.kernel.org Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Git-commit: 46358277b2da868763517f79aa0ac25ce78c4f68 Git-repo: https://android.googlesource.com/kernel/common/ Change-Id: I9c0cf904296c48cee1bbeae00680f620708e37d8 Signed-off-by: pvijayku <pvijayku@codeaurora.org>
Diffstat (limited to 'kernel/locking/rtmutex.c')
0 files changed, 0 insertions, 0 deletions