From 5ac6b3b12504e86a5be478b28f219a758e042fd7 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Wed, 14 Dec 2022 18:04:06 +0100 Subject: [PATCH] BUG/MINOR: quic: fix crash on PTO rearm if anti-amplification reset There is a possible segfault when accessing qc->timer_task in quic_conn_io_cb() without testing it. It seems however very rare as it requires several condition to be encounter. * quic_conn must be in CLOSING state after having sent a CONNECTION_CLOSE which free the qc.timer_task * quic_conn handshake must still be in progress : in fact, qc.timer_task is accessed on this path because of the anti-amplification limit lifted. I was unable thus far to trigger it but benchmarking tests seems to have fire it with the following backtrace as a result : #0 _task_wakeup (f=4096, caller=0x5620ed004a40 <_.46868>, t=0x0) at include/haproxy/task.h:195 195 state = _HA_ATOMIC_OR_FETCH(&t->state, f); [Current thread is 1 (Thread 0x7fc714ff1700 (LWP 14305))] (gdb) bt #0 _task_wakeup (f=4096, caller=0x5620ed004a40 <_.46868>, t=0x0) at include/haproxy/task.h:195 #1 quic_conn_io_cb (t=0x7fc5d0e07060, context=0x7fc5d0df49c0, state=) at src/quic_conn.c:4393 #2 0x00005620ecedab6e in run_tasks_from_lists (budgets=) at src/task.c:596 #3 0x00005620ecedb63c in process_runnable_tasks () at src/task.c:861 #4 0x00005620ecea971a in run_poll_loop () at src/haproxy.c:2913 #5 0x00005620ecea9cf9 in run_thread_poll_loop (data=) at src/haproxy.c:3102 #6 0x00007fc773c3f609 in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0 #7 0x00007fc77372d133 in clone () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) up #1 quic_conn_io_cb (t=0x7fc5d0e07060, context=0x7fc5d0df49c0, state=) at src/quic_conn.c:4393 4393 task_wakeup(qc->timer_task, TASK_WOKEN_MSG); (gdb) p qc $1 = (struct quic_conn *) 0x7fc5d0df49c0 (gdb) p qc->timer_task $2 = (struct task *) 0x0 This fix should be backported up to 2.6. --- src/quic_conn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quic_conn.c b/src/quic_conn.c index 69cbe1a98..60d5796d0 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -4389,7 +4389,7 @@ struct task *quic_conn_io_cb(struct task *t, void *context, unsigned int state) * datagram parser was not executed by only one thread. */ qc_set_timer(qc); - if (tick_isset(qc->timer) && tick_is_lt(qc->timer, now_ms)) + if (qc->timer_task && tick_isset(qc->timer) && tick_is_lt(qc->timer, now_ms)) task_wakeup(qc->timer_task, TASK_WOKEN_MSG); } ssl_err = SSL_ERROR_NONE;