Skip to contentSkip to conversation

cifs: fix potential use-after-free in cifs_echo_request()

PATCH In review Paulo Alcantara 2 participants 2 messages Nov 28, 2020 – Nov 30, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix potential use-after-free in cifs_echo_request()

This patch fixes a potential use-after-free bug in cifs_echo_request().

For instance,

thread 1
--------
cifs_demultiplex_thread()
clean_demultiplex_info()
kfree(server)

thread 2 (workqueue)
--------
apic_timer_interrupt()

    smp_apic_timer_interrupt()
      irq_exit()
        __do_softirq()
          run_timer_softirq()
            call_timer_fn()

cifs_echo_request() <- use-after-free in server ptr

---
 fs/cifs/connect.c | 2 ++
 1 file changed, 2 insertions(+)
fs/cifs/connect.c +2 -0
index c38156f324dd..28c1459fb0fc 100644
@@ -876,6 +876,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
 	list_del_init(&server->tcp_ses_list);
 	spin_unlock(&cifs_tcp_ses_lock);
 
+	cancel_delayed_work_sync(&server->echo);
+
 	spin_lock(&GlobalMid_Lock);
 	server->tcpStatus = CifsExiting;
 	spin_unlock(&GlobalMid_Lock);
Signature · 1 line
2.29.2
#1 lore raw

added Ronnie's reviewed-by to the two patches and put in cifs-2.6.git for-next

Quoted 43 lines · Paulo Alcantara

This patch fixes a potential use-after-free bug in cifs_echo_request().

For instance,

thread 1
--------
cifs_demultiplex_thread()
clean_demultiplex_info()
kfree(server)

thread 2 (workqueue)
--------
apic_timer_interrupt()

    smp_apic_timer_interrupt()
      irq_exit()
        __do_softirq()
          run_timer_softirq()
            call_timer_fn()
              cifs_echo_request() <- use-after-free in server ptr
---
 fs/cifs/connect.c | 2 ++
 1 file changed, 2 insertions(+)
fs/cifs/connect.c +2 -1
index c38156f324dd..28c1459fb0fc 100644
@@ -876,6 +876,8 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
        list_del_init(&server->tcp_ses_list);
        spin_unlock(&cifs_tcp_ses_lock);
 
+       cancel_delayed_work_sync(&server->echo);
+
        spin_lock(&GlobalMid_Lock);
        server->tcpStatus = CifsExiting;
        spin_unlock(&GlobalMid_Lock);
--

2.29.2

Signature · 3 lines
Thanks,

Steve