Skip to content
This repository was archived by the owner on Apr 5, 2026. It is now read-only.

Commit a7e832e

Browse files
committed
fix: SIGSEGV in mtfront_pre_loop from CONN_INFO on listening connection
Root cause of intermittent CI crashes. CONN_INFO(LC)->window_clamp wrote at offset 512 into an 80-byte listening_connection_info allocation (432 bytes out of bounds). The job allocator's slab layout usually placed valid memory there, but occasionally hit a page boundary causing SIGSEGV. Fix: use LISTEN_CONN_INFO(LC) which accesses the correct struct. Both structs have a window_clamp field; net-connections.c:730 already copies LC->window_clamp to accepted connections correctly.
1 parent 6148f9f commit a7e832e

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

common/server-functions.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
#include <string.h>
5454
#include <sys/resource.h>
5555
#include <sys/wait.h>
56+
#ifdef HAVE_LIBUNWIND
5657
#include <ucontext.h>
58+
#endif
5759
#include <unistd.h>
5860
#include <pthread.h>
5961

@@ -250,32 +252,37 @@ void engine_set_terminal_attributes (void) {}
250252
void extended_debug_handler (int sig, siginfo_t *info, void *cont) {
251253
ksignal (sig, SIG_DFL);
252254

253-
/* Print faulting address and interrupted PC for crash diagnosis */
255+
#ifdef HAVE_LIBUNWIND
256+
/* Print faulting address and interrupted PC for crash diagnosis.
257+
Only in debug/test builds (HAVE_LIBUNWIND implies DEBUG_TOOLS). */
254258
if (info) {
255259
char buf[256];
256260
int len = snprintf (buf, sizeof (buf),
257261
"\n*** Signal %d, faulting address %p ***\n", sig, info->si_addr);
258262
if (len > 0) kwrite (2, buf, len);
259263
}
260-
#if defined(__x86_64__) || defined(__aarch64__)
264+
#if defined(__x86_64__)
261265
if (cont) {
262266
ucontext_t *uc = (ucontext_t *)cont;
263267
char buf[256];
264-
int len;
265-
#if defined(__x86_64__)
266-
len = snprintf (buf, sizeof (buf), "RIP=0x%llx RSP=0x%llx RBP=0x%llx\n",
268+
int len = snprintf (buf, sizeof (buf), "RIP=0x%llx RSP=0x%llx RBP=0x%llx\n",
267269
(unsigned long long)uc->uc_mcontext.gregs[REG_RIP],
268270
(unsigned long long)uc->uc_mcontext.gregs[REG_RSP],
269271
(unsigned long long)uc->uc_mcontext.gregs[REG_RBP]);
272+
if (len > 0) kwrite (2, buf, len);
273+
}
270274
#elif defined(__aarch64__)
271-
len = snprintf (buf, sizeof (buf), "PC=0x%lx SP=0x%lx LR=0x%lx\n",
275+
if (cont) {
276+
ucontext_t *uc = (ucontext_t *)cont;
277+
char buf[256];
278+
int len = snprintf (buf, sizeof (buf), "PC=0x%lx SP=0x%lx LR=0x%lx\n",
272279
(unsigned long)uc->uc_mcontext.pc,
273280
(unsigned long)uc->uc_mcontext.sp,
274281
(unsigned long)uc->uc_mcontext.regs[30]);
275-
#endif
276282
if (len > 0) kwrite (2, buf, len);
277283
}
278284
#endif
285+
#endif /* HAVE_LIBUNWIND */
279286

280287
print_backtrace ();
281288

mtproto/mtproto-proxy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ void mtfront_pre_loop (void) {
22872287
if (window_clamp) {
22882288
listening_connection_job_t LC = Events[http_sfd[i]].data;
22892289
assert (LC);
2290-
CONN_INFO(LC)->window_clamp = window_clamp;
2290+
LISTEN_CONN_INFO(LC)->window_clamp = window_clamp;
22912291
if (setsockopt (http_sfd[i], IPPROTO_TCP, TCP_WINDOW_CLAMP, &window_clamp, 4) < 0) {
22922292
vkprintf (0, "error while setting window size for socket #%d to %d: %m\n", http_sfd[i], window_clamp);
22932293
}

0 commit comments

Comments
 (0)