From: Willy Tarreau Date: Fri, 27 Jul 2018 16:07:41 +0000 (+0200) Subject: BUG/MEDIUM: threads: unbreak "bind" referencing an incorrect thread number X-Git-Tag: v1.9-dev1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c477b6fcc91c382f7edc2caca692c4059487cd6f;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: threads: unbreak "bind" referencing an incorrect thread number The "process" directive on "bind" lines supports process references and thread references. No check is performed on the thread number validity, so that if a listener is only bound to non-existent threads, the traffic will never be processed. It easily happens when setting one bind line per thread with an incorrect (or reduced) thread count. No warning appears and some random connections are never served. It also happens when setting thread references with threads support disabled at build time. This patch makes use of the all_threads_mask variable to detect if some referenced threads don't exist, to emit a warning and fix this. This patch needs to be backported to 1.8, just like the previous one which it depends on (MINOR: threads: move "nbthread" parsing to hathreads.c). --- diff --git a/src/cfgparse.c b/src/cfgparse.c index 803a9189bd..5abe9fa0ca 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -7581,6 +7581,29 @@ int check_config_validity() } /* HTTP && bufsize < 16384 */ #endif + /* detect and address thread affinity inconsistencies */ + nbproc = 0; + if (bind_conf->bind_proc) + nbproc = my_ffsl(bind_conf->bind_proc); + + mask = bind_conf->bind_thread[nbproc - 1]; + if (mask && !(mask & (all_threads_mask ? all_threads_mask : 1UL))) { + unsigned long new_mask = 0; + + while (mask) { + new_mask |= mask & (all_threads_mask ? all_threads_mask : 1UL); + mask >>= global.nbthread; + } + + for (nbproc = 0; nbproc < LONGBITS; nbproc++) { + if (!bind_conf->bind_proc || (bind_conf->bind_proc & (1UL << nbproc))) + bind_conf->bind_thread[nbproc] = new_mask; + } + ha_warning("Proxy '%s': the thread range specified on the 'process' directive of 'bind %s' at [%s:%d] only refers to thread numbers out of the range defined by the global 'nbthread' directive. The thread numbers were remapped to existing threads instead (mask 0x%lx).\n", + curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line, new_mask); + } + + /* detect process and nbproc affinity inconsistencies */ if (!bind_conf->bind_proc) continue;