All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Cristian Rodriguez <yo@cristianrodriguez.net>
Cc: Mikulas Patocka <mpatocka@redhat.com>,
	 libc-alpha@sourceware.org, Zdenek Kabelac <zkabelac@redhat.com>,
	 Ondrej Kozina <okozina@redhat.com>,
	 Milan Broz <gmazyland@gmail.com>,
	dm-devel@lists.linux.dev
Subject: Re: memcpy is leaking secret data through ZMM vector registers
Date: Wed, 12 Aug 2026 18:28:24 +0200	[thread overview]
Message-ID: <lhupkznjobb.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAPBLoAdgefcQ=otsy4GMsCCAgzY=7E1bDBtZsKMFy+Af0nPVfQ@mail.gmail.com> (Cristian Rodriguez's message of "Wed, 12 Aug 2026 10:04:02 -0400")

* Cristian Rodriguez:

> c
>
> On Fri, Apr 19, 2024 at 10:08 AM Mikulas Patocka <mpatocka@redhat.com> 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.

The application might not know which vector registers glibc uses.

Ideally, we would zap the registers that we know we use in memset.  It's
probably most straightforward to do in the memset assembler
implementation, as a build variant, but I haven't tried actually
implementing it.

Thanks,
Florian


      parent reply	other threads:[~2026-08-12 16:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 14:07 memcpy is leaking secret data through ZMM vector registers Mikulas Patocka
2024-04-19 14:19 ` H.J. Lu
2024-04-19 14:24   ` Mikulas Patocka
2024-04-19 14:37     ` H.J. Lu
2024-04-19 18:04       ` Mikulas Patocka
2024-04-19 18:45         ` Paul Eggert
2024-04-19 18:47           ` Zack Weinberg
2024-04-19 18:53             ` Alexander Monakov
2024-04-19 19:11               ` Zack Weinberg
2024-04-19 20:15                 ` Mikulas Patocka
2024-04-19 20:31                   ` Zack Weinberg
2024-04-19 21:11                     ` Mikulas Patocka
2024-04-19 23:27                       ` Florian Weimer
2024-04-20  3:29                         ` Zack Weinberg
2026-08-12  9:38                           ` Jan Sebastian Götte
2024-04-21  1:20 ` Andreas K. Huettel
2024-04-22  9:33 ` Szabolcs Nagy
2026-08-12 14:04 ` Cristian Rodriguez
2026-08-12 14:12   ` H.J. Lu
2026-08-12 16:28   ` Florian Weimer [this message]

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=lhupkznjobb.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=gmazyland@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=mpatocka@redhat.com \
    --cc=okozina@redhat.com \
    --cc=yo@cristianrodriguez.net \
    --cc=zkabelac@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.