From nobody Tue Jan 30 05:39:17 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 4TPDWC0RjWz58L5R; Tue, 30 Jan 2024 05:39:19 +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 4TPDWB6Gtlz4WQL; Tue, 30 Jan 2024 05:39:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706593158; 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=U4IKwea6/kzV/36a9+uaue2xBpyB5fLvav3mrlxFc8Q=; b=Wia8bybJZBS5tA7OQf7sd2tkLKSH7a1Tr26g64+FERjtp/hzBArpZHmXY6VaHdjjKFlc49 hDZgjLb1YHB4+/m5QSkfnXmtraDxLNyQkOmtbD76bOPYnmJDVTE60IB9WwZHuo7qWmWuxc Pv4/wSkuvuXM+mPCNvhWg6E2FhMqu31ptZFP6I/XakcjN0fmLUfoQYIrTtJ4D8VhHy0sQb C7XZKW6bTEeJ24aRA+RZejtrJcMezET5oq9QiC+KAvriSY3N6Wv7RdW0BcegAnj1VretJA +azqKPXvYA7p6XmzdNtLo3tz3AzsujOJp1jVjSLnV5Wk/OnMbnS+BjAt/mAC4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706593158; 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=U4IKwea6/kzV/36a9+uaue2xBpyB5fLvav3mrlxFc8Q=; b=JIq/wexveho6IrNNTZI9VrCN59avU6FfI6cAv2CTczgjm0WdLOQqRIWOunkASft7OY4/Qi TX/QskvUJAlG6XfB21utU5OXBruYeBXHnFiMM4rz/2V0O4Zj6YhPiTsira/0ndiCvDqJvQ 5Cm0+rnRbehx8RCg6UrKZhz9lU+oznOEbVNoOKozjr4WPAWOSSYPN3yytxDx6J5hQOCqFM MbI5atNqvJvcTFQyCEgju7KpunEsn4nM6AspOANYihNW3FX2/jkYoHamBuXl40O/5uQ/ES 3sPt5bYX3osJbwSO1QjA+Ja8KiTMQ+BSy5EvPFY8oY0lg/gYjkrBmq2aDmVjfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706593158; a=rsa-sha256; cv=none; b=mPLU1vbKZbRgWUxWkfnusR9o+FuXXQAZ50OYbAHFe7z95zZOd3bQWtBvX36oxO8fj0nH2H YFK8dkRm+64uCQTP5obN12r1LEURtlGgVGo3ItY8ddK7fsoC2ulTECl/ck9hiBLNJ/TkDn 8qZCggZJ0KtKblajKGtquJqAcpeYe3RunlS+wddN/t7qYrBVUQ8A5ei4QgcWJCoBbpIiC4 HUKw2EXpv2QFJye9RXEOKvOa/Qj376lyCoStsFZ5pKi8acqHS5lktZf7nL6LRx1y18a1jJ 7oH1FeUKr72Jucxu3nW73C9gbYjpSA1RrZmkEjzY8/4lFFrX5XJjtIVkU0W56w== 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 4TPDWB3tDJzNVq; Tue, 30 Jan 2024 05:39:18 +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 40U5dHmT018999; Tue, 30 Jan 2024 05:39:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40U5dHRX018996; Tue, 30 Jan 2024 05:39:17 GMT (envelope-from git) Date: Tue, 30 Jan 2024 05:39:17 GMT Message-Id: <202401300539.40U5dHRX018996@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: bbda52e814e0 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: bbda52e814e0c760b2beaeae40a2c76ff43d1975 Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=bbda52e814e0c760b2beaeae40a2c76ff43d1975 commit bbda52e814e0c760b2beaeae40a2c76ff43d1975 Author: Aaron LI AuthorDate: 2024-01-17 23:29:23 +0000 Commit: Kyle Evans CommitDate: 2024-01-30 05:37:46 +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 6cd5c985a89f..e961c9f24d94 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -1465,8 +1465,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; @@ -1474,7 +1478,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