02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

16 Jul, 2017

1 commit

  • Pull random updates from Ted Ts'o:
    "Add wait_for_random_bytes() and get_random_*_wait() functions so that
    callers can more safely get random bytes if they can block until the
    CRNG is initialized.

    Also print a warning if get_random_*() is called before the CRNG is
    initialized. By default, only one single-line warning will be printed
    per boot. If CONFIG_WARN_ALL_UNSEEDED_RANDOM is defined, then a
    warning will be printed for each function which tries to get random
    bytes before the CRNG is initialized. This can get spammy for certain
    architecture types, so it is not enabled by default"

    * tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
    random: reorder READ_ONCE() in get_random_uXX
    random: suppress spammy warnings about unseeded randomness
    random: warn when kernel uses unseeded randomness
    net/route: use get_random_int for random counter
    net/neighbor: use get_random_u32 for 32-bit hash random
    rhashtable: use get_random_u32 for hash_rnd
    ceph: ensure RNG is seeded before using
    iscsi: ensure RNG is seeded before use
    cifs: use get_random_u32 for 32-bit lock random
    random: add get_random_{bytes,u32,u64,int,long,once}_wait family
    random: add wait_for_random_bytes() API

    Linus Torvalds
     

13 Jul, 2017

1 commit

  • Patch series "stackprotector: ascii armor the stack canary", v2.

    Zero out the first byte of the stack canary value on 64 bit systems, in
    order to mitigate unterminated C string overflows.

    The null byte both prevents C string functions from reading the canary,
    and from writing it if the canary value were guessed or obtained through
    some other means.

    Reducing the entropy by 8 bits is acceptable on 64-bit systems, which
    will still have 56 bits of entropy left, but not on 32 bit systems, so
    the "ascii armor" canary is only implemented on 64-bit systems.

    Inspired by the "ascii armor" code in execshield and Daniel Micay's
    linux-hardened tree.

    Also see https://github.com/thestinger/linux-hardened/

    This patch (of 5):

    Introduce get_random_canary(), which provides a random unsigned long
    canary value with the first byte zeroed out on 64 bit architectures, in
    order to mitigate non-terminated C string overflows.

    The null byte both prevents C string functions from reading the canary,
    and from writing it if the canary value were guessed or obtained through
    some other means.

    Reducing the entropy by 8 bits is acceptable on 64-bit systems, which
    will still have 56 bits of entropy left, but not on 32 bit systems, so
    the "ascii armor" canary is only implemented on 64-bit systems.

    Inspired by the "ascii armor" code in the old execshield patches, and
    Daniel Micay's linux-hardened tree.

    Link: http://lkml.kernel.org/r/20170524155751.424-2-riel@redhat.com
    Signed-off-by: Rik van Riel
    Acked-by: Kees Cook
    Cc: Daniel Micay
    Cc: "Theodore Ts'o"
    Cc: H. Peter Anvin
    Cc: Andy Lutomirski
    Cc: Ingo Molnar
    Cc: Catalin Marinas
    Cc: Yoshinori Sato
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rik van Riel
     

20 Jun, 2017

2 commits


28 Jan, 2017

2 commits

  • Many times, when a user wants a random number, he wants a random number
    of a guaranteed size. So, thinking of get_random_int and get_random_long
    in terms of get_random_u32 and get_random_u64 makes it much easier to
    achieve this. It also makes the code simpler.

    On 32-bit platforms, get_random_int and get_random_long are both aliased
    to get_random_u32. On 64-bit platforms, int->u32 and long->u64.

    Signed-off-by: Jason A. Donenfeld
    Cc: Greg Kroah-Hartman
    Cc: Theodore Ts'o
    Signed-off-by: Theodore Ts'o

    Jason A. Donenfeld
     
  • Now that our crng uses chacha20, we can rely on its speedy
    characteristics for replacing MD5, while simultaneously achieving a
    higher security guarantee. Before the idea was to use these functions if
    you wanted random integers that aren't stupidly insecure but aren't
    necessarily secure either, a vague gray zone, that hopefully was "good
    enough" for its users. With chacha20, we can strengthen this claim,
    since either we're using an rdrand-like instruction, or we're using the
    same crng as /dev/urandom. And it's faster than what was before.

    We could have chosen to replace this with a SipHash-derived function,
    which might be slightly faster, but at the cost of having yet another
    RNG construction in the kernel. By moving to chacha20, we have a single
    RNG to analyze and verify, and we also already get good performance
    improvements on all platforms.

    Implementation-wise, rather than use a generic buffer for both
    get_random_int/long and memcpy based on the size needs, we use a
    specific buffer for 32-bit reads and for 64-bit reads. This way, we're
    guaranteed to always have aligned accesses on all platforms. While
    slightly more verbose in C, the assembly this generates is a lot
    simpler than otherwise.

    Finally, on 32-bit platforms where longs and ints are the same size,
    we simply alias get_random_int to get_random_long.

    Signed-off-by: Jason A. Donenfeld
    Suggested-by: Theodore Ts'o
    Cc: Theodore Ts'o
    Cc: Hannes Frederic Sowa
    Cc: Andy Lutomirski
    Signed-off-by: Theodore Ts'o

    Jason A. Donenfeld
     

16 Oct, 2016

1 commit

  • Pull gcc plugins update from Kees Cook:
    "This adds a new gcc plugin named "latent_entropy". It is designed to
    extract as much possible uncertainty from a running system at boot
    time as possible, hoping to capitalize on any possible variation in
    CPU operation (due to runtime data differences, hardware differences,
    SMP ordering, thermal timing variation, cache behavior, etc).

    At the very least, this plugin is a much more comprehensive example
    for how to manipulate kernel code using the gcc plugin internals"

    * tag 'gcc-plugins-v4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
    latent_entropy: Mark functions with __latent_entropy
    gcc-plugins: Add latent_entropy plugin

    Linus Torvalds
     

12 Oct, 2016

2 commits

  • All call sites for randomize_range have been updated to use the much
    simpler and more robust randomize_addr(). Remove the now unnecessary
    code.

    Link: http://lkml.kernel.org/r/20160803233913.32511-8-jason@lakedaemon.net
    Signed-off-by: Jason Cooper
    Acked-by: Kees Cook
    Cc: "Theodore Ts'o"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jason Cooper
     
  • To date, all callers of randomize_range() have set the length to 0, and
    check for a zero return value. For the current callers, the only way to
    get zero returned is if end
    Cc: Nick Kralevich
    Cc: Jeffrey Vander Stoep
    Cc: Daniel Cashman
    Cc: Chris Metcalf
    Cc: Guan Xuetao
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jason Cooper
     

11 Oct, 2016

2 commits

  • The __latent_entropy gcc attribute can be used only on functions and
    variables. If it is on a function then the plugin will instrument it for
    gathering control-flow entropy. If the attribute is on a variable then
    the plugin will initialize it with random contents. The variable must
    be an integer, an integer array type or a structure with integer fields.

    These specific functions have been selected because they are init
    functions (to help gather boot-time entropy), are called at unpredictable
    times, or they have variable loops, each of which provide some level of
    latent entropy.

    Signed-off-by: Emese Revfy
    [kees: expanded commit message]
    Signed-off-by: Kees Cook

    Emese Revfy
     
  • This adds a new gcc plugin named "latent_entropy". It is designed to
    extract as much possible uncertainty from a running system at boot time as
    possible, hoping to capitalize on any possible variation in CPU operation
    (due to runtime data differences, hardware differences, SMP ordering,
    thermal timing variation, cache behavior, etc).

    At the very least, this plugin is a much more comprehensive example for
    how to manipulate kernel code using the gcc plugin internals.

    The need for very-early boot entropy tends to be very architecture or
    system design specific, so this plugin is more suited for those sorts
    of special cases. The existing kernel RNG already attempts to extract
    entropy from reliable runtime variation, but this plugin takes the idea to
    a logical extreme by permuting a global variable based on any variation
    in code execution (e.g. a different value (and permutation function)
    is used to permute the global based on loop count, case statement,
    if/then/else branching, etc).

    To do this, the plugin starts by inserting a local variable in every
    marked function. The plugin then adds logic so that the value of this
    variable is modified by randomly chosen operations (add, xor and rol) and
    random values (gcc generates separate static values for each location at
    compile time and also injects the stack pointer at runtime). The resulting
    value depends on the control flow path (e.g., loops and branches taken).

    Before the function returns, the plugin mixes this local variable into
    the latent_entropy global variable. The value of this global variable
    is added to the kernel entropy pool in do_one_initcall() and _do_fork(),
    though it does not credit any bytes of entropy to the pool; the contents
    of the global are just used to mix the pool.

    Additionally, the plugin can pre-initialize arrays with build-time
    random contents, so that two different kernel builds running on identical
    hardware will not have the same starting values.

    Signed-off-by: Emese Revfy
    [kees: expanded commit message and code comments]
    Signed-off-by: Kees Cook

    Emese Revfy
     

09 Jun, 2016

1 commit

  • The gcc people have confirmed that using "bool" when combined with
    inline assembly always is treated as a byte-sized operand that can be
    assumed to be 0 or 1, which is exactly what the SET instruction
    emits. Change the output types and intermediate variables of as many
    operations as practical to "bool".

    Signed-off-by: H. Peter Anvin
    Link: http://lkml.kernel.org/r/1465414726-197858-3-git-send-email-hpa@linux.intel.com
    Reviewed-by: Andy Lutomirski
    Reviewed-by: Borislav Petkov
    Acked-by: Peter Zijlstra (Intel)

    H. Peter Anvin
     

21 May, 2016

1 commit

  • Let's gather the UUID related functions under one hood.

    Signed-off-by: Andy Shevchenko
    Reviewed-by: Matt Fleming
    Cc: Dmitry Kasatkin
    Cc: Mimi Zohar
    Cc: Rasmus Villemoes
    Cc: Arnd Bergmann
    Cc: "Theodore Ts'o"
    Cc: Al Viro
    Cc: Jens Axboe
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

28 Feb, 2016

1 commit

  • Commit d07e22597d1d ("mm: mmap: add new /proc tunable for mmap_base
    ASLR") added the ability to choose from a range of values to use for
    entropy count in generating the random offset to the mmap_base address.

    The maximum value on this range was set to 32 bits for 64-bit x86
    systems, but this value could be increased further, requiring more than
    the 32 bits of randomness provided by get_random_int(), as is already
    possible for arm64. Add a new function: get_random_long() which more
    naturally fits with the mmap usage of get_random_int() but operates
    exactly the same as get_random_int().

    Also, fix the shifting constant in mmap_rnd() to be an unsigned long so
    that values greater than 31 bits generate an appropriate mask without
    overflow. This is especially important on x86, as its shift instruction
    uses a 5-bit mask for the shift operand, which meant that any value for
    mmap_rnd_bits over 31 acts as a no-op and effectively disables mmap_base
    randomization.

    Finally, replace calls to get_random_int() with get_random_long() where
    appropriate.

    This patch (of 2):

    Add get_random_long().

    Signed-off-by: Daniel Cashman
    Acked-by: Kees Cook
    Cc: "Theodore Ts'o"
    Cc: Arnd Bergmann
    Cc: Greg Kroah-Hartman
    Cc: Catalin Marinas
    Cc: Will Deacon
    Cc: Ralf Baechle
    Cc: Benjamin Herrenschmidt
    Cc: Paul Mackerras
    Cc: Michael Ellerman
    Cc: David S. Miller
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: H. Peter Anvin
    Cc: Al Viro
    Cc: Nick Kralevich
    Cc: Jeff Vander Stoep
    Cc: Mark Salyzyn
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel Cashman
     

08 Oct, 2015

1 commit

  • Add a prandom_init_once() facility that works on the rnd_state, so that
    users that are keeping their own state independent from prandom_u32() can
    initialize their taus113 per cpu states.

    The motivation here is similar to net_get_random_once(): initialize the
    state as late as possible in the hope that enough entropy has been
    collected for the seeding. prandom_init_once() makes use of the recently
    introduced prandom_seed_full_state() helper and is generic enough so that
    it could also be used on fast-paths due to the DO_ONCE().

    Signed-off-by: Daniel Borkmann
    Acked-by: Hannes Frederic Sowa
    Acked-by: Alexei Starovoitov
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

10 Jun, 2015

2 commits

  • This patch removes the kernel blocking API as it has been completely
    replaced by the callback API.

    Signed-off-by: Herbert Xu

    Herbert Xu
     
  • The get_blocking_random_bytes API is broken because the wait can
    be arbitrarily long (potentially forever) so there is no safe way
    of calling it from within the kernel.

    This patch replaces it with a callback API instead. The callback
    is invoked potentially from interrupt context so the user needs
    to schedule their own work thread if necessary.

    In addition to adding callbacks, they can also be removed as
    otherwise this opens up a way for user-space to allocate kernel
    memory with no bound (by opening algif_rng descriptors and then
    closing them).

    Signed-off-by: Herbert Xu

    Herbert Xu
     

27 May, 2015

1 commit


25 Aug, 2014

1 commit

  • This patch addresses a couple of minor items, mostly addesssing
    prandom_bytes(): 1) prandom_bytes{,_state}() should use size_t
    for length arguments, 2) We can use put_unaligned() when filling
    the array instead of open coding it [ perhaps some archs will
    further benefit from their own arch specific implementation when
    GCC cannot make up for it ], 3) Fix a typo, 4) Better use unsigned
    int as type for getting the arch seed, 5) Make use of
    prandom_u32_max() for timer slack.

    Regarding the change to put_unaligned(), callers of prandom_bytes()
    which internally invoke prandom_bytes_state(), don't bother as
    they expect the array to be filled randomly and don't have any
    control of the internal state what-so-ever (that's also why we
    have periodic reseeding there, etc), so they really don't care.

    Now for the direct callers of prandom_bytes_state(), which
    are solely located in test cases for MTD devices, that is,
    drivers/mtd/tests/{oobtest.c,pagetest.c,subpagetest.c}:

    These tests basically fill a test write-vector through
    prandom_bytes_state() with an a-priori defined seed each time
    and write that to a MTD device. Later on, they set up a read-vector
    and read back that blocks from the device. So in the verification
    phase, the write-vector is being re-setup [ so same seed and
    prandom_bytes_state() called ], and then memcmp()'ed against the
    read-vector to check if the data is the same.

    Akinobu, Lothar and I also tested this patch and it runs through
    the 3 relevant MTD test cases w/o any errors on the nandsim device
    (simulator for MTD devs) for x86_64, ppc64, ARM (i.MX28, i.MX53
    and i.MX6):

    # modprobe nandsim first_id_byte=0x20 second_id_byte=0xac \
    third_id_byte=0x00 fourth_id_byte=0x15
    # modprobe mtd_oobtest dev=0
    # modprobe mtd_pagetest dev=0
    # modprobe mtd_subpagetest dev=0

    We also don't have any users depending directly on a particular
    result of the PRNG (except the PRNG self-test itself), and that's
    just fine as it e.g. allowed us easily to do things like upgrading
    from taus88 to taus113.

    Signed-off-by: Daniel Borkmann
    Tested-by: Akinobu Mita
    Tested-by: Lothar Waßmann
    Cc: Hannes Frederic Sowa
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

20 Mar, 2014

2 commits

  • Add predicate functions for having arch_get_random[_seed]*(). The
    only current use is to avoid the loop in arch_random_refill() when
    arch_get_random_seed_long() is unavailable.

    Signed-off-by: H. Peter Anvin
    Cc: Benjamin Herrenschmidt
    Cc: Paul Mackerras
    Cc: Michael Ellerman
    Signed-off-by: Theodore Ts'o

    H. Peter Anvin
     
  • Upcoming Intel silicon adds a new RDSEED instruction, which is similar
    to RDRAND but provides a stronger guarantee: unlike RDRAND, RDSEED
    will always reseed the PRNG from the true random number source between
    each read. Thus, the output of RDSEED is guaranteed to be 100%
    entropic, unlike RDRAND which is only architecturally guaranteed to be
    1/512 entropic (although in practice is much more.)

    The RDSEED instruction takes the same time to execute as RDRAND, but
    RDSEED unlike RDRAND can legitimately return failure (CF=0) due to
    entropy exhaustion if too many threads on too many cores are hammering
    the RDSEED instruction at the same time. Therefore, we have to be
    more conservative and only use it in places where we can tolerate
    failures.

    This patch introduces the primitives arch_get_random_seed_{int,long}()
    but does not use it yet.

    Signed-off-by: H. Peter Anvin
    Reviewed-by: Ingo Molnar
    Cc: Benjamin Herrenschmidt
    Cc: Paul Mackerras
    Cc: Michael Ellerman
    Signed-off-by: Theodore Ts'o

    H. Peter Anvin
     

22 Jan, 2014

1 commit

  • Many functions have open coded a function that returns a random
    number in range [0,N-1]. Under the assumption that we have a PRNG
    such as taus113 with being well distributed in [0, ~0U] space,
    we can implement such a function as uword t = (n*m')>>32, where
    m' is a random number obtained from PRNG, n the right open interval
    border and t our resulting random number, with n,m',t in u32 universe.

    Lets go with Joe and simply call it prandom_u32_max(), although
    technically we have an right open interval endpoint, but that we
    have documented. Other users can further be migrated to the new
    prandom_u32_max() function later on; for now, we need to make sure
    to migrate reciprocal_divide() users for the reciprocal_divide()
    follow-up fixup since their function signatures are going to change.

    Joint work with Hannes Frederic Sowa.

    Cc: Jakub Zawadzki
    Cc: Eric Dumazet
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Hannes Frederic Sowa
    Signed-off-by: Daniel Borkmann
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

12 Nov, 2013

4 commits

  • Since we use prandom*() functions quite often in networking code
    i.e. in UDP port selection, netfilter code, etc, upgrade the PRNG
    from Pierre L'Ecuyer's original paper "Maximally Equidistributed
    Combined Tausworthe Generators", Mathematics of Computation, 65,
    213 (1996), 203--213 to the version published in his errata paper [1].

    The Tausworthe generator is a maximally-equidistributed generator,
    that is fast and has good statistical properties [1].

    The version presented there upgrades the 3 state LFSR to a 4 state
    LFSR with increased periodicity from about 2^88 to 2^113. The
    algorithm is presented in [1] by the very same author who also
    designed the original algorithm in [2].

    Also, by increasing the state, we make it a bit harder for attackers
    to "guess" the PRNGs internal state. See also discussion in [3].

    Now, as we use this sort of weak initialization discussed in [3]
    only between core_initcall() until late_initcall() time [*] for
    prandom32*() users, namely in prandom_init(), it is less relevant
    from late_initcall() onwards as we overwrite seeds through
    prandom_reseed() anyways with a seed source of higher entropy, that
    is, get_random_bytes(). In other words, a exhaustive keysearch of
    96 bit would be needed. Now, with the help of this patch, this
    state-search increases further to 128 bit. Initialization needs
    to make sure that s1 > 1, s2 > 7, s3 > 15, s4 > 127.

    taus88 and taus113 algorithm is also part of GSL. I added a test
    case in the next patch to verify internal behaviour of this patch
    with GSL and ran tests with the dieharder 3.31.1 RNG test suite:

    $ dieharder -g 052 -a -m 10 -s 1 -S 4137730333 #taus88
    $ dieharder -g 054 -a -m 10 -s 1 -S 4137730333 #taus113

    With this seed configuration, in order to compare both, we get
    the following differences:

    algorithm taus88 taus113
    rands/second [**] 1.61e+08 1.37e+08
    sts_serial(4, 1st run) WEAK PASSED
    sts_serial(9, 2nd run) WEAK PASSED
    rgb_lagged_sum(31) WEAK PASSED

    We took out diehard_sums test as according to the authors it is
    considered broken and unusable [4]. Despite that and the slight
    decrease in performance (which is acceptable), taus113 here passes
    all 113 tests (only rgb_minimum_distance_5 in WEAK, the rest PASSED).
    In general, taus/taus113 is considered "very good" by the authors
    of dieharder [5].

    The papers [1][2] states a single warm-up step is sufficient by
    running quicktaus once on each state to ensure proper initialization
    of ~s_{0}:

    Our selection of (s) according to Table 1 of [1] row 1 holds the
    condition L - k
    Cc: Theodore Ts'o
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Hannes Frederic Sowa
    Signed-off-by: David S. Miller

    Daniel Borkmann
     
  • struct rnd_state got mistakenly pulled into uapi header. It is not
    used anywhere and does also not belong there!

    Commit 5960164fde ("lib/random32: export pseudo-random number
    generator for modules"), the last commit on rnd_state before it
    got moved to uapi, says:

    This patch moves the definition of struct rnd_state and the inline
    __seed() function to linux/random.h. It renames the static __random32()
    function to prandom32() and exports it for use in modules.

    Hence, the structure was moved from lib/random32.c to linux/random.h
    so that it can be used within modules (FCoE-related code in this
    case), but not from user space. However, it seems to have been
    mistakenly moved to uapi header through the uapi script. Since no-one
    should make use of it from the linux headers, move the structure back
    to the kernel for internal use, so that it can be modified on demand.

    Joint work with Hannes Frederic Sowa.

    Cc: Joe Eykholt
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Hannes Frederic Sowa
    Signed-off-by: David S. Miller

    Daniel Borkmann
     
  • The Tausworthe PRNG is initialized at late_initcall time. At that time the
    entropy pool serving get_random_bytes is not filled sufficiently. This
    patch adds an additional reseeding step as soon as the nonblocking pool
    gets marked as initialized.

    On some machines it might be possible that late_initcall gets called after
    the pool has been initialized. In this situation we won't reseed again.

    (A call to prandom_seed_late blocks later invocations of early reseed
    attempts.)

    Joint work with Daniel Borkmann.

    Cc: Eric Dumazet
    Cc: Theodore Ts'o
    Signed-off-by: Hannes Frederic Sowa
    Signed-off-by: Daniel Borkmann
    Acked-by: "Theodore Ts'o"
    Signed-off-by: David S. Miller

    Hannes Frederic Sowa
     
  • For properly initialising the Tausworthe generator [1], we have
    a strict seeding requirement, that is, s1 > 1, s2 > 7, s3 > 15.

    Commit 697f8d0348 ("random32: seeding improvement") introduced
    a __seed() function that imposes boundary checks proposed by the
    errata paper [2] to properly ensure above conditions.

    However, we're off by one, as the function is implemented as:
    "return (x < m) ? x + m : x;", and called with __seed(X, 1),
    __seed(X, 7), __seed(X, 15). Thus, an unwanted seed of 1, 7, 15
    would be possible, whereas the lower boundary should actually
    be of at least 2, 8, 16, just as GSL does. Fix this, as otherwise
    an initialization with an unwanted seed could have the effect
    that Tausworthe's PRNG properties cannot not be ensured.

    Note that this PRNG is *not* used for cryptography in the kernel.

    [1] http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps
    [2] http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps

    Joint work with Hannes Frederic Sowa.

    Fixes: 697f8d0348a6 ("random32: seeding improvement")
    Cc: Stephen Hemminger
    Cc: Florian Weimer
    Cc: Theodore Ts'o
    Signed-off-by: Daniel Borkmann
    Signed-off-by: Hannes Frederic Sowa
    Signed-off-by: David S. Miller

    Daniel Borkmann
     

23 Sep, 2013

1 commit


08 May, 2013

1 commit


24 Jan, 2013

1 commit


18 Dec, 2012

2 commits

  • Add functions to get the requested number of pseudo-random bytes.

    The difference from get_random_bytes() is that it generates pseudo-random
    numbers by prandom_u32(). It doesn't consume the entropy pool, and the
    sequence is reproducible if the same rnd_state is used. So it is suitable
    for generating random bytes for testing.

    Signed-off-by: Akinobu Mita
    Cc: "Theodore Ts'o"
    Cc: Artem Bityutskiy
    Cc: Adrian Hunter
    Cc: David Woodhouse
    Cc: Eilon Greenstein
    Cc: David Laight
    Cc: Michel Lespinasse
    Cc: Robert Love
    Cc: Valdis Kletnieks
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Akinobu Mita
     
  • This renames all random32 functions to have 'prandom_' prefix as follows:

    void prandom_seed(u32 seed); /* rename from srandom32() */
    u32 prandom_u32(void); /* rename from random32() */
    void prandom_seed_state(struct rnd_state *state, u64 seed);
    /* rename from prandom32_seed() */
    u32 prandom_u32_state(struct rnd_state *state);
    /* rename from prandom32() */

    The purpose of this renaming is to prevent some kernel developers from
    assuming that prandom32() and random32() might imply that only
    prandom32() was the one using a pseudo-random number generator by
    prandom32's "p", and the result may be a very embarassing security
    exposure. This concern was expressed by Theodore Ts'o.

    And furthermore, I'm going to introduce new functions for getting the
    requested number of pseudo-random bytes. If I continue to use both
    prandom32 and random32 prefixes for these functions, the confusion
    is getting worse.

    As a result of this renaming, "prandom_" is the common prefix for
    pseudo-random number library.

    Currently, srandom32() and random32() are preserved because it is
    difficult to rename too many users at once.

    Signed-off-by: Akinobu Mita
    Cc: "Theodore Ts'o"
    Cc: Robert Love
    Cc: Michel Lespinasse
    Cc: Valdis Kletnieks
    Cc: David Laight
    Cc: Adrian Hunter
    Cc: Artem Bityutskiy
    Cc: David Woodhouse
    Cc: Eilon Greenstein
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Akinobu Mita
     

13 Oct, 2012

1 commit


19 Jul, 2012

1 commit

  • With the new interrupt sampling system, we are no longer using the
    timer_rand_state structure in the irq descriptor, so we can stop
    initializing it now.

    [ Merged in fixes from Sedat to find some last missing references to
    rand_initialize_irq() ]

    Signed-off-by: "Theodore Ts'o"
    Signed-off-by: Sedat Dilek

    Theodore Ts'o
     

15 Jul, 2012

3 commits

  • Create a new function, get_random_bytes_arch() which will use the
    architecture-specific hardware random number generator if it is
    present. Change get_random_bytes() to not use the HW RNG, even if it
    is avaiable.

    The reason for this is that the hw random number generator is fast (if
    it is present), but it requires that we trust the hardware
    manufacturer to have not put in a back door. (For example, an
    increasing counter encrypted by an AES key known to the NSA.)

    It's unlikely that Intel (for example) was paid off by the US
    Government to do this, but it's impossible for them to prove otherwise
    --- especially since Bull Mountain is documented to use AES as a
    whitener. Hence, the output of an evil, trojan-horse version of
    RDRAND is statistically indistinguishable from an RDRAND implemented
    to the specifications claimed by Intel. Short of using a tunnelling
    electronic microscope to reverse engineer an Ivy Bridge chip and
    disassembling and analyzing the CPU microcode, there's no way for us
    to tell for sure.

    Since users of get_random_bytes() in the Linux kernel need to be able
    to support hardware systems where the HW RNG is not present, most
    time-sensitive users of this interface have already created their own
    cryptographic RNG interface which uses get_random_bytes() as a seed.
    So it's much better to use the HW RNG to improve the existing random
    number generator, by mixing in any entropy returned by the HW RNG into
    /dev/random's entropy pool, but to always _use_ /dev/random's entropy
    pool.

    This way we get almost of the benefits of the HW RNG without any
    potential liabilities. The only benefits we forgo is the
    speed/performance enhancements --- and generic kernel code can't
    depend on depend on get_random_bytes() having the speed of a HW RNG
    anyway.

    For those places that really want access to the arch-specific HW RNG,
    if it is available, we provide get_random_bytes_arch().

    Signed-off-by: "Theodore Ts'o"
    Cc: stable@vger.kernel.org

    Theodore Ts'o
     
  • Add a new interface, add_device_randomness() for adding data to the
    random pool that is likely to differ between two devices (or possibly
    even per boot). This would be things like MAC addresses or serial
    numbers, or the read-out of the RTC. This does *not* add any actual
    entropy to the pool, but it initializes the pool to different values
    for devices that might otherwise be identical and have very little
    entropy available to them (particularly common in the embedded world).

    [ Modified by tytso to mix in a timestamp, since there may be some
    variability caused by the time needed to detect/configure the hardware
    in question. ]

    Signed-off-by: Linus Torvalds
    Signed-off-by: "Theodore Ts'o"
    Cc: stable@vger.kernel.org

    Linus Torvalds
     
  • We've been moving away from add_interrupt_randomness() for various
    reasons: it's too expensive to do on every interrupt, and flooding the
    CPU with interrupts could theoretically cause bogus floods of entropy
    from a somewhat externally controllable source.

    This solves both problems by limiting the actual randomness addition
    to just once a second or after 64 interrupts, whicever comes first.
    During that time, the interrupt cycle data is buffered up in a per-cpu
    pool. Also, we make sure the the nonblocking pool used by urandom is
    initialized before we start feeding the normal input pool. This
    assures that /dev/urandom is returning unpredictable data as soon as
    possible.

    (Based on an original patch by Linus, but significantly modified by
    tytso.)

    Tested-by: Eric Wustrow
    Reported-by: Eric Wustrow
    Reported-by: Nadia Heninger
    Reported-by: Zakir Durumeric
    Reported-by: J. Alex Halderman .
    Signed-off-by: Linus Torvalds
    Signed-off-by: "Theodore Ts'o"
    Cc: stable@vger.kernel.org

    Theodore Ts'o
     

28 Oct, 2011

1 commit

  • * 'x86-rdrand-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
    x86, random: Verify RDRAND functionality and allow it to be disabled
    x86, random: Architectural inlines to get random integers with RDRAND
    random: Add support for architectural random hooks

    Fix up trivial conflicts in drivers/char/random.c: the architectural
    random hooks touched "get_random_int()" that was simplified to use MD5
    and not do the keyptr thing any more (see commit 6e5714eaf77d: "net:
    Compute protocol sequence numbers and fragment IDs using MD5").

    Linus Torvalds
     

07 Aug, 2011

1 commit

  • Computers have become a lot faster since we compromised on the
    partial MD4 hash which we use currently for performance reasons.

    MD5 is a much safer choice, and is inline with both RFC1948 and
    other ISS generators (OpenBSD, Solaris, etc.)

    Furthermore, only having 24-bits of the sequence number be truly
    unpredictable is a very serious limitation. So the periodic
    regeneration and 8-bit counter have been removed. We compute and
    use a full 32-bit sequence number.

    For ipv6, DCCP was found to use a 32-bit truncated initial sequence
    number (it needs 43-bits) and that is fixed here as well.

    Reported-by: Dan Kaminsky
    Tested-by: Willy Tarreau
    Signed-off-by: David S. Miller

    David S. Miller
     

01 Aug, 2011

1 commit

  • Add support for architecture-specific hooks into the kernel-directed
    random number generator interfaces. This patchset does not use the
    architecture random number generator interfaces for the
    userspace-directed interfaces (/dev/random and /dev/urandom), thus
    eliminating the need to distinguish between them based on a pool
    pointer.

    Changes in version 3:
    - Moved the hooks from extract_entropy() to get_random_bytes().
    - Changes the hooks to inlines.

    Signed-off-by: H. Peter Anvin
    Cc: Fenghua Yu
    Cc: Matt Mackall
    Cc: Herbert Xu
    Cc: "Theodore Ts'o"

    H. Peter Anvin