From nobody Fri Nov 21 15:39:48 2025 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 4dCfY1086Jz6HMyv for ; Fri, 21 Nov 2025 15:39:49 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dCfY06KZgz3svS for ; Fri, 21 Nov 2025 15:39:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763739588; 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=HaS0TqQdmTGF9jeDsq/EfcvsB9CR4btfdpwN2uzr5zo=; b=KXQtKoV4OpHMjugcfYhryPDxVx1vWx2Npb2tjK6AxCkWx8/I2D3pWM9EyJT+hmPNtrRZpn uexKnvJmHpCWKVIH76VN/dEYRUJtJ9JBWu0nyqahf7XMsd0ro9FezvyUBtkhXi6HKXlcmC w0YxX6Fsn7OKJaRJ7FzP0TDc8NT3Vwpg4K2zjIisqgc7Wxb1230cEhXd34EAhUQTysJ8dr 7JNKygvbZf7VsudGXZ4kOyGoRygTv4qcZ2TSY285MQO7+XrBbiyO5NEwVKjpPtmH4ShJUh KLoM6yIhhkObEvCxcZNEmEwdYyD3pO5TLVSJ35dY2CI2eY8tscMwQ68V/IVMQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763739588; 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=HaS0TqQdmTGF9jeDsq/EfcvsB9CR4btfdpwN2uzr5zo=; b=TFCcjUOlFdlsY7YA8s179WkGP+1OKnAFj6gCocUO124spCOUIhOAFhRKBCZZwcOaa7wSl6 gpYIewQlinE5978CUnNQjd9fWd9y0abI2xA2z7hLdctwNt90SGKdQHu1t3JaN8YCV5M3Te N8Shb79lu5zKeHMRgFSzQYm6Sjd9/9JtgLXwyVgahe1V8Rmtgsb+8w+2NnGaUmx75Gt0C6 FkA2pX5rIFhhfzWv2eC2Xj9UGvwgZRiGm2bnjOCXmlNyQ+ibY5y1C2/6yMtFxx/4h1SHJW GJxXkF/ngsJ0NHKubzp/fXMgTKXHln3xTFBTAi+1FNBaDChe76MxWx8LfEbLcw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763739588; a=rsa-sha256; cv=none; b=oZxsmzf/2qOh/3lMxpTOhkBjjrhf+lpZEM8qAThRhfRBwRi3/FDPI4RAD2JZb/PLqHN1Dz yBk21UCdbPe2AQ1t+SjU9cnLZo+yXBBwoG1uMk8RzN8MKAO/cz9PdUGbU6BlZb+WrYCqEJ RNLZkdwSsXE5Fou8v4fllqkW9wsSkOeiJC1KZTAT2+i4RfpUO9crCJ3L9eQQ4n70vpzvZk rqZCXP7mPeJshJW9KLsT3P1qUUxKudoQN8Ic3/5sg0UzyWrbs0CNpitVEdz/jEihyU+2dL b500vanTSJpzUJbBfPsBiAbbzulXhUG6DWosxaTr5dZ29uT9JLJcKSdCrWi4bw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dCfY04x80z3F5 for ; Fri, 21 Nov 2025 15:39:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 334a7 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 21 Nov 2025 15:39:48 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 7dedc3c21436 - main - pf: fix another endpoint-independent 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7dedc3c21436bb5a1220f8901992d2772a163f78 Auto-Submitted: auto-generated Date: Fri, 21 Nov 2025 15:39:48 +0000 Message-Id: <692087c4.334a7.4ddf433f@gitrepo.freebsd.org> The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=7dedc3c21436bb5a1220f8901992d2772a163f78 commit 7dedc3c21436bb5a1220f8901992d2772a163f78 Author: Kristof Provost AuthorDate: 2025-11-21 09:03:36 +0000 Commit: Kristof Provost CommitDate: 2025-11-21 15:23:46 +0000 pf: fix another endpoint-independent crash In c12013f5bb38 we fixed udp_mapping cleanup issues in pf_get_sport(), but missed the static-port case (i.e. low == 0 && high == 0). We could still exit pf_get_sport() without either inserting the udp_mapping or freeing it. Address this and add a test case to provoke the problem. Reviewed by: thj MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D53856 --- sys/netpfil/pf/pf_lb.c | 16 ++++++++++++---- tests/sys/netpfil/pf/nat.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/sys/netpfil/pf/pf_lb.c b/sys/netpfil/pf/pf_lb.c index 3227d2906fb5..3510de3c6b3d 100644 --- a/sys/netpfil/pf/pf_lb.c +++ b/sys/netpfil/pf/pf_lb.c @@ -407,10 +407,18 @@ pf_get_sport(struct pf_pdesc *pd, struct pf_krule *r, struct pf_addr *naddr, */ key.port[sidx] = pd->nsport; if (!pf_find_state_all_exists(&key, dir)) { - MPASS(udp_mapping == NULL || - *udp_mapping == NULL); - *nport = pd->nsport; - return (0); + if (udp_mapping && *udp_mapping != NULL) { + (*udp_mapping)->endpoints[1].port = pd->nsport; + if (pf_udp_mapping_insert(*udp_mapping) == 0) { + *nport = pd->nsport; + return (0); + } + } else { + MPASS(udp_mapping == NULL || + *udp_mapping == NULL); + *nport = pd->nsport; + return (0); + } } } else if (low == high) { key.port[sidx] = htons(low); diff --git a/tests/sys/netpfil/pf/nat.sh b/tests/sys/netpfil/pf/nat.sh index 788eacdc3369..3d953b495953 100644 --- a/tests/sys/netpfil/pf/nat.sh +++ b/tests/sys/netpfil/pf/nat.sh @@ -289,6 +289,35 @@ endpoint_independent_exhaust_cleanup() rm -f server2.out } +atf_test_case "endpoint_independent_static_port" "cleanup" +endpoint_independent_static_port_head() +{ + atf_set descr 'Test that a client behind NAT gets the same external IP:port for different servers, with static-port' + atf_set require.user root +} + +endpoint_independent_static_port_body() +{ + endpoint_independent_setup # Sets ${epair_…} variables + + endpoint_independent_common \ + "nat on ${epair_nat}a inet from ! (${epair_nat}a) to any -> (${epair_nat}a)" \ + "nat on ${epair_nat}a inet from ! (${epair_nat}a) to any -> (${epair_nat}a) static-port sticky-address endpoint-independent" + + # Exhaust the available nat ports + for i in $(seq 1 10); do + echo "ping" | jexec client nc -u 198.51.100.32 1234 -w 0 + echo "ping" | jexec client nc -u 198.51.100.22 1234 -w 0 + done +} + +endpoint_independent_static_port_cleanup() +{ + pft_cleanup + rm -f server1.out + rm -f server2.out +} + atf_test_case "endpoint_independent_pass" "cleanup" endpoint_independent_pass_head() { @@ -930,6 +959,7 @@ atf_init_test_cases() atf_add_test_case "nested_anchor" atf_add_test_case "endpoint_independent_compat" atf_add_test_case "endpoint_independent_exhaust" + atf_add_test_case "endpoint_independent_static_port" atf_add_test_case "endpoint_independent_pass" atf_add_test_case "nat6_nolinklocal" atf_add_test_case "empty_table_source_hash"