From: Paolo Abeni <pabeni@redhat.com>
To: lucien.xin@gmail.com
Cc: netdev@vger.kernel.org, quic@lists.linux.dev,
davem@davemloft.net, kuba@kernel.org, edumazet@google.com,
pabeni@redhat.com, horms@kernel.org, metze@samba.org,
mbuhl@openbsd.org, tfanelli@redhat.com, hepengtao@xiaomi.com,
dreibh@simula.no, linux-cifs@vger.kernel.org, smfrench@gmail.com,
linkinjeon@kernel.org, tom@talpey.com,
kernel-tls-handshake@lists.linux.dev, chuck.lever@oracle.com,
jlayton@kernel.org, steved@redhat.com, hare@suse.de,
aahringo@redhat.com, dhowells@redhat.com, matttbe@kernel.org,
mail@johnericson.me, xiyou.wangcong@gmail.com,
alibuda@linux.alibaba.com, jbaron@akamai.com,
illiliti@protonmail.com, sd@queasysnail.net,
marcelo.leitner@gmail.com, daniel@haxx.se,
andrew.gospodarek@broadcom.com, mef@scarletmail.rutgers.edu,
paul@jakma.org
Subject: Re: [PATCH net-next v13 12/15] quic: add crypto packet encryption and decryption
Date: Thu, 11 Jun 2026 10:19:48 +0200 [thread overview]
Message-ID: <20260611081948.137325-1-pabeni@redhat.com> (raw)
In-Reply-To: <287e6b7dd877836e08b9bcb6727f547fe80f6459.1780855297.git.lucien.xin@gmail.com>
From: AI Reviewer <ai@example.com>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://netdev-ai.bots.linux.dev/sashiko/
---
quic: add crypto packet encryption and decryption
This patch adds AEAD-based packet encryption/decryption helpers, QUIC
header protection, and Retry/address-validation token generation and
verification primitives.
> diff --git a/net/quic/crypto.c b/net/quic/crypto.c
> index c68a0b570c72..77e633096c2a 100644
> --- a/net/quic/crypto.c
> +++ b/net/quic/crypto.c
[ ... ]
> +/* Retry Packet Integrity. */
> +int quic_crypto_get_retry_tag(struct quic_crypto *crypto, struct sk_buff *skb,
> + struct quic_conn_id *odcid, u32 version, u8 *tag)
> +{
> + /* Reuse RX AEAD (phase 1) in Initial crypto. */
> + struct crypto_aead *tfm = crypto->rx_tfm[1];
> + u8 *pseudo_retry, *p, *iv, *key;
> + DECLARE_CRYPTO_WAIT(wait);
> + struct aead_request *req;
> + struct scatterlist *sg;
> + u32 plen;
> + int err;
> +
> + if (skb->len < QUIC_TAG_LEN)
> + return -EINVAL;
[Low]
The guard rejects skb->len < QUIC_TAG_LEN, but a later comment in the
same function says:
> + /* The caller must ensure skb->len > QUIC_TAG_LEN. */
> + plen = 1 + odcid->len + skb->len - QUIC_TAG_LEN;
Should the check be <= QUIC_TAG_LEN, or should the comment say >= to
match the strict-less-than test?
In the boundary case where skb->len == QUIC_TAG_LEN, plen becomes
1 + odcid->len, and quic_put_data(p, skb->data, skb->len - QUIC_TAG_LEN)
copies zero bytes, so the integrity tag would be computed over a
pseudo-packet containing only the ODCID length and ODCID with no actual
Retry header bytes. Is that intended?
[ ... ]
> +/* Derives a key and IV using HKDF, configures the AEAD transform and performs
> + * AEAD encryption/decryption for the provided token.
> + */
> +static int quic_crypto_token_protect(struct quic_crypto *crypto, u8 *token,
> + u32 len, u32 adlen, bool enc)
> +{
> + u8 key[TLS_CIPHER_AES_GCM_128_KEY_SIZE], iv[QUIC_IV_LEN], *tiv;
> + /* Reuse TX AEAD (phase 1) in Initial crypto. */
> + struct crypto_aead *tfm = crypto->tx_tfm[1];
> + u32 extra = enc ? QUIC_TAG_LEN : 0;
> + struct quic_data srt = {}, k, i;
> + DECLARE_CRYPTO_WAIT(wait);
> + struct aead_request *req;
> + struct scatterlist *sg;
> + void *ctx = NULL;
> + int err;
> +
> + quic_data(&srt, quic_random_data, QUIC_RANDOM_DATA_LEN);
> + quic_data(&k, key, TLS_CIPHER_AES_GCM_128_KEY_SIZE);
> + quic_data(&i, iv, QUIC_IV_LEN);
> + err = quic_crypto_keys_derive(crypto->secret_tfm, &srt, &k, &i, NULL,
> + QUIC_VERSION_V1);
[Critical]
Can this lead to AES-GCM nonce reuse across all generated tokens?
quic_random_data is a module-global buffer initialized once in
quic_crypto_init() via get_random_bytes() and never refreshed:
static u8 quic_random_data[QUIC_RANDOM_DATA_LEN] __read_mostly;
quic_crypto_keys_derive() runs HKDF-Expand-Label over that constant
secret with constant labels "quic key" and "quic iv", so both the
derived key and the derived IV are deterministic and identical on every
invocation of quic_crypto_token_protect().
> + if (err)
> + goto out;
> + err = crypto_aead_setauthsize(tfm, QUIC_TAG_LEN);
> + if (err)
> + goto out;
> + err = crypto_aead_setkey(tfm, key, TLS_CIPHER_AES_GCM_128_KEY_SIZE);
> + if (err)
> + goto out;
> + ctx = quic_crypto_aead_mem_alloc(tfm, 0, &tiv, &req, &sg, 1);
> + if (!ctx) {
> + err = -ENOMEM;
> + goto out;
> + }
> + memcpy(tiv, iv, QUIC_IV_LEN);
> +
> + sg_init_one(sg, token, len);
> + aead_request_set_tfm(req, tfm);
> + aead_request_set_ad(req, adlen);
> + aead_request_set_crypt(req, sg, sg, len - adlen - extra, tiv);
Every call ends up using the same (K, N) pair under AES-GCM, with no
per-token random prefix and no packet-number XOR like
quic_crypto_payload_protect() does via cb->number.
NIST SP 800-38D forbids reuse of (K, N) under GCM; from two valid
ciphertexts an attacker can recover the GHASH authentication subkey H
and forge tokens for arbitrary client addresses, which would defeat
the address validation in quic_crypto_verify_token() and the
anti-amplification protections in RFC 9000 section 8.
Could a unique per-token nonce be derived (for example from a random
prefix stored in the token itself), or a nonce-misuse-resistant AEAD
be used here instead?
> + aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
> + crypto_req_done, &wait);
> + err = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
> + if (err == -EINPROGRESS || err == -EBUSY)
> + err = crypto_wait_req(err, &wait);
> +
> +out:
> + memzero_explicit(key, sizeof(key));
> + memzero_explicit(iv, sizeof(iv));
> + kfree_sensitive(ctx);
> + return err;
> +}
[ ... ]
--
This is an AI-generated review.
next prev parent reply other threads:[~2026-06-11 8:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-07 18:01 [PATCH net-next v13 00/15] net: introduce QUIC infrastructure and core subcomponents Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 01/15] net: define IPPROTO_QUIC and SOL_QUIC constants Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 02/15] net: build socket infrastructure for QUIC protocol Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 03/15] quic: provide common utilities and data structures Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 04/15] quic: provide family ops for address and protocol Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 05/15] quic: provide quic.h header files for kernel and userspace Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 06/15] quic: add stream management Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 07/15] quic: add connection id management Xin Long
2026-06-11 8:19 ` Paolo Abeni
2026-06-07 18:01 ` [PATCH net-next v13 08/15] quic: add path management Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 09/15] quic: add congestion control Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 10/15] quic: add packet number space Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 11/15] quic: add crypto key derivation and installation Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 12/15] quic: add crypto packet encryption and decryption Xin Long
2026-06-11 8:19 ` Paolo Abeni [this message]
2026-06-07 18:01 ` [PATCH net-next v13 13/15] quic: add timer management Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 14/15] quic: add packet builder base Xin Long
2026-06-07 18:01 ` [PATCH net-next v13 15/15] quic: add packet parser base Xin Long
2026-06-11 8:20 ` Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260611081948.137325-1-pabeni@redhat.com \
--to=pabeni@redhat.com \
--cc=aahringo@redhat.com \
--cc=alibuda@linux.alibaba.com \
--cc=andrew.gospodarek@broadcom.com \
--cc=chuck.lever@oracle.com \
--cc=daniel@haxx.se \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=dreibh@simula.no \
--cc=edumazet@google.com \
--cc=hare@suse.de \
--cc=hepengtao@xiaomi.com \
--cc=horms@kernel.org \
--cc=illiliti@protonmail.com \
--cc=jbaron@akamai.com \
--cc=jlayton@kernel.org \
--cc=kernel-tls-handshake@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=lucien.xin@gmail.com \
--cc=mail@johnericson.me \
--cc=marcelo.leitner@gmail.com \
--cc=matttbe@kernel.org \
--cc=mbuhl@openbsd.org \
--cc=mef@scarletmail.rutgers.edu \
--cc=metze@samba.org \
--cc=netdev@vger.kernel.org \
--cc=paul@jakma.org \
--cc=quic@lists.linux.dev \
--cc=sd@queasysnail.net \
--cc=smfrench@gmail.com \
--cc=steved@redhat.com \
--cc=tfanelli@redhat.com \
--cc=tom@talpey.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox