Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: lucien.xin@gmail.com
Cc: netdev@vger.kernel.org, quic@lists.linux.dev,
	davem@davemloft.net, kuba@kernel.org, edumazet@kernel.org,
	pabeni@redhat.com, horms@kernel.org, metze@samba.org,
	mbuhl@openbsd.org, tfanelli@redhat.com, hepengtao@xiaomi.com,
	dreibh@simula.no, jamie.bainbridge@gmail.com,
	linux-cifs@vger.kernel.org, pc@manguebit.org,
	linkinjeon@kernel.org, tom@talpey.com,
	kernel-tls-handshake@lists.linux.dev, cel@kernel.org,
	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, kuniyu@google.com
Subject: Re: [PATCH net-next v19 11/15] quic: add crypto key derivation and installation
Date: Tue, 24 Nov 2026 01:21:21 +0000	[thread overview]
Message-ID: <179548328150.3135.7027633658882912871@kernel.org> (raw)
In-Reply-To: <035db09843f506bea729e16d523b453c56647be8.1795393691.git.lucien.xin@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] Shared token key: AES-GCM nonce uniqueness across sockets
  depends only on a random 64-bit counter start.
- [Medium] The AEAD integrity limit is enforced per encryption level, but
  RFC 9001 Section 6.6 requires it per connection.
- [Low] The commit message body does not mention the socket lifecycle
  changes in net/quic/socket.c.
- [Low] struct quic_crypto::tx_count[2] is documented as 'Packets
  encrypted (key phase 0 and 1)' and is compared with…
- [Low] Type mismatch between the HP transform fields and the API used to
  allocate and free them.

--

quic: add crypto key derivation and installation

This patch adds net/quic/crypto.c with HKDF-based derivation and
installation of QUIC packet protection keys for the Initial, Handshake,
0-RTT and 1-RTT levels. It also adds key updates and token / stateless
reset secret derivation. quic_init_sock() now allocates one struct
quic_crypto per level, and a new quic_sock_destruct() defers freeing
them to a workqueue.

> diff --git a/net/quic/crypto.c b/net/quic/crypto.c
> new file mode 100644
> index 0000000000000..c28c6fa565c1a
> --- /dev/null
> +++ b/net/quic/crypto.c
> @@ -0,0 +1,593 @@

[ ... ]

> +int quic_crypto_set_cipher(struct quic_crypto *crypto, u32 type)
> +{

[ ... ]

> +	crypto->rx_tfm[1] = tfm;
> +	tfm = crypto_alloc_sync_skcipher(cipher->skc, 0, 0);
> +	if (IS_ERR(tfm)) {
> +		err = PTR_ERR(tfm);
> +		goto err;
> +	}
> +	crypto->rx_hp_tfm = tfm;

[Severity: Low]

This isn't a bug, but crypto_alloc_sync_skcipher() returns a struct
crypto_sync_skcipher pointer. In struct quic_crypto, rx_hp_tfm and
tx_hp_tfm are declared as struct crypto_skcipher pointers. Because the
value goes through void *tfm, the compiler does not see the mismatch.

quic_crypto_free() then releases them with crypto_free_skcipher() instead
of the matching crypto_free_sync_skcipher():

	if (crypto->rx_hp_tfm)
		crypto_free_skcipher(crypto->rx_hp_tfm);

This only works because base is the first member of struct
crypto_sync_skcipher.

Could these fields be declared as struct crypto_sync_skcipher pointers
and freed with crypto_free_sync_skcipher()? That would also let
SYNC_SKCIPHER_REQUEST_ON_STACK() and skcipher_request_set_sync_tfm() be
used without casts.

[ ... ]

> +/* Save token secret in Initial TX secret (phase 1) for token generation. */
> +int quic_crypto_set_token_secret(struct quic_crypto *crypto)
> +{
> +	/* Reuse TX AEAD (phase 1) in Initial crypto. */
> +	u8 key[TLS_CIPHER_AES_GCM_128_KEY_SIZE], *srt = crypto->tx_secret[1];
> +	struct crypto_aead *tfm = crypto->tx_tfm[1];
> +	struct quic_data s = {}, k, i;
> +	int err;
> +
> +	if (!memchr_inv(srt, 0, TLS_CIPHER_AES_GCM_128_SECRET_SIZE))
> +		get_random_bytes(srt, TLS_CIPHER_AES_GCM_128_SECRET_SIZE);
> +
> +	quic_data(&s, srt, TLS_CIPHER_AES_GCM_128_SECRET_SIZE);
> +	quic_data(&k, key, TLS_CIPHER_AES_GCM_128_KEY_SIZE);
> +	quic_data(&i, crypto->tx_iv[1], QUIC_IV_LEN);
> +	err = quic_crypto_keys_derive(crypto->secret_tfm, &s, &k, &i, NULL,
> +				      QUIC_VERSION_V1);
> +	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;
> +	get_random_bytes(&crypto->tx_count[1], sizeof(crypto->tx_count[1]));

[Severity: Medium]

If tx_secret[1] is already set, for example inherited from the listening
socket, this keeps that secret. It then re-derives the token AEAD key and
tx_iv[1] with the fixed QUIC_VERSION_V1 labels. So every socket that
shares the listener's token secret gets the same AES-GCM key and the same
base IV.

The only per-socket difference is the random starting value of
tx_count[1]. In the later patch "quic: add crypto packet encryption and
decryption", quic_crypto_generate_token() does:

	counter = crypto->tx_count[1]++;

and quic_crypto_token_protect() builds the nonce as tx_iv[1] XOR counter.

Won't two sockets reuse a (key, nonce) pair whenever their counter
windows overlap? With S sockets each issuing n tokens, the chance is
roughly S^2 * n / 2^64.

The listener's own Retry token counter also starts at a random point in
the same space. Nothing rotates the key. The counter is also sent in
clear in the token AAD, so an observer can see collisions directly.

A single GCM nonce reuse reveals the XOR of the two plaintexts and lets
an attacker recover the GHASH key. With that key, Retry and NEW_TOKEN
tokens can be forged, which defeats address validation on the listener.

The code that copies tx_secret[1] into accepted sockets is not in this
series. This concern is based on the memchr_inv() reuse branch above and
on the v19 changelog, which says the randomization was added "to prevent
AES-GCM nonce reuse across sockets accepted from the same listening
socket".

Does the randomization prevent reuse, or does it only make reuse
unlikely within a 64-bit space? Keeping collisions under the usual 2^-32
bound for GCM allows only about 2^16 sockets.

Would a deterministic scheme fit better? Options include a per-socket key
derived from a unique salt, one shared counter on the listener, or key
rotation.

[ ... ]

> diff --git a/net/quic/crypto.h b/net/quic/crypto.h
> new file mode 100644
> index 0000000000000..29eaf0cbd2e17
> --- /dev/null
> +++ b/net/quic/crypto.h
> @@ -0,0 +1,90 @@

[ ... ]

> +	u64 txlimit; /* Max packets encrypted per key */
> +	u64 rxlimit; /* Max decryption failures per crypto level */
> +};
> +
> +struct quic_crypto {

[ ... ]

> +	atomic_t async_pending[2]; /* Async pending count (key phase 0 and 1) */
> +	u64 tx_count[2];           /* Packets encrypted (key phase 0 and 1) */

[Severity: Low]

tx_count[] is documented as a per-phase count of encrypted packets,
compared against txlimit. quic_crypto_keys_derive_and_install() treats it
that way and resets it on rekey:

	crypto->tx_count[phase] = 0;

quic_crypto_set_token_secret() uses tx_count[1] of the Initial crypto in
a different way, as a random AES-GCM token nonce counter. The comments on
tx_secret[1], tx_iv[1] and tx_tfm[1] say "key phase 0 and 1". They do not
say that phase 1 of the Initial crypto holds the token secret and the
token AEAD.

Nothing fails at the end of the series, because Initial packets always
use key phase 0. A later change that rekeys or limit-checks phase 1 of
the Initial crypto could silently break token nonce generation, or hit a
spurious -EKEYEXPIRED.

Could the comments document this dual use, or could the token state move
to dedicated fields?

> +
> +	/* Timestamp 1st packet sent after key update */
> +	u64 key_update_send_time;
> +	u64 key_update_time; /* Duration to retain old keys after key update */
> +	u64 rx_fails;        /* Failures decrypted */

[Severity: Medium]

Is this counter meant to be connection-wide? quic_init_sock() allocates
a separate struct quic_crypto for each of the QUIC_CRYPTO_MAX levels, so
each level has its own rx_fails. struct quic_cipher above also documents
rxlimit as "Max decryption failures per crypto level".

In the later patch, quic_crypto_decrypt() checks the per-level counter:

	if (err == -EBADMSG && ++crypto->rx_fails >= crypto->cipher->rxlimit)

RFC 9001 Section 6.6 says:

  If the total number of received packets that fail authentication
  within the connection, across all keys, exceeds the integrity limit
  for the selected AEAD, the endpoint MUST immediately close the
  connection

Handshake, 0-RTT and 1-RTT all use the negotiated AEAD. An attacker
sending forged packets could therefore get up to about rxlimit failures
at each level before any counter trips. This matters most for AES-CCM,
where the limit is 2^21.5.

The v17 changelog says rx_fails was made "a connection-wide counter ...
as required by RFC9001 Section 6". Was that undone by the v18 per-level
allocation and the v19 "per crypto level" comment?

[ ... ]

> diff --git a/net/quic/socket.c b/net/quic/socket.c
> index 78a08dd998a8e..d717efca9b9e6 100644
> --- a/net/quic/socket.c
> +++ b/net/quic/socket.c
> @@ -40,11 +40,38 @@ static void quic_write_space(struct sock *sk)

[ ... ]

> +static void quic_sock_destruct(struct sock *sk)
> +{
> +	struct quic_crypto *crypto;
> +	u8 i;
> +
> +	/* Deferred crypto free for async encryption/decryption. */
> +	for (i = 0; i < QUIC_CRYPTO_MAX; i++) {
> +		crypto = quic_crypto(sk, i);
> +		if (!crypto)
> +			continue;
> +		queue_work(quic_wq, &crypto->work);
> +	}
> +
> +	quic_sk_destruct(sk);
> +}
> +
>  static int quic_init_sock(struct sock *sk)
>  {
>  	struct quic_pnspace *space;
> +	struct quic_crypto *crypto;
>  	u8 i;
>  
> +	sk->sk_destruct = quic_sock_destruct;

[Severity: Low]

This isn't a bug, but the commit message body only describes the
crypto.c helpers. It doesn't mention three changes in socket.c:

- quic_init_sock() now sets sk->sk_destruct to quic_sock_destruct().

- quic_init_sock() allocates one struct quic_crypto per encryption
  level, which adds new -ENOMEM failure points to socket creation.

- Crypto teardown is deferred to quic_wq through quic_crypto_free_work(),
  and runs after the socket is gone.

The async crypto lifetime argument depends on these points. Right now
they only appear in the v12 and v18 notes below the "---" line, which
won't end up in git history.

The body also doesn't say that several new fields and helpers are not
read or called anywhere in this patch, and are placeholders for later
patches. These include rx_fails, async_pending, key_update_send_time,
key_update_time, ticket_ready, send_offset, recv_offset, txlimit,
rxlimit, the QUIC_TOKEN_* defines and quic_crypto_discard().

Could the commit message cover these?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795393690.git.lucien.xin%40gmail.com

  reply	other threads:[~2026-11-24  1:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  0:27 [PATCH net-next v19 00/15] net: introduce QUIC infrastructure and core subcomponents Xin Long
2026-11-23  0:27 ` [PATCH net-next v19 01/15] net: define IPPROTO_QUIC and SOL_QUIC constants Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:27 ` [PATCH net-next v19 02/15] net: build socket infrastructure for QUIC protocol Xin Long
2026-11-23  0:27 ` [PATCH net-next v19 03/15] quic: provide common utilities and data structures Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:28 ` [PATCH net-next v19 04/15] quic: provide family ops for address and protocol Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:28 ` [PATCH net-next v19 05/15] quic: provide quic.h header files for kernel and userspace Xin Long
2026-11-23  0:28 ` [PATCH net-next v19 06/15] quic: add stream management Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:28 ` [PATCH net-next v19 07/15] quic: add connection id management Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:28 ` [PATCH net-next v19 08/15] quic: add path management Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:28 ` [PATCH net-next v19 09/15] quic: add congestion control Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:28 ` [PATCH net-next v19 10/15] quic: add packet number space Xin Long
2026-11-23  0:28 ` [PATCH net-next v19 11/15] quic: add crypto key derivation and installation Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko [this message]
2026-11-23  0:28 ` [PATCH net-next v19 12/15] quic: add crypto packet encryption and decryption Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko
2026-11-23  0:28 ` [PATCH net-next v19 13/15] quic: add timer management Xin Long
2026-11-23  0:28 ` [PATCH net-next v19 14/15] quic: add packet builder base Xin Long
2026-11-23  0:28 ` [PATCH net-next v19 15/15] quic: add packet parser base Xin Long
2026-11-24  1:21   ` netdev-bot+sashiko

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=179548328150.3135.7027633658882912871@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=aahringo@redhat.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=cel@kernel.org \
    --cc=daniel@haxx.se \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=dreibh@simula.no \
    --cc=edumazet@kernel.org \
    --cc=hare@suse.de \
    --cc=hepengtao@xiaomi.com \
    --cc=horms@kernel.org \
    --cc=illiliti@protonmail.com \
    --cc=jamie.bainbridge@gmail.com \
    --cc=jbaron@akamai.com \
    --cc=jlayton@kernel.org \
    --cc=kernel-tls-handshake@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --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=pabeni@redhat.com \
    --cc=paul@jakma.org \
    --cc=pc@manguebit.org \
    --cc=quic@lists.linux.dev \
    --cc=sd@queasysnail.net \
    --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