From nobody Fri Feb 03 00:06:43 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P7GD36fKMz3kkxH; Fri, 3 Feb 2023 00:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P7GD35qzkz3n1l; Fri, 3 Feb 2023 00:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675382803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o9hiUsq76l1mkA8OAy5+Rstg12wKGvyV/hccIjFtr20=; b=KNU2MVQGX7hmtS1stTmA20cra8plYqbModC2y4H/fBSLGZV8voNV3Bq9oH3BGLxHKckeHV SRW7xSQwggWiFvnZubm8gaUQvoN8KHlcrAS1pdHwwduo4JVWXV7EZcCd0hUmqoWZmInQE7 vrAnnZK6VSUo/HZh5NnSLgqAb5QVAI66GK3fhhJLlhne9egZIP3H1yIZ3+E3n3yiyUj/Wh 08ayhtUJggAc/SWZUUo6l/88qQfTDVuFYeSQUhX5gr1m+yPQjM0zh4+8zzMwH7h8rWp3Y+ P+RW1t346DwqoIbPnwyM3G4rNaX9bQQFLLqI8jFbN1lN0H6pm/hIhupUG8O99g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675382803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=o9hiUsq76l1mkA8OAy5+Rstg12wKGvyV/hccIjFtr20=; b=QP/ZHfmeH7pPY0NIGqJ39oJTr+UnPXZIIAxrwPT/5LDoYd9AaSc5+johJopEBzFO/PDGVw /4tNSzTcDCYentxx2IFKrncRC1ql7fc3xDJ5kZPqU51W2fQ1Kubs/UVlFToWXUCqxAbtrM nUsSC1k3jBaKxTK4PEtaB4vcLnV3LS2zTMflsGzYYVGB9XcFMbKxYPwv8kMhw4FnpsSEa1 scvQhDbH0pJdli88LhTScR8L/911zEgwUvS3KoCSloTsfbp+eoXZ4jo/tBA5SDZ4xqe+Js NhACicbrQq0cdtPYgepKFei4FFNmSJvIyFK2If29cnY8VKuZ4sbWg57aige7Lw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675382803; a=rsa-sha256; cv=none; b=RSv/uP+0fLKE0yLSslUG56t6SoUDsogdRtn/jinM+BTyzRcdON6wImkvCw+aJ2GzmUGn5G yLB8WHFZtDeHkvvvA8X1+fO6LL7dIlg3OXAaVrh87vmxhyqWO6jF8UBS3Aw/BONK2nbyJI zkjczS7wOQIygU3mqttkNHLHOBP9VY4D7kc4tHGZ8bDGDkgaNGWXCV3LcIC/u1300gR012 wd0O2jG5Wd4FESPTMOA06MSqxPFMzsgAcFlWsuVm3uaPXpII6RBvtLiulw1+PPP0OolRwU C8Md8sXqGgQ+cFTnYJuVO2pS3x/PlmXYcoCSh/dHlnuKerD9FZQ/pB/XEuxfkQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P7GD34SdRzFKh; Fri, 3 Feb 2023 00:06:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31306hIJ077464; Fri, 3 Feb 2023 00:06:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31306hrg077463; Fri, 3 Feb 2023 00:06:43 GMT (envelope-from git) Date: Fri, 3 Feb 2023 00:06:43 GMT Message-Id: <202302030006.31306hrg077463@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: c6522961cf5e - stable/13 - cxgbe tom: Force unsigned modulus for queue indices. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c6522961cf5ef7ecc5f4da49620f68f6e2125a0c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=c6522961cf5ef7ecc5f4da49620f68f6e2125a0c commit c6522961cf5ef7ecc5f4da49620f68f6e2125a0c Author: John Baldwin AuthorDate: 2022-05-04 22:59:44 +0000 Commit: John Baldwin CommitDate: 2023-02-02 23:28:59 +0000 cxgbe tom: Force unsigned modulus for queue indices. The final transmit and receive queue indices need to be positive values. However, since txq_idx and rxq_idx are signed (to permit using -1 to as a marker for uninitialized values), using %= with another integer type (vi->nofld[tr]xq) yielded a sign-extended modulus value. This resulted in negative queue indices and a buffer underrun when arc4random() returned a value with the sign bit set. Use a temporary unsigned variable to hold the "raw" queue index to force unsigned modulus. This worked previously because the modulus was previously applied directly to the return value of arc4random() which is unsigned before the result was assigned to txq_idx and rxq_idx. Discussed with: np Fixes: db28d4a0cd1c cxgbe/t4_tom: Support for round-robin selection of offload queues. Sponsored by: Chelsio Communications (cherry picked from commit b483b6b256b2957f857db9092ef3c420a5143972) --- sys/dev/cxgbe/tom/t4_tom.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sys/dev/cxgbe/tom/t4_tom.c b/sys/dev/cxgbe/tom/t4_tom.c index 25a63b992287..0fbcde5e0b57 100644 --- a/sys/dev/cxgbe/tom/t4_tom.c +++ b/sys/dev/cxgbe/tom/t4_tom.c @@ -1138,6 +1138,7 @@ init_conn_params(struct vi_info *vi , struct offload_settings *s, struct inpcb *inp = sotoinpcb(so); struct tcpcb *tp = intotcpcb(inp); u_long wnd; + u_int q_idx; MPASS(s->offload != 0); @@ -1222,23 +1223,21 @@ init_conn_params(struct vi_info *vi , struct offload_settings *s, /* Tx queue for this connection. */ if (s->txq == QUEUE_RANDOM) - cp->txq_idx = arc4random(); + q_idx = arc4random(); else if (s->txq == QUEUE_ROUNDROBIN) - cp->txq_idx = atomic_fetchadd_int(&vi->txq_rr, 1); + q_idx = atomic_fetchadd_int(&vi->txq_rr, 1); else - cp->txq_idx = s->txq; - cp->txq_idx %= vi->nofldtxq; - cp->txq_idx += vi->first_ofld_txq; + q_idx = s->txq; + cp->txq_idx = vi->first_ofld_txq + q_idx % vi->nofldtxq; /* Rx queue for this connection. */ if (s->rxq == QUEUE_RANDOM) - cp->rxq_idx = arc4random(); + q_idx = arc4random(); else if (s->rxq == QUEUE_ROUNDROBIN) - cp->rxq_idx = atomic_fetchadd_int(&vi->rxq_rr, 1); + q_idx = atomic_fetchadd_int(&vi->rxq_rr, 1); else - cp->rxq_idx = s->rxq; - cp->rxq_idx %= vi->nofldrxq; - cp->rxq_idx += vi->first_ofld_rxq; + q_idx = s->rxq; + cp->rxq_idx = vi->first_ofld_rxq + q_idx % vi->nofldrxq; if (SOLISTENING(so)) { /* Passive open */