From nobody Tue Apr 18 12:40:15 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 4Q13RN2qM0z453HL; Tue, 18 Apr 2023 12:40:16 +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 4Q13RN1QKZz3nkG; Tue, 18 Apr 2023 12:40:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681821616; 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=kLS0L6MQQYfsa7tC8d+FUMXwjuIHOE3ei3S4PH8CBwo=; b=NlYVatBVog08GnOF1zBpHZsdkKyxYs/ki6aMY16v4XjMBCCoY38fe6Wk18/qiW2k+Zimsh AShAH1d14TsUlCWFvzkTlqpzART9RF+h2xrNz6vCJ3zqxuHLwy11vJEPNughRf3x/PODim PSZLXan3TBNELkMmzGVekLiDWPUUjD04alLiEx6kltc0FwmwWNp+jeEsv2HVnMat7ku/Uf LJUDEe7m5izdI0JQ/9AZzczshpB7X8mWCD/5tXhypG2GDrwDozNBXQekV7ubwBchBw8KWw cJVIGu9xiPFTGk5upCJIy/S5JC0Ox2vViuEe3CNGOxF/BqqduhiJ294Hkyxz8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681821616; 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=kLS0L6MQQYfsa7tC8d+FUMXwjuIHOE3ei3S4PH8CBwo=; b=yolkEUgQ8/OyLLLjH3joVumPrC4/jx/Q3pFncA9bGBeYHnbxRITXuu/hgdVp3evZTPb9rV GaZOAkA+Z5lbCUs2hWXnemq8PtZHD5OzIGPfeTuUVLIkJ0urIhUewvvUP6eLfPAADR71qa 6gLi29e6fpJrO9UF1/GeTJ0HWxv/23m/jCaHI2V5jYxslBqsrw6X+90SPV5YnEPDTVbIGf xD7Wus0H4QHSdovBO63NgKngvMQm7HQlZQ2vDV6kMDmJ7+CHFJLI8U3h+8Zk/WgE/OEt1H al4FLXxYxtRRzH3uaSc2yDZJdQESdNdbFlDhXBTXlMWysUfvEheFjGttdzH1DA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681821616; a=rsa-sha256; cv=none; b=gNKwydSFF6cYDeZkUxWzqCr+aiyVywaq5Do3M7aiy4P4u0BgrYnWQ7F+aXbHCttL0HFquV 5Vx8jwKPThmT7fUEC8sqAQuEkLLp05TR4X++DzLKOLbXD70gDaEl9iiHvrYnKhgDq2wltv hZfBbdPtafT37ld2xpzRJ3cxEZyGJmFgjeCwZkhyPtMF26iRiQqowBPqktcf+r4vClTpYS JVw1bxlBGa9K/W0MbvzyxiIap0JFcV1QmbV5Ka6HEx4tpCEvfBsWIjylS3XCmeWuaBqkhj JrXEr0Qg08ZZZiXoBMzmzBYPjTUPyZuheprK9OeSeqtJwC4nXx5iWM+LSL3p3A== 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 4Q13RN09k0z19rH; Tue, 18 Apr 2023 12:40:16 +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 33ICeF24038557; Tue, 18 Apr 2023 12:40:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33ICeF0K038547; Tue, 18 Apr 2023 12:40:15 GMT (envelope-from git) Date: Tue, 18 Apr 2023 12:40:15 GMT Message-Id: <202304181240.33ICeF0K038547@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Randall Stewart Subject: git: 37229fed38c6 - main - tcp: Blackbox logging and tcp accounting together can cause a crash. 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: rrs X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 37229fed38c68b26a497f4fb189d4b8e35346232 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rrs: URL: https://cgit.FreeBSD.org/src/commit/?id=37229fed38c68b26a497f4fb189d4b8e35346232 commit 37229fed38c68b26a497f4fb189d4b8e35346232 Author: Randall Stewart AuthorDate: 2023-04-17 17:52:00 +0000 Commit: Randall Stewart CommitDate: 2023-04-17 17:52:00 +0000 tcp: Blackbox logging and tcp accounting together can cause a crash. If you currently turn BB logging on and in combination have TCP Accounting on we can get a crash where we have no NULL check and we run out of memory. Also lets make sure we don't do a divide by 0 in calculating any BB ratios. Reviewed by: tuexen Sponsored by: Netflix Inc Differential Revision:https://reviews.freebsd.org/D39622 --- sys/netinet/tcp_log_buf.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/sys/netinet/tcp_log_buf.c b/sys/netinet/tcp_log_buf.c index 5a16c7593cfc..c533f8329fbe 100644 --- a/sys/netinet/tcp_log_buf.c +++ b/sys/netinet/tcp_log_buf.c @@ -554,7 +554,10 @@ tcp_log_apply_ratio(struct tcpcb *tp, int ratio) INP_WUNLOCK(inp); return (EOPNOTSUPP); } - ratio_hash_thresh = max(1, UINT32_MAX / ratio); + if (ratio) + ratio_hash_thresh = max(1, UINT32_MAX / ratio); + else + ratio_hash_thresh = 0; TCPID_BUCKET_REF(tlb); INP_WUNLOCK(inp); TCPID_BUCKET_LOCK(tlb); @@ -1438,30 +1441,33 @@ tcp_log_tcpcbfini(struct tcpcb *tp) memset(&log, 0, sizeof(log)); if (tp->t_flags2 & TF2_TCP_ACCOUNTING) { - for (i = 0; itcp_cnt_counters[i]; } lgb = tcp_log_event(tp, NULL, - NULL, - NULL, - TCP_LOG_ACCOUNTING, 0, - 0, &log, false, NULL, NULL, 0, &tv); - lgb->tlb_flex1 = TCP_NUM_CNT_COUNTERS; - lgb->tlb_flex2 = 1; + NULL, + NULL, + TCP_LOG_ACCOUNTING, 0, + 0, &log, false, NULL, NULL, 0, &tv); + if (lgb != NULL) { + lgb->tlb_flex1 = TCP_NUM_CNT_COUNTERS; + lgb->tlb_flex2 = 1; + } else + goto skip_out; for (i = 0; itcp_proc_time[i]; } lgb = tcp_log_event(tp, NULL, - NULL, - NULL, - TCP_LOG_ACCOUNTING, 0, - 0, &log, false, NULL, NULL, 0, &tv); - if (tptoinpcb(tp)->inp_flags2 & INP_MBUF_ACKCMP) + NULL, + NULL, + TCP_LOG_ACCOUNTING, 0, + 0, &log, false, NULL, NULL, 0, &tv); + if (lgb != NULL) { lgb->tlb_flex1 = TCP_NUM_CNT_COUNTERS; - else - lgb->tlb_flex1 = TCP_NUM_PROC_COUNTERS; - lgb->tlb_flex2 = 2; + lgb->tlb_flex2 = 2; + } } +skip_out: log.u_bbr.timeStamp = tcp_get_usecs(&tv); log.u_bbr.cur_del_rate = tp->t_end_info; TCP_LOG_EVENTP(tp, NULL,