]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wireguard: send: append trailer after expanding head
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 29 May 2026 17:31:34 +0000 (19:31 +0200)
committerJakub Kicinski <kuba@kernel.org>
Fri, 29 May 2026 20:01:27 +0000 (13:01 -0700)
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 <Jason@zx2c4.com>
Link: https://patch.msgid.link/20260529173134.3080773-2-Jason@zx2c4.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/wireguard/send.c

index 26e09c30d596ca213a1bc62cad2aceed9a9dca50..67d01478eb76dd202bdd860f7caff083b6acbb0a 100644 (file)
@@ -177,16 +177,6 @@ static bool encrypt_packet(struct sk_buff *skb, struct noise_keypair *keypair)
        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_buff *skb, struct noise_keypair *keypair)
                     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.
         */