Message ID | 20221013175143.753815853@linuxfoundation.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp417844wrs; Thu, 13 Oct 2022 11:24:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6SEWB08wc0Z7TH16bBTX+dWB4ic6IJgso5Y8xEmNP2WKgOGd7ROIrdktfxj5etXJf3qn9V X-Received: by 2002:a17:90b:110c:b0:205:cfeb:cfb with SMTP id gi12-20020a17090b110c00b00205cfeb0cfbmr1185258pjb.75.1665685462527; Thu, 13 Oct 2022 11:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665685462; cv=none; d=google.com; s=arc-20160816; b=eoJtMd9Ou0W5MSWftmfJrAHolOANlH2H/LeDrZ39en7z5GnXQJasVN84EuZQVhZkqH jFnWVErmHKj1g4Ilqkpd1ZXQ6/qXci6Fzp7K0ZyRH1OKvSKeTw6xbU6Grm81FiAiY/MV b9bSmROnNVlmYKAHeV/DgnP82yDGIhUlusavbmwjcXgLr+TJqaKGoZNcuTmFbeL2xb9y cFdi+SIoN3L1OP3uzj51wrYCCNLMGxokOq4xBzH5qUc3MS3bVYQ20px/gGHMIrGhEdHP PrKJnWWb0HajxOm0cjPLsl3bCGl3Vmg6JpbcLxnx6P3u3/BcEMMkMPKObwLlOv9YPiOS BJwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QCCP4Ow6nByYUD6+A0Ve+foJp3blDAILnckBc6Uq/uU=; b=KEytziOoUBnUQMxvwBd8wUdiMjnrO8hCPiTamrrVM+TlRZfK0NTUyStqFBiPOGxWmj cO0ZzwdfIu8lIZYLPOU83kJaac3/Yxf7YzNCzWO/6CeX3WzAjHR8O6RkhHdSr5c+nTjh yXRu2FyMY2GmVmOsT8RxDDccq6+91lWx+v55kVwNIGMzsMjGZXKFvAFfFoPoxkpSEpMG Z1Xzf06QLQW5FnwwcYSM7j5cR/SSDYzizWEJvr6roGeUVSCj4pJSBtt4QZgyXLRNeS29 LEa77dDW5+Go8XjgsTc2FPK7A4q+hY4YdG6EiB8qGi/riPVg1caB3m/011yONlVOv80b llIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=O4DlYXgo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t14-20020a63954e000000b0046ae2a8ea9csi43219pgn.733.2022.10.13.11.24.05; Thu, 13 Oct 2022 11:24:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=O4DlYXgo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbiJMST3 (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Thu, 13 Oct 2022 14:19:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiJMSST (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Oct 2022 14:18:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6928116C221; Thu, 13 Oct 2022 11:13:59 -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 B98B4B8204E; Thu, 13 Oct 2022 17:58:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 132D5C433D6; Thu, 13 Oct 2022 17:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683916; bh=LXvBMZgQGW5rg2p6e0YwUu2ffKqKQwDfqB6k048ZkgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4DlYXgoF4nGpiwBTbKJ0JGmy46s3yDEVNZ7r8cRvd81eAnvjmAN19q5k2/oMhw8B qNxv9xH4zb1LMFayxgHkmYGfX9jKqy6w4ApVqrz3M3t4WtB4K0bU43weqLKwKjnQms iRIZmjqpPd9v11yy9nQUU62ntXC+PVuBwcVLDqsQ= From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, stable@vger.kernel.org, Guozihua <guozihua@huawei.com>, Zhongguohua <zhongguohua1@huawei.com>, Al Viro <viro@zeniv.linux.org.uk>, Theodore Tso <tytso@mit.edu>, Andrew Lutomirski <luto@kernel.org>, "Jason A. Donenfeld" <Jason@zx2c4.com> Subject: [PATCH 5.15 06/27] random: restore O_NONBLOCK support Date: Thu, 13 Oct 2022 19:52:35 +0200 Message-Id: <20221013175143.753815853@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175143.518476113@linuxfoundation.org> References: <20221013175143.518476113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746597799244198878?= X-GMAIL-MSGID: =?utf-8?q?1746597799244198878?= |
Series |
None
|
|
Commit Message
Greg KH
Oct. 13, 2022, 5:52 p.m. UTC
From: Jason A. Donenfeld <Jason@zx2c4.com> commit cd4f24ae9404fd31fc461066e57889be3b68641b upstream. Prior to 5.6, when /dev/random was opened with O_NONBLOCK, it would return -EAGAIN if there was no entropy. When the pools were unified in 5.6, this was lost. The post 5.6 behavior of blocking until the pool is initialized, and ignoring O_NONBLOCK in the process, went unnoticed, with no reports about the regression received for two and a half years. However, eventually this indeed did break somebody's userspace. So we restore the old behavior, by returning -EAGAIN if the pool is not initialized. Unlike the old /dev/random, this can only occur during early boot, after which it never blocks again. In order to make this O_NONBLOCK behavior consistent with other expectations, also respect users reading with preadv2(RWF_NOWAIT) and similar. Fixes: 30c08efec888 ("random: make /dev/random be almost like /dev/urandom") Reported-by: Guozihua <guozihua@huawei.com> Reported-by: Zhongguohua <zhongguohua1@huawei.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Theodore Ts'o <tytso@mit.edu> Cc: Andrew Lutomirski <luto@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> --- drivers/char/mem.c | 4 ++-- drivers/char/random.c | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-)
--- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -702,8 +702,8 @@ static const struct memdev { #endif [5] = { "zero", 0666, &zero_fops, 0 }, [7] = { "full", 0666, &full_fops, 0 }, - [8] = { "random", 0666, &random_fops, 0 }, - [9] = { "urandom", 0666, &urandom_fops, 0 }, + [8] = { "random", 0666, &random_fops, FMODE_NOWAIT }, + [9] = { "urandom", 0666, &urandom_fops, FMODE_NOWAIT }, #ifdef CONFIG_PRINTK [11] = { "kmsg", 0644, &kmsg_fops, 0 }, #endif --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1298,6 +1298,11 @@ static ssize_t random_read_iter(struct k { int ret; + if (!crng_ready() && + ((kiocb->ki_flags & (IOCB_NOWAIT | IOCB_NOIO)) || + (kiocb->ki_filp->f_flags & O_NONBLOCK))) + return -EAGAIN; + ret = wait_for_random_bytes(); if (ret != 0) return ret;