From nobody Wed Jan 17 23:30:40 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 4TFhvP1ybGz572Q8; Wed, 17 Jan 2024 23:30:41 +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 4TFhvP151qz4KNC; Wed, 17 Jan 2024 23:30:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705534241; 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=VGK5xJoL1H/lZaCbW4vsomWjK3MyQVNuw01IhMWUamM=; b=RFwwTr67TqaeEAiAhMibY7duokbpSkwvyQ0djnlyx6lgnbQf13SUY5blRpAlVsHSLYnapx QnyzdlHFeFDv2u8T40OVAcIzp5NJedOem/9VGG+twvn58HUpzuN7BMZ8ZbfyFkpcTrvZvV brY14eJM0CAdWDhEun4AwfHvwqpVUCJDMM8F0NfN4CWBc+2MC2hCPBsxWz99TiZvvd1K5G 6y0xu35+JonvVuHy28rpmsG0N91VVu8nW40E6MEE4OKyLW/hseANF5a5cqlgUrOJVXTtG4 MEhaAka0CboxH/tdYzZpgcrqX62xcAW76az3O0jQ4qH2sgvOL9SohHilHHwP3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705534241; 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=VGK5xJoL1H/lZaCbW4vsomWjK3MyQVNuw01IhMWUamM=; b=cD5DFNTVtwOiGxZ6K0xCuvvI2bVwfbNEX7r8W8DjoQ7RpImC9vn4wJ/46wISYH+4B8zPKV 6UPGtUX9YY4pULiOQsCudX/7EsrrC2kFjnLlu3qPjtpZhJeovKteDdeC1jZYd7i6J06+RB zr8U4fs9F0q7BqxM7zB9vWJ3RYZ3Udp6VMelDkbCEnpGSh1KRdyz7huJCqYO1gYOML/akQ M3eA4vQr7Vy4CjfopOezmMmEDT1NnfvOCYqpC/YI85D8ko049oLFa351OeGR4q4x9LhpQo /z3bs3UFEZuT7LT0726Vlj/ROc/6hctCIcPeviQgPCDUAbQ6suPD5csUYnMaMA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705534241; a=rsa-sha256; cv=none; b=Iba1QDYCoS2JyZPw0wAzRaSkanTm/e12YQ2VSMrFUEp7e3nZTeqG5qVuJ+jrSxx0NGytJE wFxlkW/1dOaRoFAWRtH6V+21S74hGhuzB9MemyYaCaHfhPBt5aur9lyfsMPu+pXxrSWsv+ g3Qxg04K4dUaSjW1dNwBESZvDA2bKNOVuaV4LdiWPX6YTX4yWWBbTz878VlFR0yMnrueKq 0SSEhl8xS8xnnpN92iU3BZwYSPEpurv9qyghNAscvrVdhgyIZDeuX6FRTU1D4Et6hyWJga QFiYSCHyUvzo+kyE0FQe8OOsgy1dklfjnwGWgXD3AJBOakJgLTyT3gMHumEeMA== 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 4TFhvP08V9zk9g; Wed, 17 Jan 2024 23:30:41 +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 40HNUeOD078540; Wed, 17 Jan 2024 23:30:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40HNUep0078537; Wed, 17 Jan 2024 23:30:40 GMT (envelope-from git) Date: Wed, 17 Jan 2024 23:30:40 GMT Message-Id: <202401172330.40HNUep0078537@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: b891f61ef538 - main - 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/main X-Git-Reftype: branch X-Git-Commit: b891f61ef538a4e9b4658b4b756635c8036a5788 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=b891f61ef538a4e9b4658b4b756635c8036a5788 commit b891f61ef538a4e9b4658b4b756635c8036a5788 Author: Aaron LI AuthorDate: 2024-01-17 23:29:23 +0000 Commit: Kyle Evans CommitDate: 2024-01-17 23:29:52 +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 --- 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 71c80c8b5f77..58c0e2db1ee8 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -1463,8 +1463,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; @@ -1472,7 +1476,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