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 D3E053D566F; Tue, 16 Jun 2026 18:09:57 +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=1781633398; cv=none; b=LYLCuYk4bSI+ES65fCywQMET/27DJS1qrRT40MVJaGKruWaf9cV6fEv+kqbRR4xR0nGAk48C3oYt49vNFXFpdKVTzIoS/xUQ35fkbMAfNY8XSUNkgiPjWTgW0Dht++TbIctUIulu2mY3ofIRIcZZoZ8P3nXg+w4U5QDRVYfUqiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781633398; c=relaxed/simple; bh=OeALJMHeVQxdL37Fis+ktCRIC4G0WaSuVn6nkJXgDx0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZrxQMgLzTQfi/55R+C1hKvwukWHdtIb/ZwccWvpfzs+7szNBt8WLjgMYblVdkmclLKjzyjqGMUCmOau86ZTwvXtsJ9plgDnPUPOORbcSUvM5ymp6qFL4fJkRYD0GffbcmfySj+nX1eUwRcwuKKH3xewv85BhvZR5tQzeVqA/q8k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eeXUTPV4; 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="eeXUTPV4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2CA31F000E9; Tue, 16 Jun 2026 18:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781633397; bh=LTcwZceMHbvuelY/SZH2P5fmhHLgMhHKw4f6RQury8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eeXUTPV4ITb+VTt8ryJdRwvCBpUdYYagFA2u81DyB9eDnyHeiKANFFY+RkSMGEyel aaUZ0kMV3ycA0xSmMFCoMbfVJb1eHTv4pLstJrjbp5gGv20tYd9ELxi6b6q3tT3JpR eIJZ2qGsbcqU5RSa6yz32ajOfWxUIO26pW4Pnbjc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Jason A. Donenfeld" , Jakub Kicinski Subject: [PATCH 5.15 071/411] wireguard: send: append trailer after expanding head Date: Tue, 16 Jun 2026 20:25:09 +0530 Message-ID: <20260616145104.050679612@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145100.376842714@linuxfoundation.org> References: <20260616145100.376842714@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 5.15-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. */