linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <graf@amazon.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Lennart Poettering <mzxreary@0pointer.de>,
	<linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Theodore Ts'o <tytso@mit.edu>,
	"Colm MacCarthaigh" <colmmacc@amazon.com>,
	Torben Hansen <htorben@amazon.co.uk>,
	Jann Horn <jannh@google.com>
Subject: Re: [PATCH 2/2] random: add fork_event sysctl for polling VM forks
Date: Mon, 2 May 2022 20:57:01 +0200	[thread overview]
Message-ID: <f90d5e06-8cd7-14b3-43d5-c4799597d023@amazon.com> (raw)
In-Reply-To: <YnAiylnSytuYM53z@zx2c4.com>

Hey Jason,

On 02.05.22 20:29, Jason A. Donenfeld wrote:
> Hi Alex,
>
> On Mon, May 02, 2022 at 07:59:08PM +0200, Alexander Graf wrote:
>> to collect the use cases we all have and evaluate whether this patch is
>> a good stepping stone towards the final solution.
> Indeed, I'm all for collecting use cases. What I meant to say is that
> we're not going to add something "just 'cuz"; I'd like to have some
> concrete things in mind.
>
> To date, I've basically had your s2n case in mind, but as you haven't
> responded to this in the last month, I started looking to see if this


Unfortunate vacation timing on my side I suppose :)


> was useful elsewhere or if I should abandon it, so I filed this issue
> with the Go project: <https://github.com/golang/go/issues/52544>. We're
> over halfway through 5.18 now, and only at this point have you arrived
> to discuss and finalize things. So in all likelihood we'll wind up
> tabling this until 5.20 or never, since what I thought was an easy
> consensus before now apparently is not.


So far I see little that would block your patch? It seems to go into a 
good direction from all I can tell.


>> 1) A way for libraries such as s2n to identify that a clone occurred.
>> Because it's a deep-down library with no access to its own thread or the
>> main loop, it can not rely on poll/select. Mmap of a file however would
>> work great, as you can create transactions on top of a 64bit mmap'ed
>> value for example.
> I didn't realize that s2n can't poll. That's surprising. In the worst
> case, can't you just spawn a thread?


You block the thread on poll, so the only option is a thread. I was 
until now always under the working assumption that we can't do this in a 
thread because you don't want your single threaded application to turn 
into a pthreaded one, but you make me wonder. Let me check with Torben 
tomorrow.


>
>> 2) A way to notify larger applications (think Java here) that a system
>> is going to be suspended soon so it can wipe PII before it gets cloned
>> for example.
> Suspension, like S3 power notification stuff? Talk to Rafael about that;


Whether you go running -> S3 -> clone or you go running -> paused -> 
clone is an implementation detail I'm not terribly worried about. Users 
can do either, because on both cases the VM is in paused state.


> this isn't related to the VM fork issue. I use those PM notifiers
> happily in kernel space but AFAICT, there's still no userspace thing for
> it. This seems orthogonal to this conversation though, so let's not veer
> off into that topic.
>
> If you didn't mean S3 but actually meant notification prior to snapshot
> taking, we don't have any virtual hardware for that, so it's a moot
> point.


I think we'll want to have an external button similar to the ACPI sleep 
button or lid close event eventually, so that we can loop the VM in on 
the suspend path the same way S3 does.

Today we don't have it, I agree. And if it's possible to maintain the 
same user space interface with this in mind, all is good. Let's just 
keep it in mind as something that will probably come eventually so that 
we don't redesign the UAPI in a year from now.


>
>> 3) Notifications after clone so applications know they can regenerate VM
>> unique data based on randomness.
> You mean this as "the same as (1) but with poll() instead of mmap()",
> right?


Yes :)


>
>> Lennart, looking at the current sysctl proposal, systemd could poll() on
>> the fork file. It would then be able to generate a /run/fork-id file
>> which it can use for the flow above, right?
> For the reasons I gave in my last email to Lennart, I don't think
> there's a good way for systemd to generate a fork-id file on its own
> either. I don't think systemd should really be involved here as a
> provider of values, just as a potential consumer of what the kernel
> provides.


Yes, systemd would poll on fork_event. When that returns, it reads 
/dev/urandom and writes a new /run/fork-id file with that. Libraries 
that don't want to be in the business of spawning threads can use that 
file to identify that they were cloned. Systemd can use that id as seed 
for networkd.


>
>> The sysctl proposal also gives us 3, if we implement the inhibitor
>> proposal [1] in systemd.
> These userspace components you're proposing seem like a lot of
> overengineering for little gain, which is why this conversation went
> nowhere when Amazon attempted all this year. But it sounds like you
> agree with me based on your remark below about systemd-less interfaces
> provided by the kernel.


I would be happy to get to 99% of this with pure kernel based 
interfaces. The reason the kernel conversation seemingly went nowhere 
was not because of "overengineering". It was because the review feedback 
eventually was "This is a file, make user space manage it".


>> Overall, it sounds to me like the sysctl poll based kernel interface in
>> this patch in combination with systemd inhibitors gives us an answer to
>> most of the flows above.
>>
>> I can see attractiveness in providing the /run/fork-id directly from the
>> kernel though, to remove the dependency on systemd for poll-less
>> notification of libraries.
>>
>> Jason, how much complexity would it add to provide an mmap() and read()
>> interface to a fork counter value to the sysctl? Read sounds like a
>> trivial change on top of what you have already, mmap a bit more heavy
>> lift. If we had both, it would allow us to implement a Linux standard
>> fork detect path in libraries that does not rely on systemd.
> mmap() does not give us anything if we're not going to expose the raw
> ACPI-mapped ID directly. It will still be a racy mechanism until we do
> that. So I think we should wait until there's a proper vmgenid
> word-sized counter to expose something mmap()able. If you have the
> energy to talk to Microsoft about this and make it happen, please be my
> guest. As I wrote at the beginning of this email. I haven't gotten a
> response from you at all about this stuff in quite some time, so I'm not
> really itching take that on alone now.


Absolutely! Let's see where it goes :)


Alex





Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879



  reply	other threads:[~2022-05-02 18:57 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 14:06 [PATCH 1/2] sysctl: read() must consume poll events, not poll() Jason A. Donenfeld
2022-05-02 14:06 ` [PATCH 2/2] random: add fork_event sysctl for polling VM forks Jason A. Donenfeld
2022-05-02 15:40   ` Lennart Poettering
2022-05-02 16:12     ` Jason A. Donenfeld
2022-05-02 16:51       ` Lennart Poettering
2022-05-02 17:59         ` Alexander Graf
2022-05-02 18:29           ` Jason A. Donenfeld
2022-05-02 18:57             ` Alexander Graf [this message]
2022-05-02 20:03               ` Jason A. Donenfeld
2022-05-03  8:29           ` Lennart Poettering
2022-05-03 11:55             ` Jason A. Donenfeld
2022-05-03 12:33               ` Lennart Poettering
2022-05-02 18:04         ` Jason A. Donenfeld
2022-05-02 18:34           ` Alexander Graf
2022-05-02 18:46             ` Jason A. Donenfeld
2022-05-02 18:56               ` Alexander Graf
2022-05-02 19:27                 ` Jason A. Donenfeld
2022-05-02 19:41                   ` Alexander Graf
2022-05-04 15:45             ` Michael Kelley (LINUX)
2022-05-02 18:44           ` Jason A. Donenfeld
2022-05-03  7:42           ` Lennart Poettering
2022-05-03  9:08             ` Jason A. Donenfeld
2022-05-03  9:32               ` Lennart Poettering
2022-05-03 10:07                 ` Jason A. Donenfeld
2022-05-03 12:42                   ` Lennart Poettering
2022-05-11  0:40   ` Simo Sorce
2022-05-11  1:18     ` Jason A. Donenfeld
2022-05-11 12:59       ` Simo Sorce
2022-05-11 13:19         ` Alexander Graf
2022-05-11 13:19         ` Jason A. Donenfeld
2022-05-11 14:32           ` Simo Sorce
2022-05-11 13:20       ` Alexander Graf
2022-05-02 15:30 ` [PATCH 1/2] sysctl: read() must consume poll events, not poll() Jason A. Donenfeld
2022-05-02 15:43   ` Lennart Poettering
2022-05-03 11:27     ` Jason A. Donenfeld
2022-05-12 17:40       ` Luis Chamberlain
2022-05-12 18:29         ` Eric W. Biederman
2022-05-12 18:32           ` Jason A. Donenfeld
2022-05-12 18:22 ` Lucas De Marchi
2022-05-12 18:27   ` Jason A. Donenfeld

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=f90d5e06-8cd7-14b3-43d5-c4799597d023@amazon.com \
    --to=graf@amazon.com \
    --cc=Jason@zx2c4.com \
    --cc=colmmacc@amazon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=htorben@amazon.co.uk \
    --cc=jannh@google.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=mzxreary@0pointer.de \
    --cc=tytso@mit.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).