From 9e1771423d5b08b5207a160dff3a98ab59aa0f02 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 21 Jan 2021 09:07:29 +0100 Subject: [PATCH] MINOR: cli/show_fd: report some easily detectable suspicious states A file descriptor which maps to a connection but has more than one thread in its mask, or an FD handle that doesn't correspond to the FD, or wiht no mux context, or an FD with no thread in its mask, or with more than 1 million events is flagged as suspicious. (cherry picked from commit dacfde4ba42e3a13dd5b13b7df7a37db06d702a6) Signed-off-by: Willy Tarreau --- src/cli.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/cli.c b/src/cli.c index 47b28fc..3331c7c 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1061,10 +1061,17 @@ static int cli_io_handler_show_fd(struct appctx *appctx) sv = objt_server(conn->target); px = objt_proxy(conn->target); is_back = conn_is_back(conn); + if (atleast2(fdt.thread_mask)) + suspicious = 1; + if (conn->handle.fd != fd) + suspicious = 1; } else if (fdt.iocb == sock_accept_iocb) li = fdt.owner; + if (!fdt.thread_mask) + suspicious = 1; + chunk_printf(&trash, " %5d : st=0x%02x(R:%c%c W:%c%c) ev=0x%02x(%c%c%c%c%c) [%c%c] tmask=0x%lx umask=0x%lx owner=%p iocb=%p(", fd, @@ -1091,6 +1098,12 @@ static int cli_io_handler_show_fd(struct appctx *appctx) } else if (fdt.iocb == conn_fd_handler) { chunk_appendf(&trash, ") back=%d cflg=0x%08x", is_back, conn_flags); + + if (conn->handle.fd != fd) { + chunk_appendf(&trash, " fd=%d(BOGUS)", conn->handle.fd); + suspicious = 1; + } + if (px) chunk_appendf(&trash, " px=%s", px->id); else if (sv) @@ -1100,6 +1113,8 @@ static int cli_io_handler_show_fd(struct appctx *appctx) if (mux) { chunk_appendf(&trash, " mux=%s ctx=%p", mux->name, ctx); + if (!ctx) + suspicious = 1; if (mux->show_fd) suspicious |= mux->show_fd(&trash, fdt.owner); } @@ -1124,6 +1139,8 @@ static int cli_io_handler_show_fd(struct appctx *appctx) #ifdef DEBUG_FD chunk_appendf(&trash, " evcnt=%u", fdtab[fd].event_count); + if (fdtab[fd].event_count >= 1000000) + suspicious = 1; #endif chunk_appendf(&trash, "%s\n", suspicious ? " !" : ""); -- 1.7.10.4