From patchwork Mon Oct 24 11:29:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp400270wru; Mon, 24 Oct 2022 04:46:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43M97saeNWANGJ/QCGljA0hROl2D87vkjL629rb7Y95yWP0r0VgpA5SPKEkwdonjkp9MPK X-Received: by 2002:aa7:d059:0:b0:460:9021:73cd with SMTP id n25-20020aa7d059000000b00460902173cdmr21082979edo.55.1666612005202; Mon, 24 Oct 2022 04:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612005; cv=none; d=google.com; s=arc-20160816; b=cdtPGFCiY+V4PYkY0P1eBJ8T1XBxdspd0fUAsclTJTvXgcuI7sJqgNFrQWrGFu0D85 IwLo1gnPJtr83K3amMoZ6M6ZopeaINcQeZDui6DFkw6H9MGxfmhBovuie08Cj1izQs7+ QPn1cJzYCWUyFWzzX24mu8WNtQhIFoBkqBcpPKWj/pN+ozDp1/sk7nkEEoo+S3JiGD2o VkSu678KBX5a99wmb/oToZdjvIesGkq2oCOXr7IUdx7luni4BA1r3atkbTsMsqAbcmTv h6yYuawjfeBksdfBB98f3AnviC+4qQ7HiDedSZ9iRJZwxRYBD1XO+YA1f5eLfYNh8/GL vT+Q== 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=yMiOb9jNunZfD96zeq5v5+NzP82+WTx7P6OfM4AnUUA=; b=cLZlocvzowt+rWcvJ5h/ZsDmvSi2h+A4Nhnctb/veqnJ2VVRBMo3NbfG7EUs/ul9zw +1eEZcWjd8Bfy8DrRloy33mNC4Y3bAqeQkALKp8WwHk5vHk5DvO4bTEukN3NhWkwSHK7 dJzEpozuprz4MA0iYyLCGOGhEbvHjv/P3Gzv0LulVB63Dj0E2OvrA16DRr2nqjZ+78x+ aS8XhD04sVxFDJiuQae9TT4kT/++z4dvy474/EaEY/t2VllOqVRoLUm3tPzPstMtCRFv 0KLQKphDond+uP8J1feLqbLaJ7dSIorYGC2ltusOLqcjtBqsHKUwE74YmGplnoMShCdH CMGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ohjFe7wJ; 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 js10-20020a17090797ca00b0078e20d9c473si22603306ejc.764.2022.10.24.04.46.20; Mon, 24 Oct 2022 04:46:45 -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=ohjFe7wJ; 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 S231521AbiJXLpz (ORCPT + 99 others); Mon, 24 Oct 2022 07:45:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231668AbiJXLoO (ORCPT ); Mon, 24 Oct 2022 07:44:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29CBA73C1F; Mon, 24 Oct 2022 04:41:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id BF2D561281; Mon, 24 Oct 2022 11:39:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D21C4C43144; Mon, 24 Oct 2022 11:39:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611594; bh=pmOPmI+oMzt7p797XAEtSZK+rbfd/3Vbxj8UdGQP6Ek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ohjFe7wJsIa4OHcGfJetr0J3szMfO934pBpJHdoKdKRsCMX3KUOYGM2i7106j/54b nlKS18/x3p+tYn4vtXztiqvj3yC5CiE2KMgBosUQWulBlqm8levNMQ+g2SYqKgLcsl 0JDMFPjQXNzVUcddzRYv51RazcQPRhiSHbQGmWIw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guozihua , Zhongguohua , Al Viro , Theodore Tso , Andrew Lutomirski , "Jason A. Donenfeld" Subject: [PATCH 4.9 037/159] random: restore O_NONBLOCK support Date: Mon, 24 Oct 2022 13:29:51 +0200 Message-Id: <20221024112950.742291077@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747569350096950871?= X-GMAIL-MSGID: =?utf-8?q?1747569350096950871?= From: Jason A. Donenfeld 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 Reported-by: Zhongguohua Cc: Al Viro Cc: Theodore Ts'o Cc: Andrew Lutomirski Cc: stable@vger.kernel.org Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1295,6 +1295,10 @@ static ssize_t random_read_iter(struct k { int ret; + if (!crng_ready() && + (kiocb->ki_filp->f_flags & O_NONBLOCK)) + return -EAGAIN; + ret = wait_for_random_bytes(); if (ret != 0) return ret;