From owner-svn-src-head@freebsd.org Mon Oct 16 17:04:25 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6C3E1E3F5C7; Mon, 16 Oct 2017 17:04:25 +0000 (UTC) (envelope-from jonlooney@gmail.com) Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 002AA3E10; Mon, 16 Oct 2017 17:04:24 +0000 (UTC) (envelope-from jonlooney@gmail.com) Received: by mail-wm0-x235.google.com with SMTP id q124so5408266wmb.0; Mon, 16 Oct 2017 10:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=GzRE2BMNbpl7b+bMmXWFi7HHRgJs0NSB4PCz/+NeMX0=; b=YzoIFanyU6xxtNJ6926zVaYv3IddT4vOcjnGYSZrouEBObK8ouQHIxc1zrzomIEZzh y3iz0/CY05PcPyiyyXT4hCQDRgfoNO0YbaoKT/ZuAr4FFAnxwdIRxbfHVr0zbuJM1K1x cL7IWRJ8Xm5jUcf5UmgzQAUIPbc8Rjcxz+mOFLHlH7wv6vh+w6YfKlHJ9+dtzKLn0Gu8 8HC0mWg6R6h+PKG7mT41A9ygG+YeiNqxZINg2mF0vIdlSHwmTABPI7iT+qS1nQg837Dl kKEoAaKMEdgHDlaAWMcEi2DiB8FUh//01xq2Umwvkx6eD2chcnuVw0EVVpWYh4pHrhRE 3T8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GzRE2BMNbpl7b+bMmXWFi7HHRgJs0NSB4PCz/+NeMX0=; b=bddbtyPYVw6TvA/bu4gmHRzqm32sUnYNKr92ysV3SdHsM5Rgu9X1Y+4In6U0t0uHQU n5O9AAoI965MLy/cnpR6H1nG3yNLqrwY0GOPY+gZynh2MLBjSjkS5oGEFn3y9sjVsGOp MBRTVjRSQk0nnbUz+sVx2Cb/ga7H3/hKuszL0cE2/FL+cyNHGpAsh1ohoN3nLW9CPzuw v7MsXUm0L48oGOA+BcoCw4h5+rJYj1iyLfuReNlk67Q1VjLq3EVzgDTbtl6SxDzamCCy sT6pWYd8c9tODhZ5+KR5bmRndiEEGgv7iobqkSF8sUkyBWXW7j3ZFKvLnOGPtj6YzQnD aIYA== X-Gm-Message-State: AMCzsaXfobduIqkQi6v6gc3UFtoaGPVG1R68hzNt7ZfEtORTSwGO2kwb 3VnyphqVUHp1Bh7FJM/03AzDV7VKQvys7AVly0SOkg== X-Google-Smtp-Source: ABhQp+TaEmBq+GR8c3+nLIZ9DpSUCNk6fWKfEXodqtz9dnnYCxtLY7BYzhnOQ4KZUi4R3SIcWqZgGi1TTUx9024gAGg= X-Received: by 10.28.174.67 with SMTP id x64mr1577141wme.82.1508173463150; Mon, 16 Oct 2017 10:04:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.150.149 with HTTP; Mon, 16 Oct 2017 10:04:22 -0700 (PDT) In-Reply-To: <201710012120.v91LKSH1050145@repo.freebsd.org> References: <201710012120.v91LKSH1050145@repo.freebsd.org> From: Jonathan Looney Date: Mon, 16 Oct 2017 13:04:22 -0400 Message-ID: Subject: Re: svn commit: r324179 - head/sys/netinet To: Julien Charbon Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Oct 2017 17:04:25 -0000 Hi Julien, I apologize for just getting to this, but your code just made it into my local tree. The non-INVARIANTS case looks incorrect. Because tw stays on the list, it can end up stuck at the front of the queue and block everything behind it. Personally, I would be more comfortable just panic'ing here. This indicates a problem. And, depending on the way things got corrupted, you could end up with other hard-to-debug problems if you continue with a corrupted state. Jonathan On Sun, Oct 1, 2017 at 5:20 PM, Julien Charbon wrote: > Author: jch > Date: Sun Oct 1 21:20:28 2017 > New Revision: 324179 > URL: https://svnweb.freebsd.org/changeset/base/324179 > > Log: > Fix an infinite loop in tcp_tw_2msl_scan() when an INP_TIMEWAIT inp has > been destroyed before its tcptw with INVARIANTS undefined. > > This is a symmetric change of r307551: > > A INP_TIMEWAIT inp should not be destroyed before its tcptw, and > INVARIANTS > will catch this case. If INVARIANTS is undefined it will emit a > log(LOG_ERR) > and avoid a hard to debug infinite loop in tcp_tw_2msl_scan(). > > Reported by: Ben Rubson, hselasky > Submitted by: hselasky > Tested by: Ben Rubson, jch > MFC after: 1 week > Sponsored by: Verisign, inc > Differential Revision: https://reviews.freebsd.org/D12267 > > Modified: > head/sys/netinet/tcp_timewait.c > > Modified: head/sys/netinet/tcp_timewait.c > ============================================================ > ================== > --- head/sys/netinet/tcp_timewait.c Sun Oct 1 20:12:30 2017 > (r324178) > +++ head/sys/netinet/tcp_timewait.c Sun Oct 1 21:20:28 2017 > (r324179) > @@ -709,10 +709,29 @@ tcp_tw_2msl_scan(int reuse) > INP_WLOCK(inp); > tw = intotw(inp); > if (in_pcbrele_wlocked(inp)) { > - KASSERT(tw == NULL, ("%s: held last inp " > - "reference but tw not NULL", > __func__)); > - INP_INFO_RUNLOCK(&V_tcbinfo); > - continue; > + if (__predict_true(tw == NULL)) { > + INP_INFO_RUNLOCK(&V_tcbinfo); > + continue; > + } else { > + /* This should not happen as in > TIMEWAIT > + * state the inp should not be > destroyed > + * before its tcptw. If INVARIANTS > is > + * defined panic. > + */ > +#ifdef INVARIANTS > + panic("%s: Panic before an > infinite " > + "loop: INP_TIMEWAIT && > (INP_FREED " > + "|| inp last reference) && tw > != " > + "NULL", __func__); > +#else > + log(LOG_ERR, "%s: Avoid an > infinite " > + "loop: INP_TIMEWAIT && > (INP_FREED " > + "|| inp last reference) && tw > != " > + "NULL", __func__); > +#endif > + INP_INFO_RUNLOCK(&V_tcbinfo); > + break; > + } > } > > if (tw == NULL) { > >