1. 25 5月, 2022 1 次提交
  2. 23 5月, 2022 3 次提交
  3. 20 5月, 2022 4 次提交
  4. 19 5月, 2022 15 次提交
  5. 18 5月, 2022 6 次提交
    • J
      random: handle latent entropy and command line from random_init() · 2f14062b
      Jason A. Donenfeld 提交于
      Currently, start_kernel() adds latent entropy and the command line to
      the entropy bool *after* the RNG has been initialized, deferring when
      it's actually used by things like stack canaries until the next time
      the pool is seeded. This surely is not intended.
      
      Rather than splitting up which entropy gets added where and when between
      start_kernel() and random_init(), just do everything in random_init(),
      which should eliminate these kinds of bugs in the future.
      
      While we're at it, rename the awkwardly titled "rand_initialize()" to
      the more standard "random_init()" nomenclature.
      Reviewed-by: NDominik Brodowski <linux@dominikbrodowski.net>
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      2f14062b
    • J
      random32: use real rng for non-deterministic randomness · d4150779
      Jason A. Donenfeld 提交于
      random32.c has two random number generators in it: one that is meant to
      be used deterministically, with some predefined seed, and one that does
      the same exact thing as random.c, except does it poorly. The first one
      has some use cases. The second one no longer does and can be replaced
      with calls to random.c's proper random number generator.
      
      The relatively recent siphash-based bad random32.c code was added in
      response to concerns that the prior random32.c was too deterministic.
      Out of fears that random.c was (at the time) too slow, this code was
      anonymously contributed. Then out of that emerged a kind of shadow
      entropy gathering system, with its own tentacles throughout various net
      code, added willy nilly.
      
      Stop👏making👏bespoke👏random👏number👏generators👏.
      
      Fortunately, recent advances in random.c mean that we can stop playing
      with this sketchiness, and just use get_random_u32(), which is now fast
      enough. In micro benchmarks using RDPMC, I'm seeing the same median
      cycle count between the two functions, with the mean being _slightly_
      higher due to batches refilling (which we can optimize further need be).
      However, when doing *real* benchmarks of the net functions that actually
      use these random numbers, the mean cycles actually *decreased* slightly
      (with the median still staying the same), likely because the additional
      prandom code means icache misses and complexity, whereas random.c is
      generally already being used by something else nearby.
      
      The biggest benefit of this is that there are many users of prandom who
      probably should be using cryptographically secure random numbers. This
      makes all of those accidental cases become secure by just flipping a
      switch. Later on, we can do a tree-wide cleanup to remove the static
      inline wrapper functions that this commit adds.
      
      There are also some low-ish hanging fruits for making this even faster
      in the future: a get_random_u16() function for use in the networking
      stack will give a 2x performance boost there, using SIMD for ChaCha20
      will let us compute 4 or 8 or 16 blocks of output in parallel, instead
      of just one, giving us large buffers for cheap, and introducing a
      get_random_*_bh() function that assumes irqs are already disabled will
      shave off a few cycles for ordinary calls. These are things we can chip
      away at down the road.
      Acked-by: NJakub Kicinski <kuba@kernel.org>
      Acked-by: NTheodore Ts'o <tytso@mit.edu>
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      d4150779
    • J
      siphash: use one source of truth for siphash permutations · e73aaae2
      Jason A. Donenfeld 提交于
      The SipHash family of permutations is currently used in three places:
      
      - siphash.c itself, used in the ordinary way it was intended.
      - random32.c, in a construction from an anonymous contributor.
      - random.c, as part of its fast_mix function.
      
      Each one of these places reinvents the wheel with the same C code, same
      rotation constants, and same symmetry-breaking constants.
      
      This commit tidies things up a bit by placing macros for the
      permutations and constants into siphash.h, where each of the three .c
      users can access them. It also leaves a note dissuading more users of
      them from emerging.
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      e73aaae2
    • J
      io_uring: add support for ring mapped supplied buffers · c7fb1942
      Jens Axboe 提交于
      Provided buffers allow an application to supply io_uring with buffers
      that can then be grabbed for a read/receive request, when the data
      source is ready to deliver data. The existing scheme relies on using
      IORING_OP_PROVIDE_BUFFERS to do that, but it can be difficult to use
      in real world applications. It's pretty efficient if the application
      is able to supply back batches of provided buffers when they have been
      consumed and the application is ready to recycle them, but if
      fragmentation occurs in the buffer space, it can become difficult to
      supply enough buffers at the time. This hurts efficiency.
      
      Add a register op, IORING_REGISTER_PBUF_RING, which allows an application
      to setup a shared queue for each buffer group of provided buffers. The
      application can then supply buffers simply by adding them to this ring,
      and the kernel can consume then just as easily. The ring shares the head
      with the application, the tail remains private in the kernel.
      
      Provided buffers setup with IORING_REGISTER_PBUF_RING cannot use
      IORING_OP_{PROVIDE,REMOVE}_BUFFERS for adding or removing entries to the
      ring, they must use the mapped ring. Mapped provided buffer rings can
      co-exist with normal provided buffers, just not within the same group ID.
      
      To gauge overhead of the existing scheme and evaluate the mapped ring
      approach, a simple NOP benchmark was written. It uses a ring of 128
      entries, and submits/completes 32 at the time. 'Replenish' is how
      many buffers are provided back at the time after they have been
      consumed:
      
      Test			Replenish			NOPs/sec
      ================================================================
      No provided buffers	NA				~30M
      Provided buffers	32				~16M
      Provided buffers	 1				~10M
      Ring buffers		32				~27M
      Ring buffers		 1				~27M
      
      The ring mapped buffers perform almost as well as not using provided
      buffers at all, and they don't care if you provided 1 or more back at
      the same time. This means application can just replenish as they go,
      rather than need to batch and compact, further reducing overhead in the
      application. The NOP benchmark above doesn't need to do any compaction,
      so that overhead isn't even reflected in the above test.
      Co-developed-by: NDylan Yudaken <dylany@fb.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      c7fb1942
    • U
      locking/atomic: Add generic try_cmpxchg64 support · 0aa7be05
      Uros Bizjak 提交于
      Add generic support for try_cmpxchg64{,_acquire,_release,_relaxed}
      and their falbacks involving cmpxchg64.
      Signed-off-by: NUros Bizjak <ubizjak@gmail.com>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/20220515184205.103089-2-ubizjak@gmail.com
      0aa7be05
    • J
      audit,io_uring,io-wq: call __audit_uring_exit for dummy contexts · 69e9cd66
      Julian Orth 提交于
      Not calling the function for dummy contexts will cause the context to
      not be reset. During the next syscall, this will cause an error in
      __audit_syscall_entry:
      
      	WARN_ON(context->context != AUDIT_CTX_UNUSED);
      	WARN_ON(context->name_count);
      	if (context->context != AUDIT_CTX_UNUSED || context->name_count) {
      		audit_panic("unrecoverable error in audit_syscall_entry()");
      		return;
      	}
      
      These problematic dummy contexts are created via the following call
      chain:
      
             exit_to_user_mode_prepare
          -> arch_do_signal_or_restart
          -> get_signal
          -> task_work_run
          -> tctx_task_work
          -> io_req_task_submit
          -> io_issue_sqe
          -> audit_uring_entry
      
      Cc: stable@vger.kernel.org
      Fixes: 5bd2182d ("audit,io_uring,io-wq: add some basic audit support to io_uring")
      Signed-off-by: NJulian Orth <ju.orth@gmail.com>
      [PM: subject line tweaks]
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      69e9cd66
  6. 17 5月, 2022 2 次提交
  7. 16 5月, 2022 5 次提交
  8. 14 5月, 2022 3 次提交
    • H
      io_uring: add IORING_ACCEPT_MULTISHOT for accept · 390ed29b
      Hao Xu 提交于
      add an accept_flag IORING_ACCEPT_MULTISHOT for accept, which is to
      support multishot.
      Signed-off-by: NHao Xu <howeyxu@tencent.com>
      Link: https://lore.kernel.org/r/20220514142046.58072-2-haoxu.linux@gmail.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      390ed29b
    • J
      timekeeping: Add raw clock fallback for random_get_entropy() · 1366992e
      Jason A. Donenfeld 提交于
      The addition of random_get_entropy_fallback() provides access to
      whichever time source has the highest frequency, which is useful for
      gathering entropy on platforms without available cycle counters. It's
      not necessarily as good as being able to quickly access a cycle counter
      that the CPU has, but it's still something, even when it falls back to
      being jiffies-based.
      
      In the event that a given arch does not define get_cycles(), falling
      back to the get_cycles() default implementation that returns 0 is really
      not the best we can do. Instead, at least calling
      random_get_entropy_fallback() would be preferable, because that always
      needs to return _something_, even falling back to jiffies eventually.
      It's not as though random_get_entropy_fallback() is super high precision
      or guaranteed to be entropic, but basically anything that's not zero all
      the time is better than returning zero all the time.
      
      Finally, since random_get_entropy_fallback() is used during extremely
      early boot when randomizing freelists in mm_init(), it can be called
      before timekeeping has been initialized. In that case there really is
      nothing we can do; jiffies hasn't even started ticking yet. So just give
      up and return 0.
      Suggested-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NJason A. Donenfeld <Jason@zx2c4.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Theodore Ts'o <tytso@mit.edu>
      1366992e
    • C
      security: declare member holding string literal const · 1af0e4a0
      Christian Göttsche 提交于
      The struct security_hook_list member lsm is assigned in
      security_add_hooks() with string literals passed from the individual
      security modules.  Declare the function parameter and the struct member
      const to signal their immutability.
      
      Reported by Clang [-Wwrite-strings]:
      
          security/selinux/hooks.c:7388:63: error: passing 'const char [8]'
            to parameter of type 'char *' discards qualifiers
            [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
                  security_add_hooks(selinux_hooks,
                                     ARRAY_SIZE(selinux_hooks), selinux);
                                                                ^~~~~~~~~
          ./include/linux/lsm_hooks.h:1629:11: note: passing argument to
            parameter 'lsm' here
                                          char *lsm);
                                                ^
      Signed-off-by: NChristian Göttsche <cgzones@googlemail.com>
      Reviewed-by: NPaul Moore <paul@paul-moore.com>
      Reviewed-by: NCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      1af0e4a0
  9. 13 5月, 2022 1 次提交
    • J
      io_uring: add flag for allocating a fully sparse direct descriptor space · a8da73a3
      Jens Axboe 提交于
      Currently to setup a fully sparse descriptor space upfront, the app needs
      to alloate an array of the full size and memset it to -1 and then pass
      that in. Make this a bit easier by allowing a flag that simply does
      this internally rather than needing to copy each slot separately.
      
      This works with IORING_REGISTER_FILES2 as the flag is set in struct
      io_uring_rsrc_register, and is only allow when the type is
      IORING_RSRC_FILE as this doesn't make sense for registered buffers.
      Reviewed-by: NHao Xu <howeyxu@tencent.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      a8da73a3