Netdev List
 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@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, 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 v18 11/15] quic: add crypto key derivation and installation
Date: Tue, 10 Nov 2026 22:29:47 +0000	[thread overview]
Message-ID: <179434978792.994134.17759133431780284123@kernel.org> (raw)
In-Reply-To: <b269e7436d8e9b5816a8e716d661767a2e43c27b.1794241656.git.lucien.xin@gmail.com>

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

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

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] quic_crypto_set_cipher() (net/quic/crypto.c:272) stores seven
  freshly allocated transforms (secret_tfm, rx_tfm[0..1], rx_hp_tfm,…
- [Low] The commit message that stays in git history leaves out the
  socket lifecycle changes in net/quic/socket.c.
- [Low] quic_crypto_set_cipher() allocates the header-protection
  transforms with crypto_alloc_sync_skcipher(), which returns struct…

--

quic: add crypto key derivation and installation

This patch adds net/quic/crypto.c. It provides HKDF helpers, cipher
transform allocation, traffic secret installation, key update and
stateless reset token derivation for QUIC. It also allocates one
struct quic_crypto per encryption level in quic_init_sock(), and a new
sk_destruct callback defers freeing those contexts to quic_wq.

> quic: add crypto key derivation and installation
>
> This patch introduces 'quic_crypto', a component responsible for QUIC
> encryption key derivation and installation across the various key
> levels: Initial, Handshake, 0-RTT (Early), and 1-RTT (Application).

[ ... ]

> - quic_crypto_derive_secret(): Generate token for stateless reset or
>   master key for session resumption.
>
> These mechanisms are essential for establishing and maintaining secure
> communication throughout the QUIC connection lifecycle.

[Severity: Low]
The commit message describes this patch only as adding crypto helpers.
Could it also mention the socket lifecycle changes in net/quic/socket.c?

The patch also does the following:

  - installs a new quic_sock_destruct() as sk->sk_destruct in
    quic_init_sock()
  - allocates QUIC_CRYPTO_MAX struct quic_crypto contexts per socket
    with kzalloc_obj()
  - defers transform teardown to quic_crypto_free_work() on quic_wq,
    which runs after the socket has been destroyed

The function list also leaves out the new exported helper
quic_crypto_set_token_secret().

These details appear only in the v18 notes below the --- line, and
git am drops that text.

> diff --git a/net/quic/crypto.c b/net/quic/crypto.c
> new file mode 100644
> index 0000000000000..c4bf99b3e8239
> --- /dev/null
> +++ b/net/quic/crypto.c

[ ... ]

> +int quic_crypto_set_cipher(struct quic_crypto *crypto, u32 type)
> +{
> +	const struct quic_cipher *cipher;
> +	void *tfm;
> +	int err;
> +
> +	if (type < QUIC_CIPHER_MIN || type > QUIC_CIPHER_MAX)
> +		return -EINVAL;
> +
> +	cipher = &ciphers[type - QUIC_CIPHER_MIN];
> +	tfm = crypto_alloc_shash(cipher->shash, 0, 0);
> +	if (IS_ERR(tfm))
> +		return PTR_ERR(tfm);
> +	crypto->secret_tfm = 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]
Are the types for the header protection transforms consistent here?

crypto_alloc_sync_skcipher() returns a struct crypto_sync_skcipher *.
The result passes through the void *tfm local into rx_hp_tfm, and
tx_hp_tfm is handled the same way. Both fields are declared as struct
crypto_skcipher * in net/quic/crypto.h.

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

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

This works today only because struct crypto_sync_skcipher wraps a
struct crypto_skcipher base at offset 0. Because tfm is a void *, the
compiler cannot catch the mismatch. The mismatch is still present at
the end of the series, where quic_crypto_header_protect() uses these
fields as struct crypto_skcipher *.

Should the fields be declared as struct crypto_sync_skcipher * and
freed with crypto_free_sync_skcipher()?

[ ... ]

> +	crypto->tx_hp_tfm = tfm;
> +
> +	crypto->cipher = cipher;
> +	crypto->cipher_type = type;
> +	return 0;
> +err:
> +	quic_crypto_free(crypto);
> +	return err;
> +}

[Severity: Medium]
Can this error path destroy state that this call did not create?

quic_crypto_set_cipher() stores seven newly allocated transforms
without checking whether the context already holds any. On failure it
calls quic_crypto_free() on the whole context. That frees every
transform and then zeroes the structure up to send_offset:

	memzero_explicit(crypto, offsetof(struct quic_crypto, send_offset));

If this ran on a context that was already set up, the old transforms
would leak. If that second call then failed, it would also wipe the
live keys, the token secret in tx_secret[1], and the cipher,
send_ready and recv_ready state.

In this series the only caller is quic_crypto_set_secret(). It calls
quic_crypto_set_cipher() only when crypto->cipher is NULL, so this
path does not appear to be reachable yet.

The notes say later patches call quic_crypto_set_cipher() directly from
quic_inet_listen(), quic_connect() and quic_accept(). Those patches are
not part of this series.

Would it be safer to reject a context that already has transforms, and
to unwind only the allocations made by this call?

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

  reply	other threads:[~2026-11-10 22:29 UTC|newest]

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

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=179434978792.994134.17759133431780284123@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@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=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