DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: dev@dpdk.org, stephen@networkplumber.org,
	david.marchand@redhat.com, bruce.richardson@intel.com
Subject: Re: [dpdk-dev] [PATCH 1/6] eal: replace libc-based random number generation with LFSR
Date: Tue, 14 May 2019 16:53:08 +0200	[thread overview]
Message-ID: <8522b2d7-8361-3e34-7750-88b66d61b98a@ericsson.com> (raw)
In-Reply-To: <20190514141615.GA12163@hmswarspite.think-freely.org>

On 2019-05-14 16:16, Neil Horman wrote:
> On Tue, May 14, 2019 at 11:20:41AM +0200, Mattias Rönnblom wrote:
>> This commit replaces rte_rand()'s use of lrand48() with a DPDK-native
>> combined Linear Feedback Shift Register (LFSR) (also known as
>> Tausworthe) pseudo-random number generator.
>>
>> This generator is faster and produces better-quality random numbers
>> than the linear congruential generator (LCG) of lib's lrand48(). The
>> implementation, as opposed to lrand48(), is multi-thread safe in
>> regards to concurrent rte_rand() calls from different lcore threads.
>> A LCG is still used, but only to seed the five per-lcore LFSR
>> sequences.
>>
>> In addition, this patch also addresses the issue of the legacy
>> implementation only producing 62 bits of pseudo randomness, while the
>> API requires all 64 bits to be random.
>>
>> This pseudo-random number generator is not cryptographically secure -
>> just like lrand48().
>>
>> Bugzilla ID: 114
>> Bugzilla ID: 276
>>
>> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
>> ---
>>   lib/librte_eal/common/include/rte_random.h |  29 ++---
>>   lib/librte_eal/common/meson.build          |   1 +
>>   lib/librte_eal/common/rte_random.c         | 139 +++++++++++++++++++++
>>   lib/librte_eal/freebsd/eal/Makefile        |   1 +
>>   lib/librte_eal/freebsd/eal/eal.c           |   2 -
>>   lib/librte_eal/linux/eal/Makefile          |   1 +
>>   lib/librte_eal/linux/eal/eal.c             |   2 -
>>   lib/librte_eal/rte_eal_version.map         |   8 ++
>>   8 files changed, 161 insertions(+), 22 deletions(-)
>>   create mode 100644 lib/librte_eal/common/rte_random.c
>>
>> diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h
>> index b2ca1c209..66dfe8ae7 100644
>> --- a/lib/librte_eal/common/include/rte_random.h
>> +++ b/lib/librte_eal/common/include/rte_random.h
>> @@ -16,7 +16,6 @@ extern "C" {
>>   #endif
>>
>>   #include <stdint.h>
>> -#include <stdlib.h>
>>
>>   /**
>>    * Seed the pseudo-random generator.
>> @@ -25,34 +24,28 @@ extern "C" {
>>    * value. It may need to be re-seeded by the user with a real random
>>    * value.
>>    *
>> + * This function is not multi-thread safe in regards to other
>> + * rte_srand() calls, nor is it in relation to concurrent rte_rand()
>> + * calls.
>> + *
>>    * @param seedval
>>    *   The value of the seed.
>>    */
>> -static inline void
>> -rte_srand(uint64_t seedval)
>> -{
>> -	srand48((long)seedval);
>> -}
>> +void
>> +rte_srand(uint64_t seedval);
>>
>>   /**
>>    * Get a pseudo-random value.
>>    *
>> - * This function generates pseudo-random numbers using the linear
>> - * congruential algorithm and 48-bit integer arithmetic, called twice
>> - * to generate a 64-bit value.
>> + * The generator is not cryptographically secure.
>> + *
>> + * If called from lcore threads, this function is thread-safe.
>>    *
>>    * @return
>>    *   A pseudo-random value between 0 and (1<<64)-1.
>>    */
>> -static inline uint64_t
>> -rte_rand(void)
>> -{
>> -	uint64_t val;
>> -	val = (uint64_t)lrand48();
>> -	val <<= 32;
>> -	val += (uint64_t)lrand48();
>> -	return val;
>> -}
>> +uint64_t
>> +rte_rand(void);
>>
>>   #ifdef __cplusplus
>>   }
>> diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build
>> index 0670e4102..bafd23207 100644
>> --- a/lib/librte_eal/common/meson.build
>> +++ b/lib/librte_eal/common/meson.build
>> @@ -35,6 +35,7 @@ common_sources = files(
>>   	'rte_keepalive.c',
>>   	'rte_malloc.c',
>>   	'rte_option.c',
>> +	'rte_random.c',
>>   	'rte_reciprocal.c',
>>   	'rte_service.c'
>>   )
>> diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c
>> new file mode 100644
>> index 000000000..4d3cf5226
>> --- /dev/null
>> +++ b/lib/librte_eal/common/rte_random.c
>> @@ -0,0 +1,139 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright(c) 2019 Ericsson AB
>> + */
>> +
>> +#include <stdlib.h>
>> +
>> +#include <rte_branch_prediction.h>
>> +#include <rte_cycles.h>
>> +#include <rte_eal.h>
>> +#include <rte_lcore.h>
>> +#include <rte_memory.h>
>> +#include <rte_random.h>
>> +
>> +struct rte_rand_state {
>> +	uint64_t z1;
>> +	uint64_t z2;
>> +	uint64_t z3;
>> +	uint64_t z4;
>> +	uint64_t z5;
>> +} __rte_cache_aligned;
>> +
>> +static struct rte_rand_state rand_states[RTE_MAX_LCORE];
>> +
> 
> It just occured to me that this variable embodies all the state of the rng.
> Whats to stop an attacker from digging through ram to get this info and
> predicting what the output will be?  I understand that this rng probably
> shouldn't be considered secure for cryptographic use, but it is used in the
> ipsec test example, so it could be mistaken for an rng that is.
> 

rte_rand() was never safe for use in cryptography, and now it's spelled 
out in the API documentation.

If the IPsec example uses rte_rand() for anything security-related, it's 
a bug or at least should be accompanied by a comment, in my opinion.

That said, if you have an attacker who's already broken into your DPDK 
process' virtual memory, I'm not sure I understand why he would care 
much about the state of the PRNG. Wouldn't he just read your private 
keys, your messages in clear text or whatever other secrets you might 
have in memory?

  parent reply	other threads:[~2019-05-14 14:53 UTC|newest]

Thread overview: 137+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-05 13:45 [dpdk-dev] [RFC] eal: make rte_rand() MT safe Mattias Rönnblom
2019-04-05 13:45 ` Mattias Rönnblom
2019-04-05 13:51 ` Mattias Rönnblom
2019-04-05 13:51   ` Mattias Rönnblom
2019-04-05 14:28   ` Bruce Richardson
2019-04-05 14:28     ` Bruce Richardson
2019-04-05 14:56     ` Mattias Rönnblom
2019-04-05 14:56       ` Mattias Rönnblom
2019-04-05 16:57 ` Stephen Hemminger
2019-04-05 16:57   ` Stephen Hemminger
2019-04-05 18:04   ` Mattias Rönnblom
2019-04-05 18:04     ` Mattias Rönnblom
2019-04-05 20:50     ` Stephen Hemminger
2019-04-05 20:50       ` Stephen Hemminger
2019-04-06  5:52       ` Mattias Rönnblom
2019-04-06  5:52         ` Mattias Rönnblom
2019-04-08 12:30       ` [dpdk-dev] [RFC 1/3] Replace lrand48-based rte_rand with LFSR generator Mattias Rönnblom
2019-04-08 12:30         ` Mattias Rönnblom
2019-04-08 12:30         ` [dpdk-dev] [RFC 2/3] Add 32-bit version of rte_rand Mattias Rönnblom
2019-04-08 12:30           ` Mattias Rönnblom
2019-04-08 12:30         ` [dpdk-dev] [RFC 3/3] Introduce random generator functions with upper bound Mattias Rönnblom
2019-04-08 12:30           ` Mattias Rönnblom
2019-04-08 12:47         ` [dpdk-dev] [RFC 1/3] Replace lrand48-based rte_rand with LFSR generator Mattias Rönnblom
2019-04-08 12:47           ` Mattias Rönnblom
2019-04-19 21:21         ` [dpdk-dev] [RFC v2 0/2] Pseudo-number generation improvements Mattias Rönnblom
2019-04-19 21:21           ` Mattias Rönnblom
2019-04-19 21:21           ` [dpdk-dev] [RFC v2 1/2] eal: replace libc-based random number generation with LFSR Mattias Rönnblom
2019-04-19 21:21             ` Mattias Rönnblom
2019-04-22 11:34             ` Neil Horman
2019-04-22 11:34               ` Neil Horman
2019-04-22 14:49               ` Stephen Hemminger
2019-04-22 14:49                 ` Stephen Hemminger
2019-04-22 15:52               ` Mattias Rönnblom
2019-04-22 15:52                 ` Mattias Rönnblom
2019-04-22 17:44                 ` Mattias Rönnblom
2019-04-22 17:44                   ` Mattias Rönnblom
2019-04-23 11:33                   ` Neil Horman
2019-04-23 11:33                     ` Neil Horman
2019-04-23 17:13                     ` Mattias Rönnblom
2019-04-23 17:13                       ` Mattias Rönnblom
2019-04-24 11:37                       ` Neil Horman
2019-04-24 11:37                         ` Neil Horman
2019-04-23 15:31                   ` Stephen Hemminger
2019-04-23 15:31                     ` Stephen Hemminger
2019-04-23 17:17                     ` Mattias Rönnblom
2019-04-23 17:17                       ` Mattias Rönnblom
2019-04-24  7:52                       ` Mattias Rönnblom
2019-04-24  7:52                         ` Mattias Rönnblom
2019-04-24 12:33                         ` [dpdk-dev] [RFC v3 0/2] Pseudo-random number generation improvements Mattias Rönnblom
2019-04-24 12:33                           ` Mattias Rönnblom
2019-04-24 12:33                           ` [dpdk-dev] [RFC v3 1/2] eal: replace libc-based random number generation with LFSR Mattias Rönnblom
2019-04-24 12:33                             ` Mattias Rönnblom
2019-05-08 20:12                             ` Stephen Hemminger
2019-05-08 20:12                               ` Stephen Hemminger
2019-05-08 20:30                               ` Mattias Rönnblom
2019-05-08 20:30                                 ` Mattias Rönnblom
2019-05-09  1:10                                 ` Stephen Hemminger
2019-05-09  1:10                                   ` Stephen Hemminger
2019-05-14  9:20                                   ` [dpdk-dev] [PATCH 0/6] Pseudo-random number generation improvements Mattias Rönnblom
2019-05-14  9:20                                     ` Mattias Rönnblom
2019-05-14  9:20                                     ` [dpdk-dev] [PATCH 1/6] eal: replace libc-based random number generation with LFSR Mattias Rönnblom
2019-05-14  9:20                                       ` Mattias Rönnblom
2019-05-14  9:32                                       ` Mattias Rönnblom
2019-05-14  9:32                                         ` Mattias Rönnblom
2019-05-14 14:16                                       ` Neil Horman
2019-05-14 14:16                                         ` Neil Horman
2019-05-14 14:53                                         ` Mattias Rönnblom [this message]
2019-05-14 14:53                                           ` Mattias Rönnblom
2019-05-17 19:27                                           ` Neil Horman
2019-05-17 20:57                                             ` Bruce Richardson
2019-05-17 21:10                                             ` Mattias Rönnblom
2019-05-19 18:32                                               ` Neil Horman
2019-05-14 15:27                                       ` Stephen Hemminger
2019-05-14 15:27                                         ` Stephen Hemminger
2019-05-14  9:20                                     ` [dpdk-dev] [PATCH 2/6] eal: add pseudo-random number generation performance test Mattias Rönnblom
2019-05-14  9:20                                       ` Mattias Rönnblom
2019-05-14  9:20                                     ` [dpdk-dev] [PATCH 3/6] eal: improve entropy for initial PRNG seed Mattias Rönnblom
2019-05-14  9:20                                       ` Mattias Rönnblom
2019-05-14  9:36                                       ` Mattias Rönnblom
2019-05-14  9:36                                         ` Mattias Rönnblom
2019-05-14  9:39                                         ` Bruce Richardson
2019-05-14  9:39                                           ` Bruce Richardson
2019-05-14 11:58                                           ` Mattias Rönnblom
2019-05-14 11:58                                             ` Mattias Rönnblom
2019-05-14  9:37                                       ` Bruce Richardson
2019-05-14  9:37                                         ` Bruce Richardson
2019-05-14  9:20                                     ` [dpdk-dev] [PATCH 4/6] eal: introduce random generator function with upper bound Mattias Rönnblom
2019-05-14  9:20                                       ` Mattias Rönnblom
2019-05-14  9:20                                     ` [dpdk-dev] [PATCH 5/6] eal: add bounded PRNG performance tests Mattias Rönnblom
2019-05-14  9:20                                       ` Mattias Rönnblom
2019-05-14  9:20                                     ` [dpdk-dev] [PATCH 6/6] eal: add pseudo-random number generation to MAINTAINERS Mattias Rönnblom
2019-05-14  9:20                                       ` Mattias Rönnblom
2019-05-16 17:55                                     ` [dpdk-dev] [PATCH v2 0/6] Pseudo-random number generation improvements Mattias Rönnblom
2019-05-16 17:55                                       ` [dpdk-dev] [PATCH v2 1/6] eal: replace libc-based random number generation with LFSR Mattias Rönnblom
2019-05-16 17:55                                       ` [dpdk-dev] [PATCH v2 2/6] eal: add pseudo-random number generation performance test Mattias Rönnblom
2019-05-16 17:55                                       ` [dpdk-dev] [PATCH v2 3/6] eal: improve entropy for initial PRNG seed Mattias Rönnblom
2019-05-16 17:55                                       ` [dpdk-dev] [PATCH v2 4/6] eal: introduce random generator function with upper bound Mattias Rönnblom
2019-05-16 17:55                                       ` [dpdk-dev] [PATCH v2 5/6] eal: add bounded PRNG performance tests Mattias Rönnblom
2019-05-16 17:55                                       ` [dpdk-dev] [PATCH v2 6/6] eal: add PRNG to MAINTAINERS and release notes Mattias Rönnblom
2019-05-16 20:35                                       ` [dpdk-dev] [PATCH v2 0/6] Pseudo-random number generation improvements Bruce Richardson
2019-06-05 10:43                                         ` [dpdk-dev] [PATCH v3 " Mattias Rönnblom
2019-06-05 10:43                                           ` [dpdk-dev] [PATCH v3 1/6] eal: replace libc-based random number generation with LFSR Mattias Rönnblom
2019-06-05 10:43                                           ` [dpdk-dev] [PATCH v3 2/6] eal: add pseudo-random number generation performance test Mattias Rönnblom
2019-06-27 21:23                                             ` Thomas Monjalon
2019-06-28  8:20                                               ` Mattias Rönnblom
2019-06-05 10:43                                           ` [dpdk-dev] [PATCH v3 3/6] eal: improve entropy for initial PRNG seed Mattias Rönnblom
2019-06-05 10:43                                           ` [dpdk-dev] [PATCH v3 4/6] eal: introduce random generator function with upper bound Mattias Rönnblom
2019-06-05 10:43                                           ` [dpdk-dev] [PATCH v3 5/6] eal: add bounded PRNG performance tests Mattias Rönnblom
2019-06-05 10:44                                           ` [dpdk-dev] [PATCH v3 6/6] eal: add PRNG to MAINTAINERS and release notes Mattias Rönnblom
2019-06-27 21:27                                             ` Thomas Monjalon
2019-06-28  8:17                                               ` Mattias Rönnblom
2019-06-15 12:23                                           ` [dpdk-dev] [PATCH v3 0/6] Pseudo-random number generation improvements Mattias Rönnblom
2019-06-28  9:01                                           ` [dpdk-dev] [PATCH v4 0/5] " Mattias Rönnblom
2019-06-28  9:01                                             ` [dpdk-dev] [PATCH v4 1/5] eal: replace libc-based random number generation with LFSR Mattias Rönnblom
2019-06-28  9:01                                             ` [dpdk-dev] [PATCH v4 2/5] eal: add pseudo-random number generation performance test Mattias Rönnblom
2019-06-28  9:01                                             ` [dpdk-dev] [PATCH v4 3/5] eal: improve entropy for initial PRNG seed Mattias Rönnblom
2019-06-28 19:01                                               ` Ferruh Yigit
2019-06-28 20:58                                                 ` Mattias Rönnblom
2019-06-28 21:08                                                   ` [dpdk-dev] [PATCH] eal: use 32-bit RDSEED to allow 32-bit x86 usage Mattias Rönnblom
2019-06-29 12:54                                                     ` Thomas Monjalon
2019-06-28  9:01                                             ` [dpdk-dev] [PATCH v4 4/5] eal: introduce random generator function with upper bound Mattias Rönnblom
2019-06-28  9:01                                             ` [dpdk-dev] [PATCH v4 5/5] eal: add bounded PRNG performance tests Mattias Rönnblom
2019-06-28 13:24                                             ` [dpdk-dev] [PATCH v4 0/5] Pseudo-random number generation improvements Thomas Monjalon
2019-04-24 12:33                           ` [dpdk-dev] [RFC v3 2/2] eal: introduce random generator function with upper bound Mattias Rönnblom
2019-04-24 12:33                             ` Mattias Rönnblom
2019-04-19 21:21           ` [dpdk-dev] [RFC v2 " Mattias Rönnblom
2019-04-19 21:21             ` Mattias Rönnblom
2019-04-20 21:08             ` Wiles, Keith
2019-04-20 21:08               ` Wiles, Keith
2019-04-21 19:05               ` Mattias Rönnblom
2019-04-21 19:05                 ` Mattias Rönnblom
2019-04-22  4:33                 ` Wiles, Keith
2019-04-22  4:33                   ` Wiles, Keith
2019-04-22  7:07                   ` Mattias Rönnblom
2019-04-22  7:07                     ` Mattias Rönnblom
2019-04-22 13:19                     ` Wiles, Keith
2019-04-22 13:19                       ` Wiles, Keith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8522b2d7-8361-3e34-7750-88b66d61b98a@ericsson.com \
    --to=mattias.ronnblom@ericsson.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=nhorman@tuxdriver.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).