Browse Source

Merge branch 'freebsd/current/master' into hardened/current/master

* freebsd/current/master:
  [PowerPC] enable atomic.c in compiler_rt and do not check and forces lock/lock_free decisions in compiled time
  cron(8): use proper variable to determine mailer process status
  powerpc: Move ppc32_runtime_resolve() declaration to the right place
  Fix mount_nfs to recognize the NFSv4 specific errors returned by nmount(2).
  Merge commit d3aeac8e2 from llvm git (by Justin Hibbits)
  Change NFSv4.1 and NFSv4.2 error strings to start with lower case letter.
  Abstract the locking for PCIe hotplug.  It still uses Giant so there's no functional change yet.
  random(9): Deprecate random(9), remove meaningless srandom(9)
  random(4): Simplify RANDOM_LOADABLE
  gone_in(9): Trivial string grammar and style cleanups
hardened/current/master
HardenedBSD Sync Service 7 months ago
parent
commit
0724f11e75
27 changed files with 234 additions and 375 deletions
  1. +3
    -0
      UPDATING
  2. +7
    -0
      contrib/llvm-project/clang/lib/AST/ExprConstant.cpp
  3. +11
    -4
      contrib/llvm-project/compiler-rt/lib/builtins/atomic.c
  4. +6
    -1
      contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  5. +8
    -0
      lib/libcompiler_rt/Makefile.inc
  6. +11
    -5
      sbin/mount_nfs/mount_nfs.c
  7. +11
    -36
      share/man/man9/random.9
  8. +1
    -3
      sys/compat/ndis/subr_ntoskrnl.c
  9. +0
    -1
      sys/dev/oce/oce_mbox.c
  10. +9
    -6
      sys/dev/pci/pci_pci.c
  11. +5
    -0
      sys/dev/pci/pcib_private.h
  12. +10
    -17
      sys/dev/random/fortuna.c
  13. +11
    -26
      sys/dev/random/other_algorithm.c
  14. +2
    -23
      sys/dev/random/random_harvestq.c
  15. +4
    -108
      sys/dev/random/random_infra.c
  16. +26
    -39
      sys/dev/random/randomdev.c
  17. +6
    -16
      sys/dev/random/randomdev.h
  18. +46
    -46
      sys/fs/nfs/nfsv4_errstr.h
  19. +0
    -20
      sys/kern/init_main.c
  20. +2
    -2
      sys/kern/subr_bus.c
  21. +8
    -2
      sys/kern/subr_stats.c
  22. +12
    -13
      sys/libkern/random.c
  23. +2
    -1
      sys/powerpc/powerpc/elf32_machdep.c
  24. +0
    -1
      sys/sys/libkern.h
  25. +26
    -0
      sys/sys/random.h
  26. +1
    -1
      sys/sys/systm.h
  27. +6
    -4
      usr.sbin/cron/cron/do_command.c

+ 3
- 0
UPDATING View File

@@ -26,6 +26,9 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 13.x IS SLOW:
disable the most expensive debugging functionality run
"ln -s 'abort:false,junk:false' /etc/malloc.conf".)

20191226:
Kernel-loadable random(4) modules are no longer unloadable.

20191222:
Clang, llvm, lld, lldb, compiler-rt, libc++, libunwind and openmp have
been upgraded to 9.0.1. Please see the 20141231 entry below for

+ 7
- 0
contrib/llvm-project/clang/lib/AST/ExprConstant.cpp View File

@@ -9896,6 +9896,13 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
}
}

// Avoid emiting call for runtime decision on PowerPC 32-bit
// The lock free possibilities on this platform are covered by the lines
// above and we know in advance other cases require lock
if (Info.Ctx.getTargetInfo().getTriple().getArch() == llvm::Triple::ppc) {
return Success(0, E);
}

return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
Success(0, E) : Error(E);
}

+ 11
- 4
contrib/llvm-project/compiler-rt/lib/builtins/atomic.c View File

@@ -51,8 +51,8 @@ static const long SPINLOCK_MASK = SPINLOCK_COUNT - 1;
////////////////////////////////////////////////////////////////////////////////
#ifdef __FreeBSD__
#include <errno.h>
#include <machine/atomic.h>
#include <sys/types.h>
#include <machine/atomic.h>
#include <sys/umtx.h>
typedef struct _usem Lock;
__inline static void unlock(Lock *l) {
@@ -117,13 +117,20 @@ static __inline Lock *lock_for_pointer(void *ptr) {
return locks + (hash & SPINLOCK_MASK);
}

/// Macros for determining whether a size is lock free. Clang can not yet
/// codegen __atomic_is_lock_free(16), so for now we assume 16-byte values are
/// not lock free.
/// Macros for determining whether a size is lock free.
#define IS_LOCK_FREE_1 __c11_atomic_is_lock_free(1)
#define IS_LOCK_FREE_2 __c11_atomic_is_lock_free(2)
#define IS_LOCK_FREE_4 __c11_atomic_is_lock_free(4)

/// 32 bit PowerPC doesn't support 8-byte lock_free atomics
#if !defined(__powerpc64__) && defined(__powerpc__)
#define IS_LOCK_FREE_8 0
#else
#define IS_LOCK_FREE_8 __c11_atomic_is_lock_free(8)
#endif

/// Clang can not yet codegen __atomic_is_lock_free(16), so for now we assume
/// 16-byte values are not lock free.
#define IS_LOCK_FREE_16 0

/// Macro that calls the compiler-generated lock-free versions of functions

+ 6
- 1
contrib/llvm-project/llvm/lib/Target/PowerPC/PPCISelLowering.cpp View File

@@ -4952,7 +4952,12 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain,
if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee))
GV = G->getGlobal();
bool Local = TM.shouldAssumeDSOLocal(*Mod, GV);
bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64;
// The PLT is only used in 32-bit ELF PIC mode. Attempting to use the PLT in
// a static relocation model causes some versions of GNU LD (2.17.50, at
// least) to force BSS-PLT, instead of secure-PLT, even if all objects are
// built with secure-PLT.
bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64 &&
Subtarget.getTargetMachine().getRelocationModel() == Reloc::PIC_;

// If the callee is a GlobalAddress/ExternalSymbol node (quite common,
// every direct call is) turn it into a TargetGlobalAddress /

+ 8
- 0
lib/libcompiler_rt/Makefile.inc View File

@@ -205,6 +205,14 @@ CFLAGS+= -DEMIT_SYNC_ATOMICS
SRCF+= stdatomic
.endif


.if "${COMPILER_TYPE}" == "clang" && \
(${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpcspe")
SRCS+= atomic.c
CFLAGS.atomic.c+= -Wno-atomic-alignment
.endif


.for file in ${SRCF}
.if ${MACHINE_ARCH:Marmv[67]*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "") \
&& exists(${CRTSRC}/${CRTARCH}/${file}vfp.S)

+ 11
- 5
sbin/mount_nfs/mount_nfs.c View File

@@ -61,7 +61,8 @@ __FBSDID("$FreeBSD$");
#include <rpcsvc/nfs_prot.h>
#include <rpcsvc/mount.h>

#include <nfsclient/nfs.h>
#include <fs/nfs/nfsproto.h>
#include <fs/nfs/nfsv4_errstr.h>

#include <arpa/inet.h>

@@ -155,7 +156,7 @@ main(int argc, char *argv[])
char *mntname, *p, *spec, *tmp;
char mntpath[MAXPATHLEN], errmsg[255];
char hostname[MAXHOSTNAMELEN + 1], gssn[MAXHOSTNAMELEN + 50];
const char *gssname;
const char *gssname, *nmount_errstr;

iov = NULL;
iovlen = 0;
@@ -462,9 +463,14 @@ main(int argc, char *argv[])
build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1);
build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));

if (nmount(iov, iovlen, 0))
err(1, "nmount: %s%s%s", mntpath, errmsg[0] ? ", " : "",
errmsg);
if (nmount(iov, iovlen, 0)) {
nmount_errstr = nfsv4_geterrstr(errno);
if (mountmode == V4 && nmount_errstr != NULL)
errx(1, "nmount: %s, %s", mntpath, nmount_errstr);
else
err(1, "nmount: %s%s%s", mntpath, errmsg[0] ? ", " : "",
errmsg);
}

exit(0);
}

+ 11
- 36
share/man/man9/random.9 View File

@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\" "
.Dd April 16, 2019
.Dd December 26, 2019
.Dt RANDOM 9
.Os
.Sh NAME
@@ -36,8 +36,7 @@
.Nm is_random_seeded ,
.Nm random ,
.Nm read_random ,
.Nm read_random_uio ,
.Nm srandom
.Nm read_random_uio
.Nd supply pseudo-random numbers
.Sh SYNOPSIS
.In sys/libkern.h
@@ -57,8 +56,6 @@
.Fn read_random_uio "struct uio *uio" "bool nonblock"
.Ss LEGACY ROUTINES
.In sys/libkern.h
.Ft void
.Fn srandom "u_long seed"
.Ft u_long
.Fn random "void"
.Sh DESCRIPTION
@@ -134,19 +131,16 @@ Otherwise, this function may block interruptibly until the random device is seed
If the function is interrupted before the random device is seeded, no data is
returned.
.Pp
The legacy
.Fn random
function will produce a sequence of numbers that can be duplicated by calling
.Fn srandom
with some constant as the
.Fa seed .
The legacy
.Fn srandom
function may be called with any
.Fa seed
value.
The deprecated
.Xr random 9
function will produce a sequence of pseudorandom numbers using a similar weak
linear congruential generator as
.Xr rand 3
(the 1988 Park-Miller LCG).
It is obsolete and scheduled to be removed in
.Fx 13.0 .
It is strongly advised that the
.Fn random
.Xr random 9
function not be used to generate random numbers.
See
.Sx SECURITY CONSIDERATIONS .
@@ -173,23 +167,6 @@ the number of bytes placed in
.Fn read_random_uio
returns zero when successful,
otherwise an error code is returned.
.Pp
The legacy
.Fn random
function uses
a non-linear additive feedback random number generator
employing a default table
of size 31
containing long integers
to return successive pseudo-random
numbers in the range from 0 to
.if t 2\u\s731\s10\d\(mi1.
.if n (2**31)\(mi1.
The period of this random number generator
is very large,
approximately
.if t 16\(mu(2\u\s731\s10\d\(mi1).
.if n 16*((2**31)\(mi1).
.Sh ERRORS
.Fn read_random_uio
may fail if:
@@ -212,8 +189,6 @@ wrote
.Sh SECURITY CONSIDERATIONS
Do not use
.Fn random
or
.Fn srandom
in new code.
.Pp
It is important to remember that the

+ 1
- 3
sys/compat/ndis/subr_ntoskrnl.c View File

@@ -3195,10 +3195,8 @@ rand(void)
}

static void
srand(unsigned int seed)
srand(unsigned int seed __unused)
{

srandom(seed);
}

static uint8_t

+ 0
- 1
sys/dev/oce/oce_mbox.c View File

@@ -859,7 +859,6 @@ oce_config_nic_rss(POCE_SOFTC sc, uint32_t if_id, uint16_t enable_rss)

fwcmd->params.req.if_id = LE_32(if_id);

srandom(arc4random()); /* random entropy seed */
read_random(fwcmd->params.req.hash, sizeof(fwcmd->params.req.hash));
rc = oce_rss_itbl_init(sc, fwcmd);

+ 9
- 6
sys/dev/pci/pci_pci.c View File

@@ -1174,6 +1174,7 @@ pcib_pcie_intr_hotplug(void *arg)

sc = arg;
dev = sc->dev;
PCIB_HP_LOCK(sc);
old_slot_sta = sc->pcie_slot_sta;
sc->pcie_slot_sta = pcie_read_config(dev, PCIER_SLOT_STA, 2);

@@ -1221,6 +1222,7 @@ pcib_pcie_intr_hotplug(void *arg)
}

pcib_pcie_hotplug_update(sc, 0, 0, true);
PCIB_HP_UNLOCK(sc);
}

static void
@@ -1230,7 +1232,7 @@ pcib_pcie_hotplug_task(void *context, int pending)
device_t dev;

sc = context;
mtx_lock(&Giant);
PCIB_HP_LOCK(sc);
dev = sc->dev;
if (pcib_hotplug_present(sc) != 0) {
if (sc->child == NULL) {
@@ -1243,7 +1245,7 @@ pcib_pcie_hotplug_task(void *context, int pending)
sc->child = NULL;
}
}
mtx_unlock(&Giant);
PCIB_HP_UNLOCK(sc);
}

static void
@@ -1252,7 +1254,7 @@ pcib_pcie_ab_timeout(void *arg)
struct pcib_softc *sc;

sc = arg;
mtx_assert(&Giant, MA_OWNED);
PCIB_HP_LOCK_ASSERT(sc);
if (sc->flags & PCIB_DETACH_PENDING) {
sc->flags |= PCIB_DETACHING;
sc->flags &= ~PCIB_DETACH_PENDING;
@@ -1269,7 +1271,7 @@ pcib_pcie_cc_timeout(void *arg)

sc = arg;
dev = sc->dev;
mtx_assert(&Giant, MA_OWNED);
PCIB_HP_LOCK_ASSERT(sc);
sta = pcie_read_config(dev, PCIER_SLOT_STA, 2);
if (!(sta & PCIEM_SLOT_STA_CC)) {
device_printf(dev, "HotPlug Command Timed Out\n");
@@ -1290,7 +1292,7 @@ pcib_pcie_dll_timeout(void *arg)

sc = arg;
dev = sc->dev;
mtx_assert(&Giant, MA_OWNED);
PCIB_HP_LOCK_ASSERT(sc);
sta = pcie_read_config(dev, PCIER_LINK_STA, 2);
if (!(sta & PCIEM_LINK_STA_DL_ACTIVE)) {
device_printf(dev,
@@ -1345,7 +1347,7 @@ pcib_alloc_pcie_irq(struct pcib_softc *sc)
return (ENXIO);
}

error = bus_setup_intr(dev, sc->pcie_irq, INTR_TYPE_MISC,
error = bus_setup_intr(dev, sc->pcie_irq, INTR_TYPE_MISC|INTR_MPSAFE,
NULL, pcib_pcie_intr_hotplug, sc, &sc->pcie_ihand);
if (error) {
device_printf(dev, "Failed to setup PCI-e interrupt handler\n");
@@ -1384,6 +1386,7 @@ pcib_setup_hotplug(struct pcib_softc *sc)
callout_init(&sc->pcie_cc_timer, 0);
callout_init(&sc->pcie_dll_timer, 0);
TASK_INIT(&sc->pcie_hp_task, 0, pcib_pcie_hotplug_task, sc);
sc->pcie_hp_lock = &Giant;

/* Allocate IRQ. */
if (pcib_alloc_pcie_irq(sc) != 0)

+ 5
- 0
sys/dev/pci/pcib_private.h View File

@@ -141,8 +141,13 @@ struct pcib_softc
struct callout pcie_ab_timer;
struct callout pcie_cc_timer;
struct callout pcie_dll_timer;
struct mtx *pcie_hp_lock;
};

#define PCIB_HP_LOCK(sc) mtx_lock((sc)->pcie_hp_lock)
#define PCIB_HP_UNLOCK(sc) mtx_unlock((sc)->pcie_hp_lock)
#define PCIB_HP_LOCK_ASSERT(sc) mtx_assert((sc)->pcie_hp_lock, MA_OWNED)

#define PCIB_SUPPORTED_ARI_VER 1

typedef uint32_t pci_read_config_fn(int b, int s, int f, int reg, int width);

+ 10
- 17
sys/dev/random/fortuna.c View File

@@ -264,15 +264,14 @@ static void random_fortuna_read(uint8_t *, size_t);
static bool random_fortuna_seeded(void);
static bool random_fortuna_seeded_internal(void);
static void random_fortuna_process_event(struct harvest_event *);
static void random_fortuna_init_alg(void *);
static void random_fortuna_deinit_alg(void *);

static void random_fortuna_reseed_internal(uint32_t *entropy_data, u_int blockcount);

struct random_algorithm random_alg_context = {
#ifdef RANDOM_LOADABLE
static
#endif
const struct random_algorithm random_alg_context = {
.ra_ident = "Fortuna",
.ra_init_alg = random_fortuna_init_alg,
.ra_deinit_alg = random_fortuna_deinit_alg,
.ra_pre_read = random_fortuna_pre_read,
.ra_read = random_fortuna_read,
.ra_seeded = random_fortuna_seeded,
@@ -289,6 +288,10 @@ random_fortuna_init_alg(void *unused __unused)
struct sysctl_oid *random_fortuna_o;
#endif

#ifdef RANDOM_LOADABLE
p_random_alg_context = &random_alg_context;
#endif

RANDOM_RESEED_INIT_LOCK();
/*
* Fortuna parameters. Do not adjust these unless you have
@@ -333,18 +336,8 @@ random_fortuna_init_alg(void *unused __unused)
fortuna_state.fs_counter = UINT128_ZERO;
explicit_bzero(&fortuna_state.fs_key, sizeof(fortuna_state.fs_key));
}

/* ARGSUSED */
static void
random_fortuna_deinit_alg(void *unused __unused)
{

RANDOM_RESEED_DEINIT_LOCK();
explicit_bzero(&fortuna_state, sizeof(fortuna_state));
#ifdef _KERNEL
sysctl_ctx_free(&random_clist);
#endif
}
SYSINIT(random_alg, SI_SUB_RANDOM, SI_ORDER_SECOND, random_fortuna_init_alg,
NULL);

/*-
* FS&K - AddRandomEvent()

+ 11
- 26
sys/dev/random/other_algorithm.c View File

@@ -87,8 +87,6 @@ static void random_other_pre_read(void);
static void random_other_read(uint8_t *, size_t);
static bool random_other_seeded(void);
static void random_other_process_event(struct harvest_event *);
static void random_other_init_alg(void *);
static void random_other_deinit_alg(void *);

/*
* RANDOM_OTHER_NPOOLS is used when reading hardware random
@@ -97,10 +95,11 @@ static void random_other_deinit_alg(void *);
*/
#define RANDOM_OTHER_NPOOLS 1

struct random_algorithm random_alg_context = {
#ifdef RANDOM_LOADABLE
static
#endif
const struct random_algorithm random_alg_context = {
.ra_ident = "other",
.ra_init_alg = random_other_init_alg,
.ra_deinit_alg = random_other_deinit_alg,
.ra_pre_read = random_other_pre_read,
.ra_read = random_other_read,
.ra_seeded = random_other_seeded,
@@ -112,34 +111,20 @@ struct random_algorithm random_alg_context = {
static mtx_t other_mtx;

/*
* void random_other_init_alg(void *unused __unused)
*
* Do algorithm-specific initialisation here.
*/
void
static void
random_other_init_alg(void *unused __unused)
{

RANDOM_RESEED_INIT_LOCK();
/*
* Do set-up work here!
*/
}
#ifdef RANDOM_LOADABLE
p_random_alg_context = &random_alg_context;
#endif

/*
* void random_other_deinit_alg(void *unused __unused)
*
* Do algorithm-specific deinitialisation here.
*/
static void
random_other_deinit_alg(void *unused __unused)
{

/*
* Do tear-down work here!
*/
RANDOM_RESEED_DEINIT_LOCK();
RANDOM_RESEED_INIT_LOCK();
}
SYSINIT(random_alg, SI_SUB_RANDOM, SI_ORDER_SECOND, random_other_init_alg,
NULL);

/*
* void random_other_pre_read(void)

+ 2
- 23
sys/dev/random/random_harvestq.c View File

@@ -49,11 +49,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/unistd.h>

#if defined(RANDOM_LOADABLE)
#include <sys/lock.h>
#include <sys/sx.h>
#endif

#include <machine/atomic.h>
#include <machine/cpu.h>

@@ -163,14 +158,7 @@ static struct kproc_desc random_proc_kp = {
static __inline void
random_harvestq_fast_process_event(struct harvest_event *event)
{
#if defined(RANDOM_LOADABLE)
RANDOM_CONFIG_S_LOCK();
if (p_random_alg_context)
#endif
p_random_alg_context->ra_event_processor(event);
#if defined(RANDOM_LOADABLE)
RANDOM_CONFIG_S_UNLOCK();
#endif
explicit_bzero(event, sizeof(*event));
}

@@ -230,11 +218,6 @@ random_sources_feed(void)
* Step over all of live entropy sources, and feed their output
* to the system-wide RNG.
*/
#if defined(RANDOM_LOADABLE)
RANDOM_CONFIG_S_LOCK();
if (p_random_alg_context) {
/* It's an indenting error. Yeah, Yeah. */
#endif
local_read_rate = atomic_readandclear_32(&read_rate);
/* Perform at least one read per round */
local_read_rate = MAX(local_read_rate, 1);
@@ -261,10 +244,6 @@ random_sources_feed(void)
}
}
explicit_bzero(entropy, sizeof(entropy));
#if defined(RANDOM_LOADABLE)
}
RANDOM_CONFIG_S_UNLOCK();
#endif
}

void
@@ -396,7 +375,7 @@ random_harvestq_init(void *unused __unused)
RANDOM_HARVEST_INIT_LOCK();
harvest_context.hc_entropy_ring.in = harvest_context.hc_entropy_ring.out = 0;
}
SYSINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_SECOND, random_harvestq_init, NULL);
SYSINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_THIRD, random_harvestq_init, NULL);

/*
* Subroutine to slice up a contiguous chunk of 'entropy' and feed it into the
@@ -485,7 +464,7 @@ random_harvestq_deinit(void *unused __unused)
while (random_kthread_control >= 0)
tsleep(&harvest_context.hc_kthread_proc, 0, "harvqterm", hz/5);
}
SYSUNINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_SECOND, random_harvestq_deinit, NULL);
SYSUNINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_THIRD, random_harvestq_deinit, NULL);

/*-
* Entropy harvesting queue routine.

+ 4
- 108
sys/dev/random/random_infra.c View File

@@ -35,11 +35,6 @@ __FBSDID("$FreeBSD$");
#include <sys/random.h>
#include <sys/sysctl.h>

#if defined(RANDOM_LOADABLE)
#include <sys/lock.h>
#include <sys/sx.h>
#endif

#include <dev/random/randomdev.h>

/* Set up the sysctl root node for the entropy device */
@@ -102,107 +97,8 @@ SYSCTL_BOOL(_kern_random_initial_seeding, OID_AUTO,
MALLOC_DEFINE(M_ENTROPY, "entropy", "Entropy harvesting buffers and data structures");

#if defined(RANDOM_LOADABLE)
struct random_algorithm *p_random_alg_context = NULL;
#else /* !defined(RANDOM_LOADABLE) */
struct random_algorithm *p_random_alg_context = &random_alg_context;
#endif /* defined(RANDOM_LOADABLE) */

#if defined(RANDOM_LOADABLE)

static void
null_read_random(void *dummy __unused, u_int dummy2 __unused)
{
panic("%s: no random module is loaded", __func__);
}

static bool
null_is_random_seeded(void)
{
return (false);
}

struct random_readers {
int (*read_random_uio)(struct uio *, bool);
void (*read_random)(void *, u_int);
bool (*is_random_seeded)(void);
} random_reader_context = {
(int (*)(struct uio *, bool))nullop,
null_read_random,
null_is_random_seeded,
};

struct sx randomdev_config_lock;

static void
random_infra_sysinit(void *dummy __unused)
{

RANDOM_CONFIG_INIT_LOCK();
}
SYSINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_FIRST, random_infra_sysinit, NULL);

void
random_infra_init(int (*p_random_read_uio)(struct uio *, bool),
void (*p_random_read)(void *, u_int),
bool (*p_is_random_seeded)(void))
{

RANDOM_CONFIG_X_LOCK();
random_reader_context.read_random_uio = p_random_read_uio;
random_reader_context.read_random = p_random_read;
random_reader_context.is_random_seeded = p_is_random_seeded;
RANDOM_CONFIG_X_UNLOCK();
}

void
random_infra_uninit(void)
{

RANDOM_CONFIG_X_LOCK();
random_reader_context.read_random_uio = (int (*)(struct uio *, bool))nullop;
random_reader_context.read_random = null_read_random;
random_reader_context.is_random_seeded = null_is_random_seeded;
RANDOM_CONFIG_X_UNLOCK();
}

static void
random_infra_sysuninit(void *dummy __unused)
{

RANDOM_CONFIG_DEINIT_LOCK();
}
SYSUNINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_FIRST, random_infra_sysuninit, NULL);

int
read_random_uio(struct uio *uio, bool nonblock)
{
int retval;

RANDOM_CONFIG_S_LOCK();
retval = random_reader_context.read_random_uio(uio, nonblock);
RANDOM_CONFIG_S_UNLOCK();
return (retval);
}

void
read_random(void *buf, u_int len)
{

RANDOM_CONFIG_S_LOCK();
random_reader_context.read_random(buf, len);
RANDOM_CONFIG_S_UNLOCK();
}

bool
is_random_seeded(void)
{
bool result;

RANDOM_CONFIG_S_LOCK();
result = random_reader_context.is_random_seeded();
RANDOM_CONFIG_S_UNLOCK();
return (result);
}


const struct random_algorithm *p_random_alg_context;
void (*_read_random)(void *, u_int);
int (*_read_random_uio)(struct uio *, bool);
bool (*_is_random_seeded)(void);
#endif /* defined(RANDOM_LOADABLE) */

+ 26
- 39
sys/dev/random/randomdev.c View File

@@ -59,17 +59,17 @@ __FBSDID("$FreeBSD$");

#define RANDOM_UNIT 0

/*
* In loadable random, the core randomdev.c / random(9) routines have static
* visibility and an alternative name to avoid conflicting with the function
* pointers of the real names in the core kernel. random_alg_context_init
* installs pointers to the loadable static names into the core kernel's
* function pointers at SI_SUB_RANDOM:SI_ORDER_SECOND.
*/
#if defined(RANDOM_LOADABLE)
#define READ_RANDOM_UIO _read_random_uio
#define READ_RANDOM _read_random
#define IS_RANDOM_SEEDED _is_random_seeded
static int READ_RANDOM_UIO(struct uio *, bool);
static void READ_RANDOM(void *, u_int);
static bool IS_RANDOM_SEEDED(void);
#else
#define READ_RANDOM_UIO read_random_uio
#define READ_RANDOM read_random
#define IS_RANDOM_SEEDED is_random_seeded
static int (read_random_uio)(struct uio *, bool);
static void (read_random)(void *, u_int);
static bool (is_random_seeded)(void);
#endif

static d_read_t randomdev_read;
@@ -89,30 +89,17 @@ static struct cdevsw random_cdevsw = {
/* For use with make_dev(9)/destroy_dev(9). */
static struct cdev *random_dev;

static void
random_alg_context_ra_init_alg(void *data)
{

p_random_alg_context = &random_alg_context;
p_random_alg_context->ra_init_alg(data);
#if defined(RANDOM_LOADABLE)
random_infra_init(READ_RANDOM_UIO, READ_RANDOM, IS_RANDOM_SEEDED);
#endif
}

static void
random_alg_context_ra_deinit_alg(void *data)
random_alg_context_init(void *dummy __unused)
{

#if defined(RANDOM_LOADABLE)
random_infra_uninit();
#endif
p_random_alg_context->ra_deinit_alg(data);
p_random_alg_context = NULL;
_read_random_uio = (read_random_uio);
_read_random = (read_random);
_is_random_seeded = (is_random_seeded);
}
SYSINIT(random_device, SI_SUB_RANDOM, SI_ORDER_THIRD, random_alg_context_ra_init_alg, NULL);
SYSUNINIT(random_device, SI_SUB_RANDOM, SI_ORDER_THIRD, random_alg_context_ra_deinit_alg, NULL);
SYSINIT(random_device, SI_SUB_RANDOM, SI_ORDER_SECOND, random_alg_context_init,
NULL);
#endif

static struct selinfo rsel;

@@ -124,7 +111,7 @@ static int
randomdev_read(struct cdev *dev __unused, struct uio *uio, int flags)
{

return (READ_RANDOM_UIO(uio, (flags & O_NONBLOCK) != 0));
return ((read_random_uio)(uio, (flags & O_NONBLOCK) != 0));
}

/*
@@ -154,7 +141,7 @@ randomdev_wait_until_seeded(bool interruptible)
if (spamcount == 0)
printf("random: %s unblock wait\n", __func__);
spamcount = (spamcount + 1) % 100;
error = tsleep(&random_alg_context, slpflags, "randseed",
error = tsleep(p_random_alg_context, slpflags, "randseed",
hz / 10);
if (error == ERESTART || error == EINTR) {
KASSERT(interruptible,
@@ -170,7 +157,7 @@ randomdev_wait_until_seeded(bool interruptible)
}

int
READ_RANDOM_UIO(struct uio *uio, bool nonblock)
(read_random_uio)(struct uio *uio, bool nonblock)
{
/* 16 MiB takes about 0.08 s CPU time on my 2017 AMD Zen CPU */
#define SIGCHK_PERIOD (16 * 1024 * 1024)
@@ -238,7 +225,7 @@ READ_RANDOM_UIO(struct uio *uio, bool nonblock)
*/
if (error == 0 && uio->uio_resid != 0 &&
total_read % sigchk_period == 0) {
error = tsleep_sbt(&random_alg_context, PCATCH,
error = tsleep_sbt(p_random_alg_context, PCATCH,
"randrd", SBT_1NS, 0, C_HARDCLOCK);
/* Squash tsleep timeout condition */
if (error == EWOULDBLOCK)
@@ -271,7 +258,7 @@ READ_RANDOM_UIO(struct uio *uio, bool nonblock)
* 'kern.random.initial_seeding.read_random_bypassed_before_seeding'.
*/
void
READ_RANDOM(void *random_buf, u_int len)
(read_random)(void *random_buf, u_int len)
{

KASSERT(random_buf != NULL, ("No suitable random buffer in %s", __func__));
@@ -305,7 +292,7 @@ READ_RANDOM(void *random_buf, u_int len)
}

bool
IS_RANDOM_SEEDED(void)
(is_random_seeded)(void)
{
return (p_random_alg_context->ra_seeded());
}
@@ -356,7 +343,7 @@ randomdev_write(struct cdev *dev __unused, struct uio *uio, int flags __unused)
if (error)
break;
randomdev_accumulate(random_buf, c);
tsleep(&random_alg_context, 0, "randwr", hz/10);
tsleep(p_random_alg_context, 0, "randwr", hz/10);
}
if (nbytes != uio->uio_resid && (error == ERESTART || error == EINTR))
/* Partial write, not error. */
@@ -385,7 +372,7 @@ randomdev_unblock(void)
{

selwakeuppri(&rsel, PUSER);
wakeup(&random_alg_context);
wakeup(p_random_alg_context);
printf("random: unblocking device.\n");
/* Do random(9) a favour while we are about it. */
(void)atomic_cmpset_int(&arc4rand_iniseed_state, ARC4_ENTR_NONE, ARC4_ENTR_HAVE);
@@ -424,7 +411,7 @@ randomdev_modevent(module_t mod __unused, int type, void *data __unused)
make_dev_alias(random_dev, "urandom"); /* compatibility */
break;
case MOD_UNLOAD:
destroy_dev(random_dev);
error = EBUSY;
break;
case MOD_SHUTDOWN:
break;

+ 6
- 16
sys/dev/random/randomdev.h View File

@@ -79,15 +79,18 @@ typedef u_int random_source_read_t(void *, u_int);
struct random_algorithm {
const char *ra_ident;
u_int ra_poolcount;
void (*ra_init_alg)(void *);
void (*ra_deinit_alg)(void *);
random_alg_pre_read_t *ra_pre_read;
random_alg_read_t *ra_read;
random_alg_seeded_t *ra_seeded;
random_alg_eventprocessor_t *ra_event_processor;
};

extern struct random_algorithm random_alg_context, *p_random_alg_context;
#if defined(RANDOM_LOADABLE)
extern const struct random_algorithm *p_random_alg_context;
#else
extern const struct random_algorithm random_alg_context;
#define p_random_alg_context (&random_alg_context)
#endif

#ifdef _KERNEL

@@ -105,19 +108,6 @@ struct random_source {
void random_source_register(struct random_source *);
void random_source_deregister(struct random_source *);

#if defined(RANDOM_LOADABLE)
extern struct sx randomdev_config_lock;
#define RANDOM_CONFIG_INIT_LOCK(x) sx_init(&randomdev_config_lock, "configuration change lock")
#define RANDOM_CONFIG_X_LOCK(x) sx_xlock(&randomdev_config_lock)
#define RANDOM_CONFIG_X_UNLOCK(x) sx_xunlock(&randomdev_config_lock)
#define RANDOM_CONFIG_S_LOCK(x) sx_slock(&randomdev_config_lock)
#define RANDOM_CONFIG_S_UNLOCK(x) sx_sunlock(&randomdev_config_lock)
#define RANDOM_CONFIG_DEINIT_LOCK(x) sx_destroy(&randomdev_config_lock)
void random_infra_init(int (*)(struct uio *, bool), void (*)(void *, u_int),
bool (*)(void));
void random_infra_uninit(void);
#endif

#endif /* _KERNEL */

void randomdev_unblock(void);

+ 46
- 46
sys/fs/nfs/nfsv4_errstr.h View File

@@ -85,54 +85,54 @@ static const char *nfsv4_errstr[NFSERR_XATTR2BIG - 10000] = {
"open file blocks op",
"lockowner state revoked",
"callback path down"
"Bad IO mode",
"Bad layout",
"Bad session digest",
"Bad session",
"Bad slot",
"Complete already",
"Not bound to session",
"Delegation already wanted",
"Back channel busy",
"Layout try later",
"Layout unavailable",
"No matching layout",
"Recall conflict",
"Unknown layout type",
"Sequence misordered",
"Sequence position",
"Request too big",
"Reply too big",
"Reply too big to cache",
"Retry uncached reply",
"Unsafe compound",
"Too many operations",
"Operation not in session",
"Hash algorithm unsupported",
"Unknown error",
"ClientID busy",
"bad IO mode",
"bad layout",
"bad session digest",
"bad session",
"bad slot",
"complete already",
"not bound to session",
"delegation already wanted",
"back channel busy",
"layout try later",
"layout unavailable",
"no matching layout",
"recall conflict",
"unknown layout type",
"sequence misordered",
"sequence position",
"request too big",
"reply too big",
"reply too big to cache",
"retry uncached reply",
"unsafe compound",
"too many operations",
"operation not in session",
"hash algorithm unsupported",
"unknown error",
"clientID busy",
"pNFS IO hole",
"Sequence false retry",
"Bad high slot",
"Dead session",
"Encrypt algorithm unsupported",
"sequence false retry",
"bad high slot",
"dead session",
"encrypt algorithm unsupported",
"pNFS no layout",
"Not only operation",
"Wrong credential",
"Wrong type",
"Directory delegation unavailable",
"Reject delegation",
"Return conflict",
"Delegation revoked",
"Partner not supported",
"Partner no auth",
"Union not supported",
"Offload denied",
"Wrong LFS",
"Bad label",
"Offload no request",
"No extended attribute",
"Extended attribute too big",
"not only operation",
"wrong credential",
"wrong type",
"directory delegation unavailable",
"reject delegation",
"return conflict",
"delegation revoked",
"partner not supported",
"partner no auth",
"union not supported",
"offload denied",
"wrong LFS",
"bad label",
"offload no request",
"no extended attribute",
"extended attribute too big",
};

/*

+ 0
- 20
sys/kern/init_main.c View File

@@ -635,7 +635,6 @@ SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL);
static void
proc0_post(void *dummy __unused)
{
struct timespec ts;
struct proc *p;
struct rusage ru;
struct thread *td;
@@ -667,28 +666,9 @@ proc0_post(void *dummy __unused)
sx_sunlock(&allproc_lock);
PCPU_SET(switchtime, cpu_ticks());
PCPU_SET(switchticks, ticks);

/*
* Give the ``random'' number generator a thump.
*/
nanotime(&ts);
srandom(ts.tv_sec ^ ts.tv_nsec);
}
SYSINIT(p0post, SI_SUB_INTRINSIC_POST, SI_ORDER_FIRST, proc0_post, NULL);

static void
random_init(void *dummy __unused)
{

/*
* After CPU has been started we have some randomness on most
* platforms via get_cyclecount(). For platforms that don't
* we will reseed random(9) in proc0_post() as well.
*/
srandom(get_cyclecount());
}
SYSINIT(random, SI_SUB_RANDOM, SI_ORDER_FIRST, random_init, NULL);

/*
***************************************************************************
****

+ 2
- 2
sys/kern/subr_bus.c View File

@@ -5971,7 +5971,7 @@ _gone_in(int major, const char *msg)

gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg);
if (P_OSREL_MAJOR(__FreeBSD_version) >= major)
printf("Obsolete code will removed soon: %s\n", msg);
printf("Obsolete code will be removed soon: %s\n", msg);
else
printf("Deprecated code (to be removed in FreeBSD %d): %s\n",
major, msg);
@@ -5984,7 +5984,7 @@ _gone_in_dev(device_t dev, int major, const char *msg)
gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg);
if (P_OSREL_MAJOR(__FreeBSD_version) >= major)
device_printf(dev,
"Obsolete code will removed soon: %s\n", msg);
"Obsolete code will be removed soon: %s\n", msg);
else
device_printf(dev,
"Deprecated code (to be removed in FreeBSD %d): %s\n",

+ 8
- 2
sys/kern/subr_stats.c View File

@@ -2963,7 +2963,14 @@ stats_v1_vsd_tdgst_compress(enum vsd_dtype vs_dtype,
* re-inserting the mu/cnt of each as a value and corresponding weight.
*/

#define bitsperrand 31 /* Per random(3). */
/*
* XXXCEM: random(9) is currently rand(3), not random(3). rand(3)
* RAND_MAX happens to be approximately 31 bits (range [0,
* 0x7ffffffd]), so the math kinda works out. When/if this portion of
* the code is compiled in userspace, it gets the random(3) behavior,
* which has expected range [0, 0x7fffffff].
*/
#define bitsperrand 31
ebits = 0;
nebits = 0;
bitsperidx = fls(maxctds);
@@ -2971,7 +2978,6 @@ stats_v1_vsd_tdgst_compress(enum vsd_dtype vs_dtype,
("%s: bitsperidx=%d, ebits=%d",
__func__, bitsperidx, (int)(sizeof(ebits) << 3)));
idxmask = (UINT64_C(1) << bitsperidx) - 1;
srandom(stats_sbinuptime());

/* Initialise the free list with randomised centroid indices. */
for (; remctds > 0; remctds--) {

+ 12
- 13
sys/libkern/random.c View File

@@ -34,32 +34,31 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/types.h>
#include <sys/libkern.h>

#define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */
#include <sys/systm.h>

static u_long randseed = 937186357; /* after srandom(1), NSHUFF counted */

void
srandom(u_long seed)
{
int i;

randseed = seed;
for (i = 0; i < NSHUFF; i++)
(void)random();
}

/*
* Pseudo-random number generator for perturbing the profiling clock,
* and whatever else we might use it for. The result is uniform on
* [0, 2^31 - 1].
*/
u_long
random()
random(void)
{
static bool warned = false;

long x, hi, lo, t;

/* Warn only once, or it gets very spammy. */
if (!warned) {
gone_in(13,
"random(9) is the obsolete Park-Miller LCG from 1988");
warned = true;
}

/*
* Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1).
* From "Random number generators: good ones are hard to find",

+ 2
- 1
sys/powerpc/powerpc/elf32_machdep.c View File

@@ -66,7 +66,6 @@

extern const char *freebsd32_syscallnames[];
static void ppc32_fixlimit(struct rlimit *rl, int which);
static void ppc32_runtime_resolve(void);

static SYSCTL_NODE(_compat, OID_AUTO, ppc32, CTLFLAG_RW, 0, "32-bit mode");

@@ -78,6 +77,8 @@ SYSCTL_ULONG(_compat_ppc32, OID_AUTO, maxdsiz, CTLFLAG_RWTUN, &ppc32_maxdsiz,
u_long ppc32_maxssiz = PPC32_MAXSSIZ;
SYSCTL_ULONG(_compat_ppc32, OID_AUTO, maxssiz, CTLFLAG_RWTUN, &ppc32_maxssiz,
0, "");
#else
static void ppc32_runtime_resolve(void);
#endif

struct sysentvec elf32_freebsd_sysvec = {

+ 0
- 1
sys/sys/libkern.h View File

@@ -166,7 +166,6 @@ void qsort_r(void *base, size_t nmemb, size_t size, void *thunk,
int (*compar)(void *, const void *, const void *));
u_long random(void);
int scanc(u_int, const u_char *, const u_char *, int);
void srandom(u_long);
int strcasecmp(const char *, const char *);
char *strcat(char * __restrict, const char * __restrict);
char *strchr(const char *, int);

+ 26
- 0
sys/sys/random.h View File

@@ -37,9 +37,35 @@

struct uio;

/*
* In the loadable random world, there are set of dangling pointers left in the
* core kernel:
* * read_random, read_random_uio, is_random_seeded are function pointers,
* rather than functions.
* * p_random_alg_context is a true pointer in loadable random kernels.
*
* These are initialized at SI_SUB_RANDOM:SI_ORDER_SECOND during boot. The
* read-type pointers are initialized by random_alg_context_init() in
* randomdev.c and p_random_alg_context in the algorithm, e.g., fortuna.c's
* random_fortuna_init_alg(). The nice thing about function pointers is they
* have a similar calling convention to ordinary functions.
*
* (In !loadable, the read_random, etc, routines are just plain functions;
* p_random_alg_context is a macro for the public visibility
* &random_alg_context.)
*/
#if defined(RANDOM_LOADABLE)
extern void (*_read_random)(void *, u_int);
extern int (*_read_random_uio)(struct uio *, bool);
extern bool (*_is_random_seeded)(void);
#define read_random(a, b) (*_read_random)(a, b)
#define read_random_uio(a, b) (*_read_random_uio)(a, b)
#define is_random_seeded() (*_is_random_seeded)()
#else
void read_random(void *, u_int);
int read_random_uio(struct uio *, bool);
bool is_random_seeded(void);
#endif

/*
* Note: if you add or remove members of random_entropy_source, remember to

+ 1
- 1
sys/sys/systm.h View File

@@ -593,7 +593,7 @@ void _gone_in_dev(struct device *dev, int major, const char *msg);
#ifdef NO_OBSOLETE_CODE
#define __gone_ok(m, msg) \
_Static_assert(m < P_OSREL_MAJOR(__FreeBSD_version)), \
"Obsolete code" msg);
"Obsolete code: " msg);
#else
#define __gone_ok(m, msg)
#endif

+ 6
- 4
usr.sbin/cron/cron/do_command.c View File

@@ -460,6 +460,8 @@ child_process(e, u)
_exit(ERROR_EXIT);
}

mail = NULL;

ch = getc(in);
if (ch != EOF) {
Debug(DPROC|DEXT,
@@ -531,7 +533,7 @@ child_process(e, u)

while (EOF != (ch = getc(in))) {
bytes++;
if (mailto)
if (mail)
putc(ch, mail);
}
}
@@ -555,12 +557,12 @@ child_process(e, u)
*/
if (WIFEXITED(waiter) && WEXITSTATUS(waiter) == 0
&& (e->flags & MAIL_WHEN_ERR) == MAIL_WHEN_ERR
&& mailto) {
&& mail) {
Debug(DPROC, ("[%d] %s executed successfully, mail suppressed\n",
getpid(), "grandchild command job"))
kill(mailpid, SIGKILL);
(void)fclose(mail);
mailto = NULL;
mail = NULL;
}


@@ -568,7 +570,7 @@ child_process(e, u)
* mailing...
*/

if (mailto) {
if (mail) {
Debug(DPROC, ("[%d] closing pipe to mail\n",
getpid()))
/* Note: the pclose will probably see

Loading…
Cancel
Save