Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6438802rwb; Mon, 5 Dec 2022 12:21:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf77vdW6s1KXUuV4U73b/F7diLprobeo6HJavG/iAjCRA87/vzkQoAH4H/BkXuAScU3WoJiX X-Received: by 2002:a17:906:5156:b0:7c0:efb6:8744 with SMTP id jr22-20020a170906515600b007c0efb68744mr6104773ejc.267.1670271682639; Mon, 05 Dec 2022 12:21:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670271682; cv=none; d=google.com; s=arc-20160816; b=ZnkQ29Idqd3k5QJ591BMgsShVwoYjGbf5700ye/6umyT9lXEIgQYEHFhAA1OH9E3R9 ZgcaUdxqYnm6gIEICVwDNBd5f9+sQm4Kwd1OPL+vyQWjzP3Ai8FitRjPVSwqVvyi6VyX DXeVl0ms2w7vS4LMkl14CNliOhEDvFCLLA8oRCKe4YiUIgqQh2pb1SfUo9CSaYLesefN v0aelTePx3QnVYFf2isOXzInesnlKrZn9cc43cKA46A/hZ0kJuzyLdQ6BAI37ENyHHIK 0DsXkCiScpKy1iGc0TN917Hgg8l8XvNV8tyAyJZBsR/HJvJeGRcu90dhMVTsASETA5n1 dbFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=J5OTqoTXPXM33Uzjd4PZuIqIzOIq6qcNx83qgoRc9Nk=; b=b/nu6xzGLMIRakn9jznlhplJzgH48ZeZBD4x5QO4m2vs28YyqPJ7g6iwb6PAk0jEAc tXisHNsU8LtyTZvwnN++kMVPrlW9Ky8beg6mWjeQxRQKFZ//zz1fmSvsgpftTivarjyy +wF3/eOTl6mTfdiWXpWsEphFLCbFnrG1CWFv7gQ20A3al5ixglwuyAeF30ldmCOQhf/B f8mQ+DxwBpjLHnfTj8lBVH3wj4WsYMWw5zdM/Qmfe8cdvxOvoFAtaJ05LQJn3DHEj8O1 NOcZOd/DhLFOM5B0Z1hktWzueqxiA3Zi/yScZVrAuQa4QSkstFLwm3ZQQBeTgSe+8MnT EtuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O1J2H4jS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga22-20020a1709070c1600b007aeef4dd9f3si12851723ejc.305.2022.12.05.12.20.59; Mon, 05 Dec 2022 12:21:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=O1J2H4jS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbiLEUHO (ORCPT + 99 others); Mon, 5 Dec 2022 15:07:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbiLEUHM (ORCPT ); Mon, 5 Dec 2022 15:07:12 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51F1313DCD for ; Mon, 5 Dec 2022 12:06:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670270776; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=J5OTqoTXPXM33Uzjd4PZuIqIzOIq6qcNx83qgoRc9Nk=; b=O1J2H4jSUKpEACxc9T45Cv8RRaNTscB7jWsgRyP6zPgATLBcEg6vsld0Nv2Ojh5Yj23FrH 2TOQO05lN+nEhgqy9hNr0fQK89bZf+egx67g6AOOXr+V4lAd32V2O8ZIFPW+FW5hHPGSd7 5y21npCahoaH8QJvLyNPVD+Qme99JAA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-v7mHkac9NfG-LNeQV8n2hg-1; Mon, 05 Dec 2022 15:06:13 -0500 X-MC-Unique: v7mHkac9NfG-LNeQV8n2hg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DEAF23810784; Mon, 5 Dec 2022 20:06:12 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93A6D112132D; Mon, 5 Dec 2022 20:06:10 +0000 (UTC) From: Florian Weimer To: "Jason A. Donenfeld" Cc: Jann Horn , 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 , Adhemerval Zanella Netto , Carlos O'Donell , Arnd Bergmann , Christian Brauner Subject: Re: [PATCH v11 1/4] random: add vgetrandom_alloc() syscall References: <20221205020046.1876356-1-Jason@zx2c4.com> <20221205020046.1876356-2-Jason@zx2c4.com> Date: Mon, 05 Dec 2022 21:06:06 +0100 In-Reply-To: (Jason A. Donenfeld's message of "Mon, 5 Dec 2022 21:02:34 +0100") Message-ID: <87bkohpqdt.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org * 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 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