From nobody Thu Jan 26 18:16:55 2023 X-Original-To: dev-commits-src-main@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 4P2png30yxz3bJP1; Thu, 26 Jan 2023 18:16:55 +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 4P2png2bK9z41Cv; Thu, 26 Jan 2023 18:16:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674757015; 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=4uu/eArj4XIkxdCMdV8PqS/9EJ+8YgL0AGeThxzXJHI=; b=C8Vu+lcSFptlHzn/CanU+PgvidESIuB9tvv8hd7ffCd5n5u9QPIyjlb47kXq5OyL37oMQh 9363FMwJguOoFmcW4MdNe85ZLoDWdOvkBrPy4mK0hA5dIDFRdD0O1GMZ5NRP6lfvbx1yRh BnsELay2SPsjWFmmCJOX+ziRnTS6Ce/1oaULFjj5pfmWyWHVbpdBRJy9VOQZrI/3OBJr2Z skzFqWO7PDOLcg9vCo6AtgfUbThO1kMzKfywwcvb3KpcssQE/aSpRl5RKr9hobwV7DYO4m IlN2RepeIDFB/jREjZdZvnZxjDxNzcEpqL11t3kj/e/eb8RSag9xzx5S//ssPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674757015; 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=4uu/eArj4XIkxdCMdV8PqS/9EJ+8YgL0AGeThxzXJHI=; b=UuNbzSTIKkmbDyi3Gpey1cZL32VLRdJ4w1R4+bzNo49FewcjoiM4wSsjYf8PH+rBPRVMk2 vA07daCEo6vnLltNg3Rv3jB0zbjUecrPSfnqE8P1EjnU88WsxTUv8hoiP9RgwdszEeCx1b 7H2jQ8iYZDALka6I48448MCMU1r86d1hAQKmYTAvN1ZCPI/7DfyiaQiU+3TQRMPkuW+vk5 Er+lKfgJJZDLCyIQRdlO08supH8qIPVpKJTVYRpRoZa2/s6TUNbSmcJGP6gGbco/M470ee nCNvNo+/7zDEwWZjPsbioeUBDpoUWyyVui896QujVpTz3HZl/y7BMRhiBouqvA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674757015; a=rsa-sha256; cv=none; b=Hs/smaNhX+gHhvcYfLH/YuIIXb8fAR+8X+6rRef/luEB5fILEjyLTpNOBhxNGZ1XsG6GqU gNIuvYruVmNovxbTnMNMQgDmF/JmRmzrdO7uC4f8VUA4JBvSenn11qWoPFDAB2OvU0PeCK Acrh+1HM3sjX7K3ryABrsvDylcAv5J4wGFqHTCCnuFYLI+xSsSSVsd0Idh7eJqJi496vn5 uO1dsMXOEpQgy4RL8ihlOaJ6upMpa1GwTKDNI616uUWWiuQ5VlViseK8qbNyXFAzmH5tw+ VffslHRBsuP64GFtZgzAVh5LOtykQMRkJb2yo7ECK8+l0ES4JSHgF9cWXszkQg== 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 4P2png1g39zfKl; Thu, 26 Jan 2023 18:16:55 +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 30QIGt82077819; Thu, 26 Jan 2023 18:16:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QIGtkr077818; Thu, 26 Jan 2023 18:16:55 GMT (envelope-from git) Date: Thu, 26 Jan 2023 18:16:55 GMT Message-Id: <202301261816.30QIGtkr077818@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: d3acb974b48b - main - tcp: protect TCP over UDP configuration with a lock List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d3acb974b48be37b552661715c4eb79d462aa6d1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=d3acb974b48be37b552661715c4eb79d462aa6d1 commit d3acb974b48be37b552661715c4eb79d462aa6d1 Author: Gleb Smirnoff AuthorDate: 2023-01-26 18:16:32 +0000 Commit: Gleb Smirnoff CommitDate: 2023-01-26 18:16:32 +0000 tcp: protect TCP over UDP configuration with a lock The sysctl modifies global sockets without any locks. The removed comment suggests that previously it relied on a lock that doesn't exist today. --- sys/netinet/tcp_subr.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 607abecfef97..9828529634bc 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -773,13 +773,14 @@ VNET_DEFINE(struct socket *, udp6_tun_socket) = NULL; #define V_udp6_tun_socket VNET(udp6_tun_socket) #endif +static struct sx tcpoudp_lock; + static void tcp_over_udp_stop(void) { - /* - * This function assumes sysctl caller holds inp_rinfo_lock() - * for writing! - */ + + sx_assert(&tcpoudp_lock, SA_XLOCKED); + #ifdef INET if (V_udp4_tun_socket != NULL) { soclose(V_udp4_tun_socket); @@ -805,10 +806,9 @@ tcp_over_udp_start(void) #ifdef INET6 struct sockaddr_in6 sin6; #endif - /* - * This function assumes sysctl caller holds inp_info_rlock() - * for writing! - */ + + sx_assert(&tcpoudp_lock, SA_XLOCKED); + port = V_tcp_udp_tunneling_port; if (ntohs(port) == 0) { /* Must have a port set */ @@ -896,6 +896,7 @@ sysctl_net_inet_tcp_udp_tunneling_port_check(SYSCTL_HANDLER_ARGS) (new > TCP_TUNNELING_PORT_MAX)) { error = EINVAL; } else { + sx_xlock(&tcpoudp_lock); V_tcp_udp_tunneling_port = new; if (old != 0) { tcp_over_udp_stop(); @@ -903,6 +904,7 @@ sysctl_net_inet_tcp_udp_tunneling_port_check(SYSCTL_HANDLER_ARGS) if (new != 0) { error = tcp_over_udp_start(); } + sx_xunlock(&tcpoudp_lock); } } return (error); @@ -1479,6 +1481,7 @@ tcp_init(void *arg __unused) TAILQ_INIT(&t_functions); rw_init(&tcp_function_lock, "tcp_func_lock"); register_tcp_functions(&tcp_def_funcblk, M_WAITOK); + sx_init(&tcpoudp_lock, "TCP over UDP configuration"); #ifdef TCP_BLACKBOX /* Initialize the TCP logging data. */ tcp_log_init();