Jiri Slaby 303b0b
From: Min Li <lm0963hack@gmail.com>
Jiri Slaby 303b0b
Date: Sat, 4 Mar 2023 22:23:30 +0800
Jiri Slaby 303b0b
Subject: [PATCH] Bluetooth: Fix race condition in hidp_session_thread
Jiri Slaby 303b0b
References: bsc#1012628
Jiri Slaby 303b0b
Patch-mainline: 6.2.12
Jiri Slaby 303b0b
Git-commit: c95930abd687fcd1aa040dc4fe90dff947916460
Jiri Slaby 303b0b
Jiri Slaby 303b0b
commit c95930abd687fcd1aa040dc4fe90dff947916460 upstream.
Jiri Slaby 303b0b
Jiri Slaby 303b0b
There is a potential race condition in hidp_session_thread that may
Jiri Slaby 303b0b
lead to use-after-free. For instance, the timer is active while
Jiri Slaby 303b0b
hidp_del_timer is called in hidp_session_thread(). After hidp_session_put,
Jiri Slaby 303b0b
then 'session' will be freed, causing kernel panic when hidp_idle_timeout
Jiri Slaby 303b0b
is running.
Jiri Slaby 303b0b
Jiri Slaby 303b0b
The solution is to use del_timer_sync instead of del_timer.
Jiri Slaby 303b0b
Jiri Slaby 303b0b
Here is the call trace:
Jiri Slaby 303b0b
Jiri Slaby 303b0b
? hidp_session_probe+0x780/0x780
Jiri Slaby 303b0b
call_timer_fn+0x2d/0x1e0
Jiri Slaby 303b0b
__run_timers.part.0+0x569/0x940
Jiri Slaby 303b0b
hidp_session_probe+0x780/0x780
Jiri Slaby 303b0b
call_timer_fn+0x1e0/0x1e0
Jiri Slaby 303b0b
ktime_get+0x5c/0xf0
Jiri Slaby 303b0b
lapic_next_deadline+0x2c/0x40
Jiri Slaby 303b0b
clockevents_program_event+0x205/0x320
Jiri Slaby 303b0b
run_timer_softirq+0xa9/0x1b0
Jiri Slaby 303b0b
__do_softirq+0x1b9/0x641
Jiri Slaby 303b0b
__irq_exit_rcu+0xdc/0x190
Jiri Slaby 303b0b
irq_exit_rcu+0xe/0x20
Jiri Slaby 303b0b
sysvec_apic_timer_interrupt+0xa1/0xc0
Jiri Slaby 303b0b
Jiri Slaby 303b0b
Cc: stable@vger.kernel.org
Jiri Slaby 303b0b
Signed-off-by: Min Li <lm0963hack@gmail.com>
Jiri Slaby 303b0b
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Jiri Slaby 303b0b
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Jiri Slaby 303b0b
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Jiri Slaby 303b0b
---
Jiri Slaby 303b0b
 net/bluetooth/hidp/core.c | 2 +-
Jiri Slaby 303b0b
 1 file changed, 1 insertion(+), 1 deletion(-)
Jiri Slaby 303b0b
Jiri Slaby 303b0b
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
Jiri Slaby 303b0b
index cc20e706..82cc15ad 100644
Jiri Slaby 303b0b
--- a/net/bluetooth/hidp/core.c
Jiri Slaby 303b0b
+++ b/net/bluetooth/hidp/core.c
Jiri Slaby 303b0b
@@ -433,7 +433,7 @@ static void hidp_set_timer(struct hidp_session *session)
Jiri Slaby 303b0b
 static void hidp_del_timer(struct hidp_session *session)
Jiri Slaby 303b0b
 {
Jiri Slaby 303b0b
 	if (session->idle_to > 0)
Jiri Slaby 303b0b
-		del_timer(&session->timer);
Jiri Slaby 303b0b
+		del_timer_sync(&session->timer);
Jiri Slaby 303b0b
 }
Jiri Slaby 303b0b
 
Jiri Slaby 303b0b
 static void hidp_process_report(struct hidp_session *session, int type,
Jiri Slaby 303b0b
-- 
Jiri Slaby 303b0b
2.35.3
Jiri Slaby 303b0b