Re: memcpy is leaking secret data through ZMM vector registers

Cristian Rodriguez <[email protected]>
Newsgroups dev.linux.lists.dm-devel
Message-ID <CAPBLoAdgefcQ=otsy4GMsCCAgzY=7E1bDBtZsKMFy+Af0nPVfQ@mail.gmail.com>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.