Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4041055imw; Mon, 18 Jul 2022 20:49:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tRu2p8rDSBYb0AzTulx0v4xosVs8eFyxmhCI4r5VVSk2HuDDCJrtUEsrhMalWlz6m7USMh X-Received: by 2002:a17:906:8443:b0:72b:67a6:a42f with SMTP id e3-20020a170906844300b0072b67a6a42fmr28639260ejy.309.1658202545007; Mon, 18 Jul 2022 20:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658202545; cv=none; d=google.com; s=arc-20160816; b=IHG1OH2W9LB7SfRCQ10e5pPIgswIiekRSbqeU+sckYWLGzu6X61gjzT1kiLNKQmDw3 gn6+ctuCLpb0Owayqu19chudpMf47ZWfoZzVZIcIVVhxlTUMvF13n1Py5qUMVA9Jfux4 ker5FlFb5jvY0lGs2pY6FsBrFzkWjg/z6HFUSWtv4++KSmaCuwb3soCyXOkESlnC0AwK e6s3maQzuKBHYZud1XP0/jv7o2n7YlXaJjMbn13uO2MvzBDNeh3t2XlurwgTHaMIDQwW Jhtn87RXkJKYo5LPWkWEecILJsE1few77Y6CAkG25Ty9s2SmH/wxMfIF+WD6RZTnHzc2 URcg== 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=qYvSAkqdLhG4sGd086gkiMIMGXGKJ2QzNRJxyr8EtPw=; b=VWwxro9SRo/pbymNcfL43Qrdn3ivZw/7+oEOYwU71ysbHGUVq6d0X2i3DMWoBYbkfq nmM3y+3C98A+jP2TJhUyruufBYstsw1+bOdgrdAVIrZzHWUVqsOoqtYbeVyyQb2P6zhi PVs/qjFh70t/1Yg68PYieGy0mXpGa6eYvR+tShcZMaF21B5TKVQGx8GxDAVJYi64EICd Q9wGvY5pTjW9ghyxXpYrd72BDxU2FdCibBMyxhU8Vy4WTeaN7OmURRSL5qz19HfVKLCD sQY2JCd0Tdwi38wydRx/8l5ipvq7Qbjb47Z9c2l9GG/Ns7CJGhVpHC9cRnnLxi9GSSQ6 x4pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qI75aTHd; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a17090668cf00b0072ad602a2d0si1275684ejr.160.2022.07.18.20.48.40; Mon, 18 Jul 2022 20:49:04 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=qI75aTHd; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234238AbiGSDrX (ORCPT + 99 others); Mon, 18 Jul 2022 23:47:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbiGSDrV (ORCPT ); Mon, 18 Jul 2022 23:47:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFEE72018B for ; Mon, 18 Jul 2022 20:47:19 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 96A81B81914 for ; Tue, 19 Jul 2022 03:47:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18F8BC341C6; Tue, 19 Jul 2022 03:47:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658202437; bh=PtC6fKUZkG8pT1plPerVVE8siIjEm+Hq7rwa9yLpj1o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qI75aTHduhSaksc2YIWEZFHJe8HDOdI+0zo+zXYWW5kWzLkJIyvsCMDNjutvSDmaY +GGZykhFTvHYdxpW7PvMRGEmgWoIlZUKKSbYVTnrXJ6yTGGD17dDT3IGYVBASN9RBp RfUi6ctnChSCODKx0hP9o4/JrHTq2sFxM4Do7L1KBmaXv67VnZqvTk1SpCqT0KcZjd JP+yxx6A8uasjEuTGerUXOQEpFOliJ3H3hdr1hAQa5nsX6EkjTZ+MkZnVQf6XbdjSd CDwJ0KvMVNDx373yIHkORnQ5rn84wu9pGzGDRFLeBwwwevGXfmeC5RnVsi5Tc2Yr81 4baH2uTSu10fg== Date: Mon, 18 Jul 2022 20:47:15 -0700 From: Eric Biggers To: "Guozihua (Scott)" Cc: linux-crypto@vger.kernel.org, luto@kernel.org, tytso@mit.edu, "Jason A. Donenfeld" Subject: Re: Inquiry about the removal of flag O_NONBLOCK on /dev/random Message-ID: References: <13e1fa9d-4df8-1a99-ca22-d9d655f2d023@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Mon, Jul 18, 2022 at 04:52:59PM +0800, Guozihua (Scott) wrote: > On 2022/7/14 15:33, Guozihua (Scott) wrote: > > Hi Community, > > > > Recently we noticed the removal of flag O_NONBLOCK on /dev/random by > > commit 30c08efec888 ("random: make /dev/random be almost like > > /dev/urandom"), it seems that some of the open_source packages e.g. > > random_get_fd() of util-linux and __getrandom() of glibc. The man page > > for random() is not updated either. > > Correction: I mean various open source packages are still using O_NONBLOCK > flag while accessing /dev/random > > > > Would anyone please kindly provide some background knowledge of this > > flag and it's removal? Thanks! > > This was changed a while ago, in v5.6. /dev/random no longer recognizes O_NONBLOCK because it no longer blocks, except before the entropy pool has been initialized. (I don't know why O_NONBLOCK stopped being recognized *before* the entropy pool has been initialized; it's either an oversight, or it was decided it doesn't matter. Probably the latter, since I can't think of a real use case for using O_NONBLOCK on /dev/random.) The random(4) man page is indeed in need of an update, not just for this reason but for some other reasons too. The util-linux code which you mentioned is opening /dev/random with O_NONBLOCK if opening /dev/urandom fails, which is pretty much pointless. Perhaps the author thought that /dev/random with O_NONBLOCK is equivalent to /dev/urandom (it's not). The glibc code, if you mean sysdeps/mach/hurd/getrandom.c, is actually code written for GNU Hurd, not for Linux, so it's not relevant. - Eric