Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3668795rwb; Sun, 20 Nov 2022 19:31:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf5qgkbFwn0CY1bRAEbimFHG234WHCtTzvJhgnrW4qYQxzKI1jczUFL4rOtVjWuX8VClxnvW X-Received: by 2002:a17:902:7e88:b0:179:ee39:e300 with SMTP id z8-20020a1709027e8800b00179ee39e300mr10136562pla.58.1669001460225; Sun, 20 Nov 2022 19:31:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669001460; cv=none; d=google.com; s=arc-20160816; b=mn4Z7w5j/25L+GcHgyCseKPH6KmuJPbPxqZddGsBIDzWDmOiUnzWVAh8/nD6uXkq5l 9PyFqHHTnc1ZFhUZl8A4QOgme9XJSH3586pOFGqYHDvds2cBc6BZlz0TmsbdNXRW9d+l hBITFYGzZRmoknc9pjXJ5x5RoggAgWe8wdv3XuoWe785pnExSeARk5XL3xf+Bwlnv3X8 c/vj4fjYUKQfYtzZLppTmh1oOsjtt5v9IxZtSFpIInPYl50COy8bZJmp3sFOCT4b3VhC yETQX8VYUrKo4CL4Lcajgj4C/bZy15DDDjwPIShfRCi8fEf7Wc+ukCrnLi3ibEVfR3Ew PsIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iHEmdgq+IRGtyRkvMHcpeJyVrJYV+YY+BtviBpbtKkE=; b=Ly2wbQBhc86ICNQeH1UUFSguR9fEduwupTHXPsFB/EWSNvgm/2JIUX6ylEWJwCIna5 vxvoLyOsIi+YeP2KQY9pzNouumXkS8ydHDJYDEUSdVUfxv4rUXnvjSsplBuHR/bwm35U R/91TyjaySsYPU2ikQCK2Euhv0V1FuH5W8HikPEDhWte2+YN/a6IBfPtGox43lELzdRW ZAZi15mqNKEKZwQqEl4WaIZSMhOYOlyB6OidRAwhsu52RlVXY0Y+6q/Ab9bxjJr3rnK3 6EMYVDyMZoTWkk6uvX3dtMeZF7cY0tZ5knuWfNjpVbRY04i+DugZpXI1qzDQnoOLDp9g Nsbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=FGcmyMnA; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a056a00240100b005676e2c36b4si1880214pfh.47.2022.11.20.19.30.44; Sun, 20 Nov 2022 19:31:00 -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=@zx2c4.com header.s=20210105 header.b=FGcmyMnA; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229826AbiKUDX2 (ORCPT + 99 others); Sun, 20 Nov 2022 22:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbiKUDX1 (ORCPT ); Sun, 20 Nov 2022 22:23:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A7618B10; Sun, 20 Nov 2022 19:23:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5157A60E9F; Mon, 21 Nov 2022 03:23:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA7D0C433C1; Mon, 21 Nov 2022 03:23:24 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="FGcmyMnA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1669001003; 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=iHEmdgq+IRGtyRkvMHcpeJyVrJYV+YY+BtviBpbtKkE=; b=FGcmyMnAD11Sh+J4t9G3VpYMKj7qX+ijuot6gl1P6jUUjOl0wT6U3g43oAe6fszlrs6kBx CtJekQ6F9NjrzynOGtu7yfJ7JIVyT2tu+QbpXIMaZ/rrVuuMkaq1nlhrRFTgAHJp55Srgv RPRdrjHlUn754oDRoamnEDWZ5Wp6WSI= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 73f9b883 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 21 Nov 2022 03:23:22 +0000 (UTC) Date: Mon, 21 Nov 2022 04:23:20 +0100 From: "Jason A. Donenfeld" To: Eric Biggers Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-crypto@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Greg Kroah-Hartman , Adhemerval Zanella Netto , Carlos O'Donell Subject: Re: [PATCH v5 2/3] random: introduce generic vDSO getrandom() implementation Message-ID: References: <20221119120929.2963813-1-Jason@zx2c4.com> <20221119120929.2963813-3-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Sun, Nov 20, 2022 at 02:04:49AM +0100, Jason A. Donenfeld wrote: > On Sun, Nov 20, 2022 at 01:53:53AM +0100, Jason A. Donenfeld wrote: > > I'm not quite sure what the best approach here is. One idea would be to > > just note that libcs should wait until vgetrandom() has returned > > everywhere before forking, using its atfork functionality. > > To elaborate on this idea a bit, the way this looks is: > > rwlock_t l; > pid_t fork(void) > { > pid_t pid; > write_lock(&l); > pid = syscall_fork(); > write_unlock(&l); > return pid; > } > ssize_t getrandom(...) > { > ssize_t ret; > ... > if (!read_try_lock(&l)) > return syscall_getrandom(...); > ret = vdso_getrandom(...); > read_unlock(&l); > return ret; > } > > So maybe that doesn't seem that bad, especially considering libc already > has the kind of infrastructure in place to do that somewhat easily. > Maybe there's a priority locking thing to get right here -- the writer > should immediately starve out all future readers, so it's not unbound -- > but that seems par for the course. Fortunately none of this was necessary, and I've got things implemented without needing to resort to that, for v+1. Jason