open-gpu-kernel-modules icon indicating copy to clipboard operation
open-gpu-kernel-modules copied to clipboard

CC mode: memmgrVerifyGspDmaOps fails (NV_ERR_INVALID_DATA) when gcm(aes) resolves to the generic template — zero-length AAD scatterlist entry in libspdm_aead.c

Open probatur opened this issue 1 month ago • 5 comments

NVIDIA Open GPU Kernel Modules Version

595.91.07 (open kernel modules, distribution package nvidia-kernel-source-595-server-open)

Please confirm this issue does not happen with the proprietary driver (of the same version). This issue tracker is only for bugs specific to the open kernel driver.

  • [ ] I confirm that this does not happen with the proprietary driver package.

Operating System and Version

Ubuntu 24.04 LTS

Kernel Release

Linux 6.17.0 x86_64 (Ubuntu distribution kernel series; reproduced in a 6.17.0 kernel, and the hash walk in crypto/ahash.c is unchanged in current master)

Please confirm you are running a stable release kernel (e.g. not a -rc). We do not accept bug reports for unreleased kernels.

  • [x] I am running on a stable kernel release.

Hardware: GPU

NVIDIA H100 NVL (Confidential Computing mode on)

Describe the bug

Symptom. With CC on, RM init fails in the GSP DMA self-check (memmgrVerifyGspDmaOps): the write is rejected with NV_ERR_INVALID_DATA. RPC traffic works. It happens when gcm(aes) resolves to the generic template gcm_base(ctr(aes-generic),ghash-generic) at the time the driver allocates its tfm, e.g. on a kernel without CRYPTO_AES_NI_INTEL, or with it modular and not yet loaded. When an AES-NI gcm(aes) is registered first (built in, or aesni_intel loaded before nvidia), the same system initialises.

Cause (read in source, reproduced in a test module).

  1. kernel-open/nvidia/libspdm_aead.c, libspdm_aead_prealloced: when a_data is NULL and a_data_size is 0, sg_set_buf() still sets the first (AAD) entry of sg_in/sg_out (to the preallocated buffer, length 0), and the request is out of place. The DMA path calls ccslEncryptWithRotationChecks(..., NULL, 0, ...), so it hits this.
  2. include/crypto/aead.h (l.63-65 in 6.17): "zero-length scatterlist elements are not allowed in the used part of the scatterlist. Thus, if there is no associated data, the first element must point to the plaintext/ciphertext."
  3. In crypto/gcm.c, with assoclen 0, the GHASH pass starts on that empty entry; crypto_hash_walk_first() returns 0 for it and the ahash update hashes no ciphertext. The tag becomes GHASH(padding, lengths) XOR E(J0): ciphertext right, tag wrong. The AES-NI GCM implementations are not affected: with no associated data they hash nothing for the AAD, and their data pass uses the skcipher walk, which steps over the zero-length entry, so GHASH covers the ciphertext.

To Reproduce

Reproduction (no GPU needed). A kernel module that builds the same 3-entry layout (zero-length AAD entry first, 4-byte plaintext, 16-byte tag, 12-byte IV, out of place) and encrypts with gcm(aes):

  • generic template: ciphertext equals the reference; tag differs (it equals the value predicted from "GHASH over 12 zero bytes + the lengths block");
  • aesni drivers: tag equals the reference;
  • generic template with a 2-entry layout (no AAD entry): tag equals the reference. We can share the module source on request.

Bug Incidence

Always

nvidia-bug-report.log.gz

Not attached. The defect is in the driver's kernel-crypto glue and reproduces without a GPU (see To Reproduce). It is fully determined by the source lines cited above. We can run nvidia-bug-report.sh on request if you still need it.

More Info

Suggested fix. In libspdm_aead_prealloced, when a_data_size is 0 do not put an AAD entry in either sg_in or sg_out: start both lists at the payload entry (or build 2-entry lists), as aead.h requires. Workaround: make an AES-NI gcm(aes) available before the driver allocates its AEAD (CONFIG_CRYPTO_AES_NI_INTEL=y, or load aesni_intel before nvidia).

Related: NVIDIA/nvtrust#19 (closed, not planned), whose reporter found "modprobe aesni_intel" made the driver load; this is likely the same defect.

Note on the form: not tested with the proprietary driver package, so the box above is left unticked; the defect is in kernel-open/nvidia/libspdm_aead.c as cited.

probatur avatar Oct 14 '26 19:10 probatur

I’d like to work on this issue. I’ll start by skipping the AAD scatterlist entry when a_data_size is zero, then verify encryption and decryption with both generic and AES-NI GCM implementations. I’ll open a draft PR for feedback once the initial changes are ready.

vishalshetagar avatar Oct 19 '26 19:10 vishalshetagar

Independent confirmation on real hardware, on the 580 branch and an older kernel than the original report.

Setup

  • GPU: NVIDIA H100 80GB HBM3 (SXM), Confidential Computing mode on, VBIOS 96.00.D9.00.01
  • Driver: 580.178.04 open kernel modules (Ubuntu's signed linux-modules-nvidia-580-open package), GSP firmware 580.178.04
  • Guest: Ubuntu 22.04, kernel 6.8.0-1073-gcp, Intel TDX confidential VM on Google Cloud (a3-highgpu-1g)
  • CONFIG_CRYPTO_AES_NI_INTEL=m. In our image, udev module autoloading was disabled, so aesni_intel was never loaded. The CPU has the aes and pclmulqdq flags.

Failing boot (nothing loaded by hand), /proc/crypto:

name    : gcm(aes)
driver  : gcm_base(ctr(aes-generic),ghash-generic)
priority: 100

First nvidia-smi:

NVRM: ... NV_ERR_INVALID_DATA ... NV2080_CTRL_CMD_INTERNAL_MEMMGR_MEMORY_TRANSFER_WITH_GSP @ mem_utils.c:306
NVRM: ... returned from memmgrVerifyGspDmaOps(pGpu, GPU_GET_MEMORY_MANAGER(pGpu)) @ kern_bus_gm107.c:402
NVRM: RmInitAdapter: RmInitNvDevice failed, bailing out of RmInitAdapter
NVRM: GPU 0000:04:00.0: RmInitAdapter failed! (0x24:0x25:1220)

Working boot: same disk image, kernel and command line. After a VM stop/start, we ran modprobe aesni_intel before the first device open. gcm(aes) then resolved to generic-gcm-aesni (priority 400), and the GPU initialised: no memmgrVerifyGspDmaOps error, CC status ON, ready state set, and a CUDA matmul completed.

A caveat for anyone hitting this. After one failed CC init, reloading nvidia in the same boot does not recover. The GPU then refuses probe ("does not include the required GPU System Processor (GSP)") until the VM is fully stopped and started. A guest reboot is not enough to test a workaround.

Workaround we ship (it also satisfies the ordering for distros that build AES-NI as a module):

# /etc/modules-load.d/<name>.conf   (aesni_intel listed before nvidia)
aesni_intel
nvidia
# /etc/modprobe.d/<name>.conf
softdep nvidia pre: aesni_intel

We also check before starting nvidia-persistenced that the top-priority gcm(aes) driver in /proc/crypto is not gcm_base(...), and fail closed if it is.

On whose bug it is. include/crypto/aead.h (lines 63-65 in both v6.8 and current master) says that zero-length scatterlist elements are not allowed in the used part of the list. So the driver's layout is outside the API contract, and the fix belongs in libspdm_aead.c, as #1467 does. The code is unchanged at 580.178.04 and at 620.70.06, apart from the added crypto_aead_setauthsize() call. One data point that may matter for testing: since commit 9f4e9553a1f4 ("crypto: gcm - Use GHASH library instead of crypto_ahash", in v7.1), the generic template hashes through scatterwalk_next(), whose clamp steps over empty entries. From reading the code, the mis-tag is therefore likely limited to kernels before v7.1. We have not tested that. On those newer kernels, a test of #1467 with the generic template may pass with or without the patch.

We noticed that 620.70.06 adds aesni_intel gcm ctr ghash to the module's MODULE_SOFTDEP (libspdm_internal_crypt_lib.c). That should hide the problem wherever modprobe honours softdeps and AES-NI is built as a module. It does not cover kernels without AES-NI, other loaders, or the 580/595 branches, and the empty AAD entry is still there. (Earlier tags have "pre: ecdh_generic,ecdsa_generic"; the comma likely makes modprobe read it as a single module name.)

We can test #1467 on CC H100 hardware against 580.178.04 if that helps.

maayank avatar Nov 15 '26 14:11 maayank

@maayank Thanks for the detailed confirmation and the offer to test. Testing #1467 against 580.178.04 on your CC H100 setup would be very helpful.

Could you apply the same change to lkca_aead_internal() and test with gcm_base(ctr(aes-generic),ghash-generic) still selected when the driver allocates its AEAD, without the AES-NI workaround?

Following your recovery caveat, please use a full VM stop/start between trials. Confirmation that the patched driver completes initialization, keeps CC enabled, and runs the CUDA matmul would provide the hardware validation currently missing from the PR.

vishalshetagar avatar Nov 15 '26 14:11 vishalshetagar

@vishalshetagar Hardware results for #1467 on a CC H100: the patch fixes it.

Setup

  • NVIDIA H100 80GB HBM3, CC mode on, VBIOS 96.00.D9.00.01, GSP firmware 580.178.04
  • Intel TDX confidential VM on Google Cloud (a3-highgpu-1g, Spot), stock Ubuntu 22.04 image, kernel 6.8.0-1073-gcp. Secure Boot was off so the self-built modules would load.
  • Userspace: Ubuntu's 580.178.04-0ubuntu0.22.04.1 packages (nvidia-utils, nvidia-compute-utils, libnvidia-compute, libnvidia-cfg1, nvidia-firmware). CUDA test with torch 2.11.0+cu128.
  • Two module builds from tag 580.178.04 (make modules NV_KERNEL_MODULES="nvidia nvidia-uvm", gcc-12): plain, and with the #1467 diff applied (only kernel-open/nvidia/libspdm_aead.c differs).
  • No AES-NI: install aesni_intel /bin/false and install ghash_clmulni_intel /bin/false in modprobe.d, and the initramfs regenerated. Each trial: modprobe ecdsa_generic ecdh_generic, insmod nvidia.ko nvidia-uvm.ko, nvidia-persistenced --uvm-persistence-mode, nvidia-smi, nvidia-smi conf-compute -f / -srs 1 / -grs, then a 4096x4096 torch matmul on cuda:0.
  • Full VM stop/start before every trial.

In every trial, after the driver loaded, /proc/crypto showed only the generic template, and lsmod showed neither aesni_intel nor ghash_clmulni_intel:

name         : gcm(aes)
driver       : gcm_base(ctr(aes-generic),ghash-generic)
priority     : 100

Results

Trial (each after a stop/start) Driver Result
1 580.178.04 + #1467 GPU initialised, Persistence Mode Enabled, CC status: ON, Ready state: ready, matmul OK, no NVRM errors
2 580.178.04 plain (control) memmgrVerifyGspDmaOps NV_ERR_INVALID_DATA, RmInitAdapter failed! (0x24:0x25:1220), nvidia-smi: No devices were found
3 580.178.04 + #1467 (after trial 2's failed init) same as trial 1: CC ON, ready, matmul OK, no NVRM errors

Control (trial 2), first failure:

NVRM: nvAssertOkFailedNoLog: Assertion failed: Invalid data passed [NV_ERR_INVALID_DATA] (0x00000025) returned from pRmApi->Control(..., NV2080_CTRL_CMD_INTERNAL_MEMMGR_MEMORY_TRANSFER_WITH_GSP, ...)
NVRM: nvCheckOkFailedNoLog: Check failed: Invalid data passed [NV_ERR_INVALID_DATA] (0x00000025) returned from _memmgrMemReadOrWriteWithGsp(pGpu, pDstInfo, pBuf, size, NV_FALSE ) @ mem_utils.c:800
NVRM: nvAssertOkFailedNoLog: Assertion failed: Invalid data passed [NV_ERR_INVALID_DATA] (0x00000025) returned from memmgrVerifyGspDmaOps(pGpu, GPU_GET_MEMORY_MANAGER(pGpu)) @ kern_bus_gm107.c:402
NVRM: RmInitNvDevice: *** Cannot initialize the device
NVRM: GPU 0000:04:00.0: RmInitAdapter failed! (0x24:0x25:1220)

Patched (trial 1 and 3):

NVIDIA H100 80GB HBM3   Persistence-M: On
Driver Version : 580.178.04   GSP Firmware Version : 580.178.04
CC status: ON
Confidential Compute GPUs Ready state: ready
2.11.0+cu128 True NVIDIA H100 80GB HBM3
matmul ok

Two things that can confuse a re-run:

  • Ubuntu's packaged nvidia-persistenced.service runs with --no-persistence-mode and is started when the device appears. In CC mode, the GPU is then torn down after the first client closes, and every later open fails with Disabling GSP offload -- GPU not supported / RmInitAdapter failed! (0x22:0x56:776), which looks like a driver failure. Mask that unit and run nvidia-persistenced --uvm-persistence-mode yourself.
  • We also ran a GPU-free test module with the driver's 3-entry layout (zero-length AAD entry first, out of place) against GCM spec test cases 2 and 3:
    • On 6.8.0-1073-gcp and 7.0.0-1017-gcp, the generic template (gcm_base(ctr(aes-generic),ghash-generic), and on 7.0 gcm_base(ctr(aes-lib),ghash-pclmulqdqni)) gives the right ciphertext and a wrong tag, while the 2-entry layout is correct. For 16-byte-multiple lengths the wrong tag equals GHASH over the lengths block only, XOR E(K, J0).
    • On 7.3.0-1004-gcp, the non-AES-NI default is gcm-aes-lib, which returns the correct tag for the 3-entry layout. So kernels from about v7.1 on mask the bug, and a software test of #1467 there would pass with or without the patch.
    • The AES-NI drivers are correct on all three.

maayank avatar Nov 15 '26 20:11 maayank

@maayank Thanks for the thorough hardware validation and the controlled patched/unpatched/patched comparison. This confirms that #1467 fixes CC initialization with generic GCM on your H100 setup, with CC enabled and the CUDA matmul completing successfully. I’ll update the PR’s validation section to reference your results and the tested driver/kernel versions.

vishalshetagar avatar Nov 16 '26 01:11 vishalshetagar