From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D47FB3C09F3; Tue, 16 Jun 2026 16:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781628506; cv=none; b=XkL/TWbJe/x5qtPR/BW4sflmYYonXNYLWzxBnt3xdh0gT9TM5VODYHW4u9r/ZJQ5SJKjG7GCIKwaW3EGeCadTU2H/MTEAbRxZKfiM+nlQ0Wp7MBWL2QKPVZmoIhwyRAxw5fb0LqHGB+cNBC9GGd0YaVAYT98Dk072f9KMmDqCvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781628506; c=relaxed/simple; bh=O2bMrW3ERrhjOcA/2UOeAAgkDUbTs4RMUfIkaIc+bzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J3BBFyaYv6zWd68yGbikcgLCZIlCB69eqSPdQ0S732HhEsaqc6hUsosApJfkDIMsvUX1oFlFcvwzWiGrsKWazHzf+6d0EMBtVJ4UHi9HoTT/GAgRJb9BfLMSsHfLHYRNTY/IFNxpx04L40UltpGdkcO+mczWCneJKoTPpZuhI8w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hoUdolwt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="hoUdolwt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E690F1F000E9; Tue, 16 Jun 2026 16:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781628505; bh=Ypcfu636jiEd+ttEz0JgWhZuyKJemCStVSO78n65IOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hoUdolwtzci5xMPvWhUoYY/NvVa8iZjWNdW+2tqX4hcxe3hfuV1/3v6GQumY9lr9C 1Dd2HltrYmcWlZulk8uAtQV9b8Z2GbwCdTVUGwn67lp/KeGrlP9CkvaZbPRG9l2C3h 4C+zp/EQYUil8DM96E0QtZ/oJaryDtTTyyMm49WM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Jason A. Donenfeld" , Jakub Kicinski Subject: [PATCH 6.6 107/452] wireguard: send: append trailer after expanding head Date: Tue, 16 Jun 2026 20:25:34 +0530 Message-ID: <20260616145123.387788097@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145117.796205997@linuxfoundation.org> References: <20260616145117.796205997@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason A. Donenfeld commit f75e3eb08fe31d30a9af6ed80cdd22e6772837e2 upstream. With how this is currently written, we add the trailer, zero it out, and then add the header space on. If that header space requires a reallocation + copy, the zeros in the trailer aren't copied, because the skb len hasn't actually been yet expanded to cover that. Instead add the padding at the end of the process rather than at the beginning. Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") Cc: stable@vger.kernel.org Signed-off-by: Jason A. Donenfeld Link: https://patch.msgid.link/20260529173134.3080773-2-Jason@zx2c4.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireguard/send.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/drivers/net/wireguard/send.c +++ b/drivers/net/wireguard/send.c @@ -177,16 +177,6 @@ static bool encrypt_packet(struct sk_buf trailer_len = padding_len + noise_encrypted_len(0); plaintext_len = skb->len + padding_len; - /* Expand data section to have room for padding and auth tag. */ - num_frags = skb_cow_data(skb, trailer_len, &trailer); - if (unlikely(num_frags < 0 || num_frags > ARRAY_SIZE(sg))) - return false; - - /* Set the padding to zeros, and make sure it and the auth tag are part - * of the skb. - */ - memset(skb_tail_pointer(trailer), 0, padding_len); - /* Expand head section to have room for our header and the network * stack's headers. */ @@ -198,6 +188,16 @@ static bool encrypt_packet(struct sk_buf skb_checksum_help(skb))) return false; + /* Expand data section to have room for padding and auth tag. */ + num_frags = skb_cow_data(skb, trailer_len, &trailer); + if (unlikely(num_frags < 0 || num_frags > ARRAY_SIZE(sg))) + return false; + + /* Set the padding to zeros, and make sure it and the auth tag are part + * of the skb. + */ + memset(skb_tail_pointer(trailer), 0, padding_len); + /* Only after checksumming can we safely add on the padding at the end * and the header. */