From patchwork Sat Jun 3 02:32:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 9763767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1EBE160360 for ; Sat, 3 Jun 2017 02:32:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D0D528485 for ; Sat, 3 Jun 2017 02:32:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01E16284FF; Sat, 3 Jun 2017 02:32:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 332B028485 for ; Sat, 3 Jun 2017 02:32:39 +0000 (UTC) Received: (qmail 21997 invoked by uid 550); 3 Jun 2017 02:32:38 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 20322 invoked from network); 3 Jun 2017 02:32:31 -0000 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=5gmt KPCLbmYjY/X3rfHEzeu7uBQ=; b=IWFJL00oejY8JpGTGFkw90dIe3Sjl2cSiY5p aHsbutZRGSPowDYeEpsB0F8DrEeqUPGVtmVQn4PNAppBf3ExW3M1llAZyK/2W9h8 qPPr0dtHuJm8n6vGctiVlWwQCDfVXwPzO8YPQx3Ti4wCFJSZX2je+QoK0/Q3PwHU +xPtE0SAxeiwaIuyIusMGi6w7ot7TMVLtYUY5kYDThSoHrMANgRicjae6ntn+o/6 eHkCWbjwKgyjs4qQFvXWcd2T855CVGZh3o1l8Y+EXEHtbHvMn7QhhFY0YtGnd2NF SSzBQFb71Bv4P+lJpIwSS/CD2+WQUyyhf1u5qKUeeFifCnd02Q== From: "Jason A. Donenfeld" To: Theodore Ts'o , Linux Crypto Mailing List , LKML , kernel-hardening@lists.openwall.com Cc: "Jason A. Donenfeld" Date: Sat, 3 Jun 2017 04:32:03 +0200 Message-Id: <20170603023204.30933-3-Jason@zx2c4.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170603023204.30933-1-Jason@zx2c4.com> References: <20170603023204.30933-1-Jason@zx2c4.com> Subject: [kernel-hardening] [PATCH RFC 2/3] random: add get_random_{bytes, u32, u64, int, long}_wait family X-Virus-Scanned: ClamAV using ClamSMTP These functions are simple convience wrappers that call wait_for_random_bytes before calling the respective get_random_* function. Signed-off-by: Jason A. Donenfeld --- include/linux/random.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/linux/random.h b/include/linux/random.h index 20dd73418bd5..6a19da815ff1 100644 --- a/include/linux/random.h +++ b/include/linux/random.h @@ -58,6 +58,36 @@ static inline unsigned long get_random_long(void) #endif } +/* Calls wait_for_random_bytes(is_interruptable, timeout) and then + * calls get_random_bytes(buf, nbytes). Returns the result of the + * call to wait_for_random_bytes. + */ +static inline int get_random_bytes_wait(void *buf, int nbytes, + bool is_interruptable, unsigned long timeout) +{ + int ret = wait_for_random_bytes(is_interruptable, timeout); + if (unlikely(ret)) + return ret; + get_random_bytes(buf, nbytes); + return 0; +} + +#define declare_get_random_var_wait(var) \ + static inline int get_random_ ## var ## _wait(var *out, \ + bool is_interruptable, unsigned long timeout) { \ + int ret = wait_for_random_bytes(is_interruptable, timeout); \ + if (unlikely(ret)) \ + return ret; \ + *out = get_random_ ## var(); \ + return 0; \ + } +declare_get_random_var_wait(u32) +declare_get_random_var_wait(u64) +declare_get_random_var_wait(int) +declare_get_random_var_wait(long) +#undef declare_get_random_var + + unsigned long randomize_page(unsigned long start, unsigned long range); u32 prandom_u32(void);