From nobody Tue Jan 30 05:39:25 2024 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 4TPDWK55X8z58L3J; Tue, 30 Jan 2024 05:39:25 +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 4TPDWK4DRpz4WQT; Tue, 30 Jan 2024 05:39:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706593165; 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=6MxAsiv05/6xZa+fvJUPnnta1mUo89SOw9pMMtQdyq0=; b=bnKiO+wVh08JRNHMCud5TFeq0Wd5uD5w2IaACFoYGFhZ2Wc8aOFDvs5bgeCoCEBpEQoHNE Cs6aBzwCDUgsjS3EnZLIlD57S+KL+ZtJ2zYuRBb0Wtu3QF9pqBVX74ANevLKMdgnfaCXr4 9RFYaLMqic9cdt/cL3bzSnmVZeOQ8sBYqdTtQ1jf2K1YisPoUTwc4/BIaaIDvyaLaiUxn+ qGuxQqjPA/gVbiZlREeDhC1UbdIVxmpSyQtdFDJ83mf5t84qFlmxAoBRN4g/Ys9WkZ+QAq iPIDOD5+t8qqrPn9YX8p+4kCpKL/znBD352VzVEjV3oCwDbZ+MM2G85zPhJmow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706593165; 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=6MxAsiv05/6xZa+fvJUPnnta1mUo89SOw9pMMtQdyq0=; b=DIMS/9GL9o0/fEutlDQm09I48zfU3o04KFrmtDSCAZB/hER7yTsUDSMKhWSOZTVmGSlasi /qxVf4N9i6NRcYRWWFqbp0JVQ1ppPDLZGDbxNuR0QvKVqqvSsr7gymuGjI4Fzi+QbdM5Hh 1j1Uortvtii1nkGL+eiZicGI80knR8F7gtkVhsXAk9EpyFhcGqGdejBe+ZGWYCE8iIni8o rn3QjoU3/Ug8lMpJvdfgVDNsD6EIC45LNvYqsxRGArwLzYS/gLZ18/MOEI/5l/COpVTVuh tn1YvHy6IuhvZokbAQPs4KJE1Vk/fRjJomM9zFzQOOpjHYtXDdylmtKhQhH11A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706593165; a=rsa-sha256; cv=none; b=SUicE5c+yDrYFJoUJgdD1HfCBBGlwvYudMnfTs7tDCZUVjH/NEYbDK9qaL0dXekfGjzv4Q MSWD6Khc6qYv2OiNAmbk2UtzLeT30frGAKd8rEeBPCaD4fqcZjNAiDUoVnVCVNtmDiQv7A IqFk2GKFeSpVUBqc/Iqq2YZp2EknfiJ85yz0x+wLuBqAbv88tiRR+GulwEBYY3pCPgxHgw 927+Q46BQ5t0iAgDAXkuV8KgPAWNxRNc6+gKMMozfKVd1iFXmB7r4pJbe87awGaqRJNZgN VxKRDzTEEZ6QitmJu6pPUATU+JHYWgmoGjZB1ZFz6V4P2aEVE4YuorEL3yEmhQ== 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 4TPDWK2CJmzNTC; Tue, 30 Jan 2024 05:39:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40U5dPEo019291; Tue, 30 Jan 2024 05:39:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40U5dPBE019288; Tue, 30 Jan 2024 05:39:25 GMT (envelope-from git) Date: Tue, 30 Jan 2024 05:39:25 GMT Message-Id: <202401300539.40U5dPBE019288@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 86986d381072 - stable/14 - if_wg: fix erroneous calculation in calculate_padding() for p_mtu == 0 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 86986d381072171a5d6183701ae2f96c2d9a6406 Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=86986d381072171a5d6183701ae2f96c2d9a6406 commit 86986d381072171a5d6183701ae2f96c2d9a6406 Author: Aaron LI AuthorDate: 2024-01-17 23:29:23 +0000 Commit: Kyle Evans CommitDate: 2024-01-30 05:37:29 +0000 if_wg: fix erroneous calculation in calculate_padding() for p_mtu == 0 In practice this is harmless; only keepalive packets may realistically have p_mtu == 0, and they'll also have no payload so the math works out the same either way. Still, let's prefer technical accuracy and calculate the amount of padding needed rather than the padded length... PR: 276363 (cherry picked from commit b891f61ef538a4e9b4658b4b756635c8036a5788) --- sys/dev/wg/if_wg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/dev/wg/if_wg.c b/sys/dev/wg/if_wg.c index 0ea40b763416..738b1e76fa85 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -1461,8 +1461,12 @@ calculate_padding(struct wg_packet *pkt) { unsigned int padded_size, last_unit = pkt->p_mbuf->m_pkthdr.len; - if (__predict_false(!pkt->p_mtu)) - return (last_unit + (WG_PKT_PADDING - 1)) & ~(WG_PKT_PADDING - 1); + /* Keepalive packets don't set p_mtu, but also have a length of zero. */ + if (__predict_false(pkt->p_mtu == 0)) { + padded_size = (last_unit + (WG_PKT_PADDING - 1)) & + ~(WG_PKT_PADDING - 1); + return (padded_size - last_unit); + } if (__predict_false(last_unit > pkt->p_mtu)) last_unit %= pkt->p_mtu; @@ -1470,7 +1474,7 @@ calculate_padding(struct wg_packet *pkt) padded_size = (last_unit + (WG_PKT_PADDING - 1)) & ~(WG_PKT_PADDING - 1); if (pkt->p_mtu < padded_size) padded_size = pkt->p_mtu; - return padded_size - last_unit; + return (padded_size - last_unit); } static void