linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Jann Horn <jannh@google.com>,
	linux-kernel@vger.kernel.org, patches@lists.linux.dev,
	tglx@linutronix.de, linux-crypto@vger.kernel.org,
	linux-api@vger.kernel.org, x86@kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	Carlos O'Donell <carlos@redhat.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Christian Brauner <brauner@kernel.org>
Subject: Re: [PATCH v11 1/4] random: add vgetrandom_alloc() syscall
Date: Mon, 05 Dec 2022 21:06:06 +0100	[thread overview]
Message-ID: <87bkohpqdt.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <Y45OWhyN+U975vIN@zx2c4.com> (Jason A. Donenfeld's message of "Mon, 5 Dec 2022 21:02:34 +0100")

* Jason A. Donenfeld:

> Hi Jann,
>
> On Mon, Dec 05, 2022 at 08:13:36PM +0100, Jann Horn wrote:
>> On Mon, Dec 5, 2022 at 3:01 AM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>> > +       mm->def_flags |=
>> > +               /*
>> > +                * Don't allow state to be written to swap, to preserve forward secrecy.
>> > +                * This works in conjunction with MAP_LOCKED in do_mmap(), below, which
>> > +                * actually does the locking (and associated permission check and accounting).
>> > +                * Here, VM_LOCKONFAULT together with VM_NORESERVE simply make the mlocking
>> > +                * happen the first time it's actually used, the same as when calling
>> > +                * mlock2(MLOCK_ONFAULT) from userspace.
>> > +                */
>> > +               VM_LOCKONFAULT | VM_NORESERVE |
>> 
>> Have you checked the interaction with this line in dup_mmap()?
>> "tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);"
>> 
>> As the mlock.2 manpage says, "Memory locks are not inherited by a
>> child created via fork(2)". I think the intention here is that the VMA
>> should stay unswappable after fork(), right?
>> 
>> Of course, trying to reserve more mlocked memory in fork() would also
>> be problematic...
>
> Thanks for pointing that out! Indeed that seems problematic.
> Fortunately, the use of WIPEONFORK at the same time as LOCKONFAULT means
> that memory doesn't actually need to be reserved in fork() itself. So
> something like the below seems correct and doable.
>
> Jason
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index ec57cae58ff1..cd53ffff615d 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -656,7 +656,9 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
>  			tmp->anon_vma = NULL;
>  		} else if (anon_vma_fork(tmp, mpnt))
>  			goto fail_nomem_anon_vma_fork;
> -		tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
> +		if ((tmp->vm_flags & (VM_LOCKONFAULT | VM_WIPEONFORK)) !=
> +		    (VM_LOCKONFAULT | VM_WIPEONFORK))
> +			tmp->vm_flags &= ~(VM_LOCKED | VM_LOCKONFAULT);
>  		file = tmp->vm_file;
>  		if (file) {
>  			struct address_space *mapping = file->f_mapping;

Still it's a bit concerning that calling getrandom (the libc function)
now apparently can kill the process if the system is under severe memory
pressure.  In many cases, that's okay, but we wouldn't want that for
PID 1, for example.  vm.overcommit_memory=2 mode is supposed to prevent
such crashes, and I think NORESERVE (not shown here) sidesteps that.

Thanks,
Florian


  reply	other threads:[~2022-12-05 20:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05  2:00 [PATCH v11 0/4] implement getrandom() in vDSO Jason A. Donenfeld
2022-12-05  2:00 ` [PATCH v11 1/4] random: add vgetrandom_alloc() syscall Jason A. Donenfeld
2022-12-05 18:34   ` Florian Weimer
2022-12-05 18:38     ` Jason A. Donenfeld
2022-12-05 19:13   ` Jann Horn
2022-12-05 20:02     ` Jason A. Donenfeld
2022-12-05 20:06       ` Florian Weimer [this message]
2022-12-06 12:57         ` Jason A. Donenfeld
2022-12-05  2:00 ` [PATCH v11 2/4] arch: allocate vgetrandom_alloc() syscall number Jason A. Donenfeld
2022-12-05  2:00 ` [PATCH v11 3/4] random: introduce generic vDSO getrandom() implementation Jason A. Donenfeld
2022-12-05 18:56   ` Florian Weimer
2022-12-05 19:04     ` Jason A. Donenfeld
2022-12-05 19:35       ` Florian Weimer
2022-12-05  2:00 ` [PATCH v11 4/4] x86: vdso: Wire up getrandom() vDSO implementation 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=87bkohpqdt.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=Jason@zx2c4.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=arnd@arndb.de \
    --cc=brauner@kernel.org \
    --cc=carlos@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jannh@google.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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).