On Wed, Aug 12, 2026 at 10:04 PM Cristian Rodriguez
<[email protected]> wrote:
>
> c
>
> On Fri, Apr 19, 2024 at 10:08 AM Mikulas Patocka <[email protected]> wrote:
> >
> > Hi
> >
> > As a part of LVM2, we are developing the libdevmapper library. The library
> > may be used to load cryptographic keys to the kernel, so it avoids leaking
> > the data to kernel memory and to the swap partition.
> >
> > After the use of cryptographic data, the libdevmapper library clears them
> > with memset and frees them afterwards. It executes __asm__ volatile("" :::
> > "memory") to thwart some compiler optimization regarding writing to
> > to-be-freed memory.
> >
> > We have a test "dmsecuretest.sh" that loads cryptographic keys into the
> > kernel, dumps a core, the core file is analyzed and if it contains the
> > key, the test fails.
> >
> > This test fails on AMD Zen 4 - the reason for the failure is that the
> > "memcpy" function uses ZMM registers for data copying. When memcpy exits,
> > the encryption key is present in the ZMM registers and the key remains
> > there even after both source and destination buffers of memcpy were
> > cleared.
>
> Isn't this what  -fzero-call-used-regs thing is all about? can-t you
> just apply the same technique in the memcpy implementation and zero
> them out on return?
> vector registers are volatile after all.

This isn't limited to vector registers.   If you don't want to leave anything
behind, you should use -fzero-call-used-regs in functions where keys
are accessed.

-- 
H.J.

Reply via email to