Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6131614iog; Thu, 23 Jun 2022 12:01:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1stFtOWLePzeyJADKXkwuCIt0Kmr1t7ibMJ1Hn11YQJfitBeW0rksAOaM78ez8rcUt9hs7n X-Received: by 2002:a05:6a00:1a8f:b0:51c:2f82:cdba with SMTP id e15-20020a056a001a8f00b0051c2f82cdbamr42636572pfv.85.1656010894772; Thu, 23 Jun 2022 12:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656010894; cv=none; d=google.com; s=arc-20160816; b=EzwFm6QiAKiSMrKdpzX56LU5RoDyKfjt06yxNySDmV0qkgpx9IcWcZGPwd8oAooaZF 279bU8kMWOipzG/7VuCy7UyeeQQTUeePs+IzlRBIyZsLqAaS7hA8EPq9meb+bwZUTF8x DAt7W46D9n24QaYsUjBIpEEMX+mDGqLno1v/JUBMHpL8o8cTUIaL13X8P2X8nTK4uOWq cnItCVKt1RCyzymbuXgN49vLGPWcwTh9GSAsLzu6/fcU41Kfom3VFaSliwZ3nKmkCAda AaLNucxIlybEkFfoBGaANZrommpxUnA8BK7RzlN0hAH/Q8lVbGNPxxqe83nHzCioOQff LZMQ== 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=r3vwNwjlTOXkQXfIOkJ0eMhr//VTuj+dyN3221heVdA=; b=w+d0rrhJnchk+IP6RPp4uwD72LGk1FZNOadwPQOIDLVpr+Aa6HOUGbEGwldB1J9qCK oVP4dDEKKGQ6hn6XTGn8TI+VmgkaWkq2vsQ9wKORs6WOpazfEYiz/NVRdNjlgqIsj3yJ ZhrkElRqBjs7Ij4hts0QybiH8kKDomBeBg2yA0J1LH3/FCwD0pf8L/Iq0esnlwuJA1AP 8GsdrG0iHKyIDIKYDuDZGik0KB+Q122DWJXZrKpq97HSTj+WzrarLEIbE9QrpfHc97yG ZPrVDsEqJiJbSXA7+x9o25Fc3cfwVPfSas0PnYXlEINItUEnRDj49EN5KiIl0kfiRfY4 Lk2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y9UnxRQP; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020a170902dac700b001624625418dsi308283plx.597.2022.06.23.12.01.22; Thu, 23 Jun 2022 12:01:34 -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=Y9UnxRQP; 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 S232850AbiFWRA0 (ORCPT + 99 others); Thu, 23 Jun 2022 13:00:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232803AbiFWQt6 (ORCPT ); Thu, 23 Jun 2022 12:49:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91FB865D7; Thu, 23 Jun 2022 09:47:55 -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 5657861FA7; Thu, 23 Jun 2022 16:47:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 274A9C341C6; Thu, 23 Jun 2022 16:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656002873; bh=on1mcXpHvtEEBiQUkCQcIaAraZzLUj878rAwYC0ELY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y9UnxRQPzKjEa0vbc5e0fMKc8+fFcoMtjsPV30mvHuSii0dhy93YSma2SX4wo23FY N6KAK1Dv1d8UVW10Qhy++EAWaq1mrzE9EXD/DRc8XEpRpuHEmZg+6lCGYVvkBiQ8KI 2PyQnZhmn48EXVKnLoCci07qaXvW8sdUxWKJmWAg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Theodore Tso , "Jason A. Donenfeld" Subject: [PATCH 4.9 055/264] random: add GRND_INSECURE to return best-effort non-cryptographic bytes Date: Thu, 23 Jun 2022 18:40:48 +0200 Message-Id: <20220623164345.629744497@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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,T_SCC_BODY_TEXT_LINE 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 From: Andy Lutomirski commit 75551dbf112c992bc6c99a972990b3f272247e23 upstream. Signed-off-by: Andy Lutomirski Link: https://lore.kernel.org/r/d5473b56cf1fa900ca4bd2b3fc1e5b8874399919.1577088521.git.luto@kernel.org Signed-off-by: Theodore Ts'o Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 11 +++++++++-- include/uapi/linux/random.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -2187,7 +2187,14 @@ SYSCALL_DEFINE3(getrandom, char __user * { int ret; - if (flags & ~(GRND_NONBLOCK|GRND_RANDOM)) + if (flags & ~(GRND_NONBLOCK|GRND_RANDOM|GRND_INSECURE)) + return -EINVAL; + + /* + * Requesting insecure and blocking randomness at the same time makes + * no sense. + */ + if ((flags & (GRND_INSECURE|GRND_RANDOM)) == (GRND_INSECURE|GRND_RANDOM)) return -EINVAL; if (count > INT_MAX) @@ -2196,7 +2203,7 @@ SYSCALL_DEFINE3(getrandom, char __user * if (flags & GRND_RANDOM) return _random_read(flags & GRND_NONBLOCK, buf, count); - if (!crng_ready()) { + if (!(flags & GRND_INSECURE) && !crng_ready()) { if (flags & GRND_NONBLOCK) return -EAGAIN; ret = wait_for_random_bytes(); --- a/include/uapi/linux/random.h +++ b/include/uapi/linux/random.h @@ -48,8 +48,10 @@ struct rand_pool_info { * * GRND_NONBLOCK Don't block and return EAGAIN instead * GRND_RANDOM Use the /dev/random pool instead of /dev/urandom + * GRND_INSECURE Return non-cryptographic random bytes */ #define GRND_NONBLOCK 0x0001 #define GRND_RANDOM 0x0002 +#define GRND_INSECURE 0x0004 #endif /* _UAPI_LINUX_RANDOM_H */