You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qemu/include/crypto
Peter Xu 7e0c22d585 io/crypto: Move tls premature termination handling into QIO layer
QCryptoTLSSession allows TLS premature termination in two cases, one of the
case is when the channel shutdown() is invoked on READ side.

It's possible the shutdown() happened after the read thread blocked at
gnutls_record_recv().  In this case, we should allow the premature
termination to happen.

The problem is by the time qcrypto_tls_session_read() was invoked,
tioc->shutdown may not have been set, so this may instead be treated as an
error if there is concurrent shutdown() calls.

To allow the flag to reflect the latest status of tioc->shutdown, move the
check upper into the QIOChannel level, so as to read the flag only after
QEMU gets an GNUTLS_E_PREMATURE_TERMINATION.

When at it, introduce qio_channel_tls_allow_premature_termination() helper
to make the condition checks easier to read.  When doing so, change the
qatomic_load_acquire() to qatomic_read(): here we don't need any ordering
of memory accesses, but reading a flag.  qatomic_read() would suffice
because it guarantees fetching from memory.  Nothing else we should need to
order on memory access.

This patch will fix a qemu qtest warning when running the preempt tls test,
reporting premature termination:

QTEST_QEMU_BINARY=./qemu-system-x86_64 ./tests/qtest/migration-test --full -r /x86_64/migration/postcopy/preempt/tls/psk
...
qemu-kvm: Cannot read from TLS channel: The TLS connection was non-properly terminated.
...

In this specific case, the error was set by postcopy_preempt_thread, which
normally will be concurrently shutdown()ed by the main thread.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juraj Marcin <jmarcin@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20250918203937.200833-2-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
3 weeks ago
..
aes-round.h crypto: Add aesdec_ISB_ISR_AK_IMC 2 years ago
aes.h target/riscv: Use existing lookup tables for MixColumns 2 years ago
afsplit.h qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop prefix 1 year ago
akcipher.h include/: spelling fixes 2 years ago
block.h qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop prefix 1 year ago
cipher.h qapi/crypto: Rename QCryptoCipherAlgorithm to *Algo, and drop prefix 1 year ago
clmul.h crypto: Add generic 64-bit carry-less multiply routine 2 years ago
desrfb.h replace TABs with spaces 3 years ago
hash.h crypto: Introduce SM3 hash hmac pbkdf algorithm 12 months ago
hmac.h crypto/hmac: Allow to build hmac over multiple qcrypto_gnutls_hmac_bytes[v] calls 2 months ago
init.h crypto: Fix LGPL information in the file headers 6 years ago
ivgen.h qapi/crypto: Rename QCryptoIVGenAlgorithm to *Algo, and drop prefix 1 year ago
pbkdf.h qapi/crypto: Rename QCryptoCipherAlgorithm to *Algo, and drop prefix 1 year ago
random.h crypto: Fix LGPL information in the file headers 6 years ago
secret.h Use DECLARE_*CHECKER* macros 5 years ago
secret_common.h bulk: Do not declare function prototypes using 'extern' keyword 2 years ago
secret_keyring.h qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros 5 years ago
sm4.h crypto: Add SM4 constant parameter CK 2 years ago
tls-cipher-suites.h Clean up header guards that don't match their file name 4 years ago
tlscreds.h crypto: Make QCryptoTLSCreds* structures private 4 years ago
tlscredsanon.h crypto: Make QCryptoTLSCreds* structures private 4 years ago
tlscredspsk.h crypto: Make QCryptoTLSCreds* structures private 4 years ago
tlscredsx509.h crypto: Make QCryptoTLSCreds* structures private 4 years ago
tlssession.h io/crypto: Move tls premature termination handling into QIO layer 3 weeks ago
x509-utils.h qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop prefix 1 year ago
xts.h crypto: Fix LGPL information in the file headers 6 years ago