From patchwork Fri May 7 08:15:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1475388 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fc3Dt63nyz9sPf; Fri, 7 May 2021 18:16:14 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1leved-0000rO-3d; Fri, 07 May 2021 08:16:11 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1leveZ-0000pa-RN for kernel-team@lists.ubuntu.com; Fri, 07 May 2021 08:16:07 +0000 Received: from mail-ed1-f71.google.com ([209.85.208.71]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1leveZ-00048n-Js for kernel-team@lists.ubuntu.com; Fri, 07 May 2021 08:16:07 +0000 Received: by mail-ed1-f71.google.com with SMTP id s20-20020a0564025214b029038752a2d8f3so4062079edd.2 for ; Fri, 07 May 2021 01:16:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=evN6XmxhaSNnUH/xZqhBPyskOY2oOkvnbjNCGwe1B1Q=; b=r4tSga2kUddm+bWOLRDGORjxFNLt+NhVfY/SXDUOmMY0TAYv1NmeR0p4J9FU5nN41E qb+RWG04ORcKC0q/aIcJyWvJr0jjT4PirgSMAeNlK7la8MF5ev4n8Mc5uh40G+r9lC2J DCfIyu03OzvHnpY8wP7/dppbISMK7j+q/RCHF/UGGTyl7TfB0m3d+4EpESWOFNEpSFov XQLqmQUDznuNWD92oyKmnclYh4ht1DlvL223a310IhHA2Tp1BM+fPzcdiecQ8tvlKEHB BDKUYVm4vGg/WZGDt4f9/lH2IWnXvCKOgQDYpNMHp3ZrdQvl0ZopOOYyMTihrkiJIhr7 xQxQ== X-Gm-Message-State: AOAM533NP1Kk1LyrSUM2DGI/0cbXvUaEM1tHC4ABdtK/BSo6ygRmyNTA j7HD54DDqJiyW9Dtm3GN45hocMTXj25twTe1bFa6pL8+40efQR+98+BWMjQx6L2keB2mpzs3Tuh XVOIQ0A1jyuMETiWE6ZSjX2/e7pj4PP8H1ZLz8ZsVxQ== X-Received: by 2002:aa7:c4d0:: with SMTP id p16mr10221499edr.102.1620375367331; Fri, 07 May 2021 01:16:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXoAwQNvrkfI8S5rcdMFJ8u8LX1ZA54pLqvY+KcwN5PsYVQV8/r7MPFi+Xefiyj255rjLrLQ== X-Received: by 2002:aa7:c4d0:: with SMTP id p16mr10221479edr.102.1620375367133; Fri, 07 May 2021 01:16:07 -0700 (PDT) Received: from xps-13-7390.homenet.telecomitalia.it (host-79-19-135-103.retail.telecomitalia.it. [79.19.135.103]) by smtp.gmail.com with ESMTPSA id q25sm2977290ejd.9.2021.05.07.01.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 01:16:06 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU][F/aws][PATCH 3/5] random: Add a urandom_read_nowait() for random APIs that don't warn Date: Fri, 7 May 2021 10:15:45 +0200 Message-Id: <20210507081547.6945-4-andrea.righi@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210507081547.6945-1-andrea.righi@canonical.com> References: <20210507081547.6945-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Andy Lutomirski BugLink: https://bugs.launchpad.net/bugs/1927692 /dev/random and getrandom() never warn. Split the meat of urandom_read() into urandom_read_nowarn() and leave the warning code in urandom_read(). This has no effect on kernel behavior, but it makes subsequent patches more straightforward. It also makes the fact that getrandom() never warns more obvious. Signed-off-by: Andy Lutomirski Link: https://lore.kernel.org/r/c87ab200588de746431d9f916501ef11e5242b13.1577088521.git.luto@kernel.org Signed-off-by: Theodore Ts'o (cherry picked from commit c6f1deb158789abba02a7eba600747843eeb3a57) Signed-off-by: Andrea Righi --- drivers/char/random.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 3089aee11a7e..cfa87fcfe51b 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -2019,12 +2019,23 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) return _random_read(file->f_flags & O_NONBLOCK, buf, nbytes); } +static ssize_t +urandom_read_nowarn(struct file *file, char __user *buf, size_t nbytes, + loff_t *ppos) +{ + int ret; + + nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3)); + ret = extract_crng_user(buf, nbytes); + trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool)); + return ret; +} + static ssize_t urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) { unsigned long flags; static int maxwarn = 10; - int ret; if (!crng_ready() && maxwarn > 0) { maxwarn--; @@ -2036,10 +2047,8 @@ urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) crng_init_cnt = 0; spin_unlock_irqrestore(&primary_crng.lock, flags); } - nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3)); - ret = extract_crng_user(buf, nbytes); - trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool)); - return ret; + + return urandom_read_nowarn(file, buf, nbytes, ppos); } static __poll_t @@ -2206,7 +2215,7 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count, if (unlikely(ret)) return ret; } - return urandom_read(NULL, buf, count, NULL); + return urandom_read_nowarn(NULL, buf, count, NULL); } /********************************************************************