Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6136034iog; Thu, 23 Jun 2022 12:06:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vzWgxunFWBvwYZd6N434XqxYFaZvMMx662G6ur+BD6Q0ZF69kP0C75H+TkqLoEEryWHhK9 X-Received: by 2002:a17:906:2245:b0:715:7c81:e39d with SMTP id 5-20020a170906224500b007157c81e39dmr9643119ejr.262.1656011163354; Thu, 23 Jun 2022 12:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011163; cv=none; d=google.com; s=arc-20160816; b=AI8uY1+bIIxI4wyVWbC68dkDfKWxDnI9o/L4yaVQLwtKaBF8RwAcTzle8abM+fOa98 VlDshxjrjxEyLUWTwz27+I3r//koWH1D5g3YfdDIrH8dr/JtKvzLmpplCA+bJyYEFXdr 7aiDx1r7/Ays3l+1w1ToMJ4+0z+YtSLPKMrx+jCQOxmLha9/HDJix6rNc8g7VXQDJVJJ HS+64CmWblAaI5CnLQ86lVs3exdmZtDZjRiZ2ovHMVsItE+ieZm6FSoO2uht+qgv/TTt SoF5UoqoZzKESutvBecgOhXDNeVmgpnUdmJZtAcD5X68V8XokNSyvrJh47ndmLUlQ41t Qa/g== 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=y934XJ2w4HVK0LFGVjBd8Gm+HI2WqKBh/KSdAilI9bE=; b=Y3d/YvIDRD9iMS0L+PpD8qhJxwrXdP8a9HGx+H2JKcwBI/JjMhsNU1or97cd8NDvRK kkoLH0bG+Oucui+LqkFBUJE9Fa22wnw/dS0YpmlXUWty7LX0v4BVDwKL79lItya4rLIN y4tLmkmrLf7vTorZc2IEQkwBKzoSoQ8oXisfgAnsVfUS+9R6HwVedFI0L1TxMgNpq8SR 2ZmHBWqqxK2wvcuQpbiIxBAAVTENn2bH/icQhglf3mv/Ur+f2Vazv34OZPbmeNhUaAmV 5iXRHJQcReo5BtW5AMVrLPURONS2D94Qw629EjjDkhKRIjjxxsqoY2H6isumfYoLaM58 kaxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=G+C2aDe7; 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 hv13-20020a17090760cd00b0071bbadaaf42si7501762ejc.425.2022.06.23.12.05.37; Thu, 23 Jun 2022 12:06:03 -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=G+C2aDe7; 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 S235275AbiFWRyl (ORCPT + 99 others); Thu, 23 Jun 2022 13:54:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235399AbiFWRwa (ORCPT ); Thu, 23 Jun 2022 13:52:30 -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 6EDAF443DB; Thu, 23 Jun 2022 10:13:04 -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 07B0661CD9; Thu, 23 Jun 2022 17:13:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE5EDC3411B; Thu, 23 Jun 2022 17:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004383; bh=X0jxhBZCxLRFvTy4ajXUWCmCOWKNyZfQNhAR4NMapk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G+C2aDe7MgjkJGPy+zDb35UeDHjenYmuQV9XzDqMKt4KOaPhwC3OU4HRdwqjKDig1 CiEG2PAnegDI6pk8RJNvhBnodxjCwWjdHgoV1+lrIkXYaZLucQ+8qhvwFVwRuz49VT MRxP20sQqUePkxyIGVIQfl2zo8XjkurHBVorjrQQ= 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.19 020/234] random: add GRND_INSECURE to return best-effort non-cryptographic bytes Date: Thu, 23 Jun 2022 18:41:27 +0200 Message-Id: <20220623164343.634372566@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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 @@ -2197,7 +2197,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) @@ -2206,7 +2213,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 @@ -49,8 +49,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 */