]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
7 years agoMFC r315272, r315370
delphij [Wed, 31 May 2017 05:10:03 +0000 (05:10 +0000)]
MFC r315272, r315370

r315272:
Implement INHERIT_ZERO for minherit(2).

INHERIT_ZERO is an OpenBSD feature.

When a page is marked as such, it would be zeroed
upon fork().

This would be used in new arc4random(3) functions.

PR: 182610
Reviewed by: kib (earlier version)
Differential Revision: https://reviews.freebsd.org/D427

r315370:
The adj_free and max_free values of new_entry will be calculated and
assigned by subsequent vm_map_entry_link(), therefore, remove the
pointless copying.

Submitted by: alc

7 years agoMFC r315615:
delphij [Wed, 31 May 2017 05:05:32 +0000 (05:05 +0000)]
MFC r315615:

Make space style consistent with earlier entries.

7 years agoMFC r318975:
delphij [Wed, 31 May 2017 05:00:02 +0000 (05:00 +0000)]
MFC r318975:

Tighten /entropy permissions.

PR: 219527
Reported by: Lu Tung-Pin <lutungpin at openmailbox.org>
Submitted by: jilles

7 years agoMFC r318774:
np [Wed, 31 May 2017 00:43:34 +0000 (00:43 +0000)]
MFC r318774:

cxgbe/iw_cxgbe: sodisconnect failures are harmless and should not be
treated as fatal errors.

Sponsored by: Chelsio Communications

7 years agoMFC r318762:
np [Wed, 31 May 2017 00:16:05 +0000 (00:16 +0000)]
MFC r318762:

cxgbe(4): Update the T4, T5, and T6 firmwares to 1.16.45.0.

The latest firmware has a number of link related fixes, support for a
new custom card, and the fix for a bug that affected rate limiting on
FreeBSD.

Relnotes: Yes
Sponsored by: Chelsio Communications

7 years agoMFC r314176 and r318973.
np [Tue, 30 May 2017 21:55:48 +0000 (21:55 +0000)]
MFC r314176 and r318973.

r314176:
Add support for RDMA from userspace with T6 cards.

r318973:
libcxgb4: Use memcpy instead of copying WRs 8B at a time in the userspace
RDMA library for cxgbe(4).

Sponsored by: Chelsio Communications

7 years agoRegenerate src.conf(5)
ngie [Tue, 30 May 2017 18:08:33 +0000 (18:08 +0000)]
Regenerate src.conf(5)

7 years agoMFC r313169,r319246:
ngie [Tue, 30 May 2017 18:04:55 +0000 (18:04 +0000)]
MFC r313169,r319246:

r313169 (by wblock):

Clarify some option descriptions, add a line of text to makeman to
add the slightest hint of a shade of a clue of what it does.

r319246:

Use .Xr to reference libblacklist(3), blacklistctl(8), and blacklistd(8)

7 years agoMFC r317168:
ngie [Tue, 30 May 2017 17:47:19 +0000 (17:47 +0000)]
MFC r317168:

Add a knob, WITH*_RPCBIND_WARMSTART_SUPPORT, to allow the end-user to build
rpcbind(8) with/without warmstart support.

The knob defaults to off to preserve POLA for the feature.

See rpcbind(8) for more details about the warmstart feature.

Relnotes: yes

7 years agoMFC r317155,r317162,r317163,r317164:
ngie [Tue, 30 May 2017 17:37:40 +0000 (17:37 +0000)]
MFC r317155,r317162,r317163,r317164:

r317155:

rpcbind(8): wordsmith -h description and mention -W in the SYNOPSIS section

-W was already documented in the OPTIONS section.

r317162:

rpcbind(8): add a description for /var/run/rpcbind.sock under the FILES section

r317163:

rpcbind(8): post-humously document -w (warmstart) support added in r74462

warmstart support saves portmap/rpcbind(8) registration state on exit and
restores the saved registration state on restart.

r317164:

Fix indentation per style.Makefile(5)

7 years agoMFC r318305: makeman: reword description, based on feedback from wblock
emaste [Tue, 30 May 2017 17:09:47 +0000 (17:09 +0000)]
MFC r318305: makeman: reword description, based on feedback from wblock

7 years agoMFC arch.7 man page describing some arch-specific details
emaste [Tue, 30 May 2017 17:07:40 +0000 (17:07 +0000)]
MFC arch.7 man page describing some arch-specific details

MFC of r318386, r317938, r317844, r317843, r317840, r317835, r317809,
       r317790, r317754, r317708, r317681, r312563, r308251, r308130,
       r307687, r303153, r303134, r303045, r303044, r303033
Changes by br, emaste, jhb, jhibbits, kevlo, kib

Sponsored by: The FreeBSD Foundation

7 years agoMFC r318316: uniq: allow -c to be used with -d or -u
emaste [Tue, 30 May 2017 16:55:15 +0000 (16:55 +0000)]
MFC r318316: uniq: allow -c to be used with -d or -u

Bring in some bits from NetBSD and lift the restriction in uniq(1) that
-c cannot be used with the -d and -u options.  This restriction seems
unnecessary and is supported at least by GNU, OpenBSD, and NetBSD.  Lift
the restriction and simplify the show() logic a little bit to maintain
functionality when -c is provided with -d/-u.

Also with this change, -d and -u are now actually a mutually exclusive,
albeit valid, combination.  Given that they both indicate opposite
behavior, uniq(1) will no longer output anything if both -d and -u are
supplied.  This is in line with NetBSD as well as GNU.

Adjust the man page and usage() to reflect that -c is its own standalone
option.

PR: 200553
Submitted by: Kyle Evans <kevans91@ksu.edu>

7 years agoMFC r318689: Add parent interface reference counting to if_vlan.
mav [Tue, 30 May 2017 16:34:18 +0000 (16:34 +0000)]
MFC r318689: Add parent interface reference counting to if_vlan.

Using plain ifunit() looks like a request for troubles.

7 years agoMFC r318593:
asomers [Tue, 30 May 2017 15:33:27 +0000 (15:33 +0000)]
MFC r318593:

Fix build of AIO tests with -DDEBUG

Also, redefine some constants for clarity.  No functional change.

7 years agoMFC r318141, r318143-r318144
asomers [Tue, 30 May 2017 15:18:22 +0000 (15:18 +0000)]
MFC r318141, r318143-r318144

r318141:
strcpy => strlcpy

Reported by: Coverity
CID: 1352771
Sponsored by: Spectra Logic Corp

r318143:
strcpy => strlcpy

Reported by: Coverity
CID: 1006715
Sponsored by: Spectra Logic Corp

r318144:
Don't depend on assert(3) getting evaluated

Reported by: imp
X-MFC-With: 318141, 318143
Sponsored by: Spectra Logic Corp

7 years agoMFC r307334, r318252: Support write-through caches on arm64
andrew [Tue, 30 May 2017 13:56:38 +0000 (13:56 +0000)]
MFC r307334, r318252: Support write-through caches on arm64

r307334:
Create macros for the MAIR memory attributes. While here add an uncached
memory type, however the VM code still needs to be taught about this.

r318252:
Add the VM_MEMATTR_WRITE_THROUGH memory type to arm64 and use it to support
VM_MEMATTR_WRITE_COMBINING in the kernel. This fixes a bug where Xorg would
use write back cached memory for its graphics buffers. This would produce
artifacts on the screen as cachelines were written to memory.

7 years agoMFC r317824:
andrew [Tue, 30 May 2017 13:35:54 +0000 (13:35 +0000)]
MFC r317824:

Add reclaim_pv_chunk on arm64. This is based on the amd64 code so should
operate similarly, other than not needing the delayed invalidation.

It has been tested with artificial injection of vm_page_alloc failures
while running 'sort /dev/zero'.

7 years agoMFC r317361:
andrew [Tue, 30 May 2017 13:26:37 +0000 (13:26 +0000)]
MFC r317361:

Call the PSCI reset from cpu_reset on arm64. When rebooting from DDB the
kernel calls this directly so the event handler is not called, meaning
the computer fails to reboot.

7 years agoMFC r317197:
andrew [Tue, 30 May 2017 13:21:43 +0000 (13:21 +0000)]
MFC r317197:

Restrict the arm64 supervisor all instructions to only allow a zero
immediate value for system calls. We may wish to use other values in the
future for other purposes.

7 years agoMFC r317192:
andrew [Tue, 30 May 2017 13:16:06 +0000 (13:16 +0000)]
MFC r317192:

Push loading curthread into assembly in the synchronous exception handlers.
This will help investigating the performance impact of moving parts of the
switch statement in do_el0_sync into assembly.

7 years agoMFC r313396:
andrew [Tue, 30 May 2017 13:02:10 +0000 (13:02 +0000)]
MFC r313396:

Push reading of ESR_EL1 to assembly. Among other uses this will allow us
to expose this to signal handlers, e.g. for the clang sanitizers.

7 years agoMFC r316734, r316761: Support Execute-Never bit in the arm64 pmap.
andrew [Tue, 30 May 2017 12:44:01 +0000 (12:44 +0000)]
MFC r316734, r316761: Support Execute-Never bit in the arm64 pmap.

r316734:
Start to use the User and Privileged execute-never bits in the arm64
pagetables. This sets both bits when entering an address we know shouldn't
be executed.

I expect we could mark all userspace pages as Privileged execute-never to
ensure the kernel doesn't branch to one of these addresses.

While here add the ARMv8.1 upper attributes.

r316761:
Set the arm64 Execute-never bits in more places.

We need to set the Execute-never bits when mapping device memory as the
hardware may perform speculative instruction fetches.

Set the Privileged Execute-ever bit on userspace memory to stop the kernel
if it is tricked into executing it.

7 years agoMFC r316732, r316756: Enable Privileged Access Never on arm64.
andrew [Tue, 30 May 2017 12:26:36 +0000 (12:26 +0000)]
MFC r316732, r316756: Enable Privileged Access Never on arm64.

r316732:
Use the unprivileged variant of the load and store instructions most
places possible in the kernel. This forces these functions to fail if
userspace is unable to access a given memory location, even if it is in
the user memory range.

This will simplify adding Privileged Access Never support later.

r316756:
In ARMv8.1 ARM has added a process state bit to disable access to userspace
from the kernel. Make use of this to restrict accessing userspace to just
the functions that explicitly handle crossing the user kernel boundary.

7 years agoMFC r316755:
andrew [Tue, 30 May 2017 11:03:05 +0000 (11:03 +0000)]
MFC r316755:

Add SCTLR bits added in ARMv8.1 and ARMv8.2 and start to use them in the
early boot code.

7 years agoMFC r312703:
andrew [Tue, 30 May 2017 10:50:15 +0000 (10:50 +0000)]
MFC r312703:

Fix the error value we write in cerror. __error returns an int *, however
we were writing a 64 bit value meaning the 32 bits after this would be
trashed.

7 years agoRegenerate src.conf(5) after MK_DIALOG was added
ngie [Tue, 30 May 2017 07:31:02 +0000 (07:31 +0000)]
Regenerate src.conf(5) after MK_DIALOG was added

7 years agoMFC r314463:
ngie [Tue, 30 May 2017 07:29:18 +0000 (07:29 +0000)]
MFC r314463:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

7 years agoMFC r306375,r307802:
ngie [Tue, 30 May 2017 07:28:27 +0000 (07:28 +0000)]
MFC r306375,r307802:

r306375 (by emaste):

Add a WITHOUT_DIALOG src.conf(5) knob

It also turns off dependencies (bsdinstall, bsdconfig, dpv, tzsetup).

r307802 (by bapt):

Fix build of tzsetup when WITHOUT_DIALOG is set

Hide dialog specific code behind HAVE_DIALOG. It allows to build a stripped
down version (missing the dialog UI) but perfectly function tzsetup when
world is built WITHOUT_DIALOG

Reorganise a bit the code to limit the number of blocks under HAVE_DIALOG

7 years agoMFC r314451,r314452,r314453,r314456,r314457,r314458,r314459,r314460,r314461,r314462...
ngie [Tue, 30 May 2017 05:15:09 +0000 (05:15 +0000)]
MFC r314451,r314452,r314453,r314456,r314457,r314458,r314459,r314460,r314461,r314462,r314464,r314466,r314468,r314470,r314472,r314478:

r314451:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

The SRCTOP conversion simplifies pathing in make/displayed output.

Also, while here, change a hardcoded path to ar5523.bin.uu in the make target
with ${.ALLSRC} .

r314452:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

r314453:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

r314456:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314457:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

The SRCTOP conversion simplifies pathing in make/displayed output.

Also, while here, change a hardcoded path to ${RPCDIR}/ypupdate_prot.x in
the make targets with ${.ALLSRC} .

r314458:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314459:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314460:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314461:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314462:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

The SRCTOP conversion simplifies pathing in make/displayed output.

Also, while here, change a hardcoded path to ${RPCDIR}/ypxfrd.x in
the make targets with ${.ALLSRC} .

r314464:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314466:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314468:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

Also, use :H where possible/sensical to manipulate .CURDIR-relative paths

This simplifies pathing in make/displayed output.

r314470:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

r314472:

Simplify/improve idioms in usr.sbin/ntp Makefiles

- Use SRCTOP-relative paths to other directories instead of
  .CURDIR-relative ones. This simplifies pathing in make/displayed output.
- Also, use :H where possible/sensical to manipulate .CURDIR-relative
  paths
- Remove superfluous bsd.own.mk .includes which are already handled via
  src.opts.mk .includes

r314478:

Simplify idioms in Makefiles further

- Use SRCTOP-relative paths instead of .CURDIR-relative ones where possible
- Use :H to manipulate .CURDIR in areas instead of ..-relative paths.

7 years agoMFC r314541:
ngie [Tue, 30 May 2017 04:45:11 +0000 (04:45 +0000)]
MFC r314541:

Use SRCTOP-relative paths to other directories instead of .CURDIR-relative ones

This simplifies pathing in make/displayed output.

7 years agoMFC r314658:
ngie [Tue, 30 May 2017 04:42:36 +0000 (04:42 +0000)]
MFC r314658:

crypto: normalize paths using SRCTOP-relative paths or :H when possible

This simplifies make logic/output

7 years agoMFC r318439:
ngie [Tue, 30 May 2017 04:36:11 +0000 (04:36 +0000)]
MFC r318439:

Normalize .PATH on SRCTOP

This will help Jenkins dedupe 9 warnings between the static build and
the module build of ipsec(4).

Missed in SRCTOP conversion in r314651.

MFC with: r314651

7 years agoMFC r307741:
ngie [Tue, 30 May 2017 04:31:35 +0000 (04:31 +0000)]
MFC r307741:
r307741 (by emaste):

Allow all subdirectories to be optional via SUBDIR.${MK_*}

Tested by: br
Pointy hat to: emaste

7 years agoMFC r315170:
ngie [Tue, 30 May 2017 04:27:05 +0000 (04:27 +0000)]
MFC r315170:
r315170 (by imp):

Adopt SRCTOP in usr.bin

Prefer ${SRCTOP}/foo over ${.CURDIR}/../../foo and ${SRCTOP}/usr.bin/foo
over ${.CURDIR}/../foo for paths in Makefiles.

Silence on: arch@ (twice)

7 years agoMFC r314655:
ngie [Tue, 30 May 2017 04:17:22 +0000 (04:17 +0000)]
MFC r314655:

bin: normalize paths using SRCTOP-relative paths or :H when possible

This simplifies make logic/output

7 years agoMFC r314655:
ngie [Tue, 30 May 2017 04:15:40 +0000 (04:15 +0000)]
MFC r314655:

bin: normalize paths using SRCTOP-relative paths or :H when possible

This simplifies make logic/output

7 years agoMFC r314657:
ngie [Tue, 30 May 2017 04:13:06 +0000 (04:13 +0000)]
MFC r314657:

kerberos5: normalize paths using SRCTOP-relative paths or :H when possible

This simplifies make logic/output

7 years agoMFC r314651,r318439,r318440:
ngie [Tue, 30 May 2017 04:11:12 +0000 (04:11 +0000)]
MFC r314651,r318439,r318440:

r314651:

sys/modules: normalize .CURDIR-relative paths to SRCTOP

This simplifies make output/logic

Tested with: `cd sys/modules; make ALL_MODULES=` on amd64

r318439:

Normalize .PATH on SRCTOP

This will help Jenkins dedupe 9 warnings between the static build and
the module build of ipsec(4).

Missed in SRCTOP conversion in r314651.

MFC with: r314651

r318440:

Normalize SYSDIR on SRCTOP instead of .CURDIR

This is being done to simplify pathing for CFLAGS and source files.

7 years agoMFC r307698:
ngie [Tue, 30 May 2017 04:00:26 +0000 (04:00 +0000)]
MFC r307698:
r307698 (by lwhsu):

- Add required header for fixing `make` in sys/modules/gpio

7 years agoMFC r308161:
ngie [Tue, 30 May 2017 03:55:38 +0000 (03:55 +0000)]
MFC r308161:
r308161 (by lwhsu):

- Fix `make` in sys/modules/bhnd

7 years agoMFC r318606:
cy [Tue, 30 May 2017 03:33:48 +0000 (03:33 +0000)]
MFC r318606:

Refactor & compact struct i6addr_t #ifdef: remove redundant structure
definintion when USE_INET6 is false.

7 years agoMFC r318588:
cy [Tue, 30 May 2017 03:30:53 +0000 (03:30 +0000)]
MFC r318588:

Fix up two assertions following malloc(). vangyzen@ notified me of
the second one. The first one is fixed as well.

Reported by: vangyzen@

7 years agoMFC r318578:
cy [Tue, 30 May 2017 03:27:59 +0000 (03:27 +0000)]
MFC r318578:

Fix non-recoverable name resolution failures due to negative cache
entries never expiring. This patch honours the negative cache timeout.

To test/experience the failure do the following:

1. Edit /etc/ncd.conf to adjust the cache timeouts as follows:

positive-time-to-live hosts 30
negative-time-to-live hosts 1

2. Ensure that nsswitch.conf hosts line contains something like:

hosts: files cache dns

Note that cache must be specified before dns.

3. Start nscd.

4. Run the following command:

while true; do nc -z -w 3 www.google.com 80; sleep 5; done

5. While running the command, remove or comment out all nameserver
   statements in /etc/resolv.conf. After a short while you will notice
   non-recoverable name rsolution failures.

6. Uncomment or replace all nameserver statements back into
   /etc/resolv.conf. Take note that name resolution never recovers.
   To recover nscd must be restarted. This patch fixes this.

PR: 207804
Submitted by: Jov <amutu@amutu.com>

7 years agoMFC r318745:
cy [Tue, 30 May 2017 03:25:05 +0000 (03:25 +0000)]
MFC r318745:

Remove redundant variable declaration.

7 years agoMFC r315368:
cy [Tue, 30 May 2017 03:22:18 +0000 (03:22 +0000)]
MFC r315368:

calloc() and realloc() modernization.

This commit replaces calloc calls, which called calloc() as if it were
malloc() by allocating a multiple of objects as a sizeof multiplied by
the number of objects. The patch rectifies this by calling calloc() as
it was meant to be called.

This commit also replaces realloc() with reallocarray() in a similar
fashion as above. Instead of calculating the memory to reallocated
(changed) by multiplying sizeof by the number of objects, the sizeof
and number are passed as separate arguments to reallocarray(), letting
reallocarray() do the multiplication instead. Like the calloc()
adjustment above, this is approach is cleaner and more elegant than
than the previous code.

This has been tested on my production firewall and a laptop (also
running ipfilter).

Submitted by: pfg

7 years agoMFC r318006:
ngie [Tue, 30 May 2017 03:10:05 +0000 (03:10 +0000)]
MFC r318006:

style(9): sort headers and remove duplicates

7 years agoMFC r312913,r318100,r318107:
ngie [Tue, 30 May 2017 03:09:01 +0000 (03:09 +0000)]
MFC r312913,r318100,r318107:

r312913 (by asomers):

Improve the aio tests

* Add tests for aio_suspend(2).
* Add tests for polled completion notification.
* Test the full matrix of file descriptor types and completion notification
  mechanisms.
* Don't bother with mkstemp, because ATF runs every test in its own temp dir.
* Fix some typos.
* Remove extraneous ATF_REQUIRE_KERNEL_MODULE calls.

r318100:

style(9): move function definition curly braces to column 0

r318107:

Remove unused constant (PATH_TEMPLATE)

It was made unnecessary in r312913.

MFC with: r312913

7 years agoMFC r318094,r318098,r318099:
ngie [Tue, 30 May 2017 03:05:22 +0000 (03:05 +0000)]
MFC r318094,r318098,r318099:

r318094:

style(9): clean up trailing whitespace

r318098:

Refactor ATF_REQUIRE_UNSAFE_AIO and PLAIN_REQUIRE_UNSAFE_AIO

This is being done to reduce duplication between the two macros.

r318099:

Print out when unsafe AIO is enabled to debugging purposes

7 years agoMFC r318007,r318008,r318009,r318011:
ngie [Tue, 30 May 2017 03:02:07 +0000 (03:02 +0000)]
MFC r318007,r318008,r318009,r318011:

r318007:

Add intermediary Makefile for compiling all items in the directory

r318008:

Only compile tests/ if MK_TESTS != no or ALL_MODULES is defined

r318009:

Add MK_TESTS to kern.opts.mk to support r31800

MFC with: r318008
Pointyhat to: ngie

r318011:

Mark this Makefile SUBDIR_PARALLEL

I inserted the necessary SUBDIR+= .WAIT in the previous commit

7 years agoMFC r319015:
ngie [Tue, 30 May 2017 02:56:17 +0000 (02:56 +0000)]
MFC r319015:

Use calloc instead of malloc + memset

7 years agoMFC r318010:
ngie [Tue, 30 May 2017 02:53:00 +0000 (02:53 +0000)]
MFC r318010:

style(9): sort headers

7 years agoMFC r318591: compress: Add basic tests.
jilles [Mon, 29 May 2017 21:48:02 +0000 (21:48 +0000)]
MFC r318591: compress: Add basic tests.

7 years agoMFC r317313:
ngie [Mon, 29 May 2017 18:19:32 +0000 (18:19 +0000)]
MFC r317313:

gctl_test.t: catch errors with the mdcfg directive

While here, add a note about certain testcases relying on `count=1024` in
the "create" portion.

7 years agoMFC r314659,r314676:
ngie [Mon, 29 May 2017 18:17:34 +0000 (18:17 +0000)]
MFC r314659,r314676:

r314659:

usr.sbin: normalize paths using SRCTOP-relative paths or :H when possible

This simplifies make logic/output

r314676:

Fix build after r314656

Some of the changes I introduced to use .ALLSRC were correct in spirit,
but incorrect in reality -- in particular, ../Makefile.inc hadn't been
pulled in via bsd.init.mk (via bsd.lib.mk, bsd.prog.mk), so the value
of .ALLSRC (evaluated immediately) was empty. .include bsd.init.mk
explicitly so we can be certain that the values used as dependencies in
the targets are defined when the target recipe has been evaluated.

Reminder: thou shalt separate out separate functional changes before
          committing them.

(YUGE) Pointyhat to: ngie
In collaboration with: bdrewery

7 years agoMFC r318788:
pfg [Mon, 29 May 2017 15:24:45 +0000 (15:24 +0000)]
MFC r318788:
bhyvegc_resize: make use of reallocarray(3) for bounds-checking.

Also add __FBSDID.

Reviewed by: grehan

7 years agoMFC r318446:
kib [Mon, 29 May 2017 13:25:55 +0000 (13:25 +0000)]
MFC r318446:
Update my copyright, note The FreeBSD Foundation involvement.

7 years agoMFC direct execution mode for rtld.
kib [Mon, 29 May 2017 13:24:27 +0000 (13:24 +0000)]
MFC direct execution mode for rtld.

MFC r318313:
Make ld-elf.so.1 directly executable.

MFC r318352 (by jonathan):
Rename rtld's parse_libdir to parse_integer.

MFC r318380:
Pretend that there is some security when executing in direct mode.

MFC r318431 (by jonathan):
Allow rtld direct-exec to take a file descriptor.

MFC r318445:
Fix style, add static keyword before static function definition.

MFC r318739:
For ld.so direct execution mode, implement -p option.

7 years agoMFC r318312:
kib [Mon, 29 May 2017 13:18:20 +0000 (13:18 +0000)]
MFC r318312:
Fix the AT_EXECFD functionality.

7 years agoMFC r318318:
kib [Mon, 29 May 2017 13:17:00 +0000 (13:17 +0000)]
MFC r318318:
Ensure that resume path on amd64 only accesses page tables for normal
operation after processor is configured to allow all required
features.

7 years agoMFC r318303:
kib [Mon, 29 May 2017 12:55:26 +0000 (12:55 +0000)]
MFC r318303:
Style.

7 years agoMFC r318299:
kib [Mon, 29 May 2017 12:53:44 +0000 (12:53 +0000)]
MFC r318299:
Simplify cleanup on failure in realpath(3).

7 years agoMFC r318298:
kib [Mon, 29 May 2017 12:52:13 +0000 (12:52 +0000)]
MFC r318298:
Fix several buffer overflows in realpath(3), and other minor issues.

PR: 219154

7 years agoMFC r318632, r318633:
royger [Mon, 29 May 2017 11:37:08 +0000 (11:37 +0000)]
MFC r318632, r318633:

bsdinstall: mount is not needed for the ZFS install case
bsdinstall: do not use distextract in scripted mode

7 years agoMFC r314659,r314676:
ngie [Mon, 29 May 2017 10:15:41 +0000 (10:15 +0000)]
MFC r314659,r314676:

r314659:

usr.sbin: normalize paths using SRCTOP-relative paths or :H when possible

This simplifies make logic/output

r314676:

Fix build after r314656

Some of the changes I introduced to use .ALLSRC were correct in spirit,
but incorrect in reality -- in particular, ../Makefile.inc hadn't been
pulled in via bsd.init.mk (via bsd.lib.mk, bsd.prog.mk), so the value
of .ALLSRC (evaluated immediately) was empty. .include bsd.init.mk
explicitly so we can be certain that the values used as dependencies in
the targets are defined when the target recipe has been evaluated.

Reminder: thou shalt separate out separate functional changes before
          committing them.

(YUGE) Pointyhat to: ngie
In collaboration with: bdrewery

7 years agoMFC r315561:
ngie [Mon, 29 May 2017 06:31:07 +0000 (06:31 +0000)]
MFC r315561:
r315561 (by trasz):

Bring back the "i".  The point is to make it easy to find via "apropos
iscsi", along with all the other relevant components.

7 years agoMFC r316179,r316180,r316181,r316260:
ngie [Mon, 29 May 2017 06:26:00 +0000 (06:26 +0000)]
MFC r316179,r316180,r316181,r316260:

r316179 (by cem):

t_msgsnd: Use msgsnd()'s msgsz argument correctly to avoid overflow

msgsnd's msgsz argument is the size of the message following the 'long'
message type.  Don't include the message type in the size of the message
when invoking msgsnd(2).

CID: 1368712

r316180 (by cem):

Follow-up to r316179: More of the same

CIDs: 1368705136870613687071368710

r316181 (by cem):

t_msgctl: Fix the same msgsnd() misuse as t_msgsnd

msgsnd(2)'s msgsz argument does not describe the full structure, only the
message component.

CIDs: 13687031368711

r316260:

Annotate all changes made in r316178-r316180 with __FreeBSD__

Restore the stock (upstream) code under an #else block, so it's easier
for me to visualize and understand the code that needs to be upstreamed.

7 years agoMFC r318315:
ngie [Mon, 29 May 2017 06:15:41 +0000 (06:15 +0000)]
MFC r318315:

lib/libc/gen/realpath_test: make check result from getcwd(3)

This is being done to avoid dereferencing a NULL pointer via strlcat,
obscuring the underlying issue with the getcwd(3) call.

7 years agoMFC r308826: zfs: fix up after the removal of PG_CACHED pages in r308691
avg [Mon, 29 May 2017 06:15:06 +0000 (06:15 +0000)]
MFC r308826: zfs: fix up after the removal of PG_CACHED pages in r308691

Now that r308691 has been MFC-ed as a part of r318716,
r308826 must be MFC-ed as well.

PR: 214629
Reported by: mshirk@daemon-security.com [head], lev [stable/11]

7 years agoMFC r318688: "struct ata_params" field "reserved206[2]" actually starts at
rpokala [Mon, 29 May 2017 05:22:34 +0000 (05:22 +0000)]
MFC r318688: "struct ata_params" field "reserved206[2]" actually starts at
offset 20*7*.

Sponsored by: Panasas

7 years agoMFC r318906:
dim [Sun, 28 May 2017 18:18:01 +0000 (18:18 +0000)]
MFC r318906:

Pull in r303257 from upstream llvm trunk (by Krzysztof Parzyszek)

  [PPC] Properly update register save area offsets

  The variables MinGPR/MinG8R were not updated properly when resetting the
  offsets, which in the included testcase lead to saving the CR register
  in the same location as R30.

  This fixes another issue reported in PR26519.

  Differential Revision: https://reviews.llvm.org/D33017

Reported by: Mark Millard
PR: 206990

7 years agoMFC r318860:
hselasky [Sun, 28 May 2017 10:43:16 +0000 (10:43 +0000)]
MFC r318860:
Declare the "snd_fxdiv_table" once. This shaves around 24Kbytes of
binary data from sound.ko and the kernel.

7 years agoMFC r315698:
ngie [Sun, 28 May 2017 06:31:52 +0000 (06:31 +0000)]
MFC r315698:

libkvm: bump WARNS to 6 after recent commits done to resolve warnings issues

Tested with: make tinderbox; clang 4.0.0 (amd64), gcc 4.2.1/6.3.0 (amd64)

7 years agoMFC r318872:
gjb [Sun, 28 May 2017 03:59:33 +0000 (03:59 +0000)]
MFC r318872:
 Enable DHCP and IPv6 autoconfig on non-cloud VM images.

PR: 203653
Sponsored by: The FreeBSD Foundation

7 years agoMFC r309412,r316109,r316132:
ngie [Sun, 28 May 2017 01:08:46 +0000 (01:08 +0000)]
MFC r309412,r316109,r316132:

r309412 (by imp):

dd is currently a bootstrap tool. It really doesn't have any business
being a bootstrap tool. However, for reproducible build output,
FreeBSD added dd status=none because it was otherwise difficult to
suppress the status information, but retain any errors that might
happen. There's no real reason that dd has to be a build tool, other
than we use status=none unconditional. Remove dd from a bootstrap tool
entirely by only using status=none when available. This may also help
efforts to build the system on non-FreeBSD hosts as well.

r316109:

Don't hardcode input files for stage 1/2 bootloaders; use .ALLSRC instead

This is a better pattern to follow when creating the bootloaders and doing
the relevant space checks to make sure that the sizes aren't exceeded (and
thus, copy-pasting is a bit less error prone).

r316132:

Parameterize out 7680 (15 * 512) as BOOT2SIZE, similar to sys/boot/i386/zfsboot/...

This is being done to make it easier to change in the future--this action might be
needed sooner rather than later because of gcc 6.3.0 bailing, stating that there
is negative free space left (deficit) in the boot2 bootloader.

7 years agoMFC r316131:
ngie [Sun, 28 May 2017 00:45:02 +0000 (00:45 +0000)]
MFC r316131:

Fix up r316081 by using nitems(cam_errbuf) instead of sizeof(cam_errbuf)

Part of my original reasoning as far as converting the snprintf
calls was to permit switching over from char[] to wchar_t[] in the
future, as well as futureproof in case cam_errbuf's size was ever
changed.

Unfortunately, my approach was bugged because it conflated the
number of items with the size of the buffer, instead of the number of
elements being a fixed size != 1 byte.

Use nitems(..) instead which counts the quantity of items of a specific
type, as opposed to an unqualified sizeof(..) (which assumes that the
number of characters is equal to the buffer size).

Noted by: cem

7 years agoMFC r317310,r317316:
ngie [Sun, 28 May 2017 00:25:41 +0000 (00:25 +0000)]
MFC r317310,r317316:

r317310:

Minor style(9) fixups

Delete trailing whitespace and sort headers.

Leave libgeom.h's placement alone, per reasoning in r317289.

r317316:

Minor style(9) fixups

Delete trailing whitespace and sort headers.

Leave libgeom.h's placement alone, per reasoning in r317289.

7 years agoMFC r314833
rgrimes [Sun, 28 May 2017 00:13:44 +0000 (00:13 +0000)]
MFC r314833
Convert absolute links to relative links.
Style.Makefile(9) has been ignored to produce minimal diffs.

MFC r314837
The relative symlink fix causes downstream issues for
EMC DELL Isilon so revert the relative symlink fix
pending a better solution.

Reported by: ngie

MFC r315091
Revert r314833 until the problem with INSTALL_RSYMLINKS can be found
as it appears to break arm release builds.

PR: 217705
Reported by: cyclaero@gmail.com

Approved by: grehan (mentor)

7 years agoMFC r317290,r317291,r317292,r317293,r317294,r317295,r317304,r317306,r317307,r317308...
ngie [Sat, 27 May 2017 23:31:51 +0000 (23:31 +0000)]
MFC r317290,r317291,r317292,r317293,r317294,r317295,r317304,r317306,r317307,r317308,r317309:

r317290:

Fix -Wimplicit-function-declaration compilation warning by moving libgeom.h
#include below the stdio.h #include.

gctl_dump(3) needs stdio.h, per reasoning noted in r317289.

PR: 218809

r317291:

Rename gctl.t to gctl_test.t and test.c to gctl_test_helper.c

This is being done to reduce ambiguity and to make the tests more portable
in the future to other locations in the source tree.

r317292:

gctl_test.t: use make to compile gctl_test_helper instead of calling cc directly

r317293:

gctl_test_helper: apply polish

- Staticize variables to fix warnings.
- Sprinkle asserts around for calls that can fail
- Apply style(9) for main(..) definition.
- ANSIify usage(..) definition.

r317294:

Bump WARNS to 6 per previous commits which fixed warnings

Tested with: clang (4.0), gcc (4.2.1, 6.3.0)

r317295:

The GPT class no longer exists; use the PART class instead

r317304:

gctl_test_helper: add diagnostic output for parse_retval(..)

This will help end-users better diagnose issues with the function.

r317306:

gctl_test.t: minor tweaks

- Declare $count with the `my` scope operator to permit `use strict`.
- Add `use strict`.
- Use `use warnings` instead of using `-w` in the shebang.
- Don't unlink $cmd when done (prevents unnecessary rebuilding).
- Improve the error message when running with insufficient permissions, e.g.,
  non-root.

r317307:

Use verb=delete not verb=remove

The `remove` verb hasn't been present in geom_part*(4) for well
over a decade, if ever. I couldn't find any references to it in
^/stable/5 at least, which is around the timeframe that this test
was written.

r317308:

gctl_test.t: more tweaks to try and update the code and get it functional (again?)

- Make the logfile for $out be built off the basename for $cmd, instead of $cmd.
  (r317292 broke this assumption).
- Rename $mntpt to $mntpt_prefix for clarity, as this variable is a prefix for
  mountpoints.
- Reindent the umount directive block while here to match the rest of the code.

r317309:

gctl_test.t: improve error reporting with mdcfg and mount directives

If the commands had failed previously, it would press on and result in a
series of cascading failures. Fail early and continue on to the next case
instead of executing additional commands after a previously failed series
of steps.

7 years agoMFC r319010:
ngie [Sat, 27 May 2017 23:24:33 +0000 (23:24 +0000)]
MFC r319010:

Fix #if conditional added in r319008

I committed an earlier version of the file by accident

This is a no-op on ^/head and ^/stable/11.

7 years agoMFC r319008:
ngie [Sat, 27 May 2017 23:20:28 +0000 (23:20 +0000)]
MFC r319008:

kvm_geterr_test: Compile out the portions that require kvm_open2(3) on
systems that lack the libcall, based on __FreeBSD_version.

kvm_open2(3) wasn't made available until r291406, which is in ^/stable/11,
but not ^/stable/10. This makes some of kvm_geterr_test available for testing
on ^/stable/10.

7 years agoMFC r316099:
ngie [Sat, 27 May 2017 23:04:40 +0000 (23:04 +0000)]
MFC r316099:

lib/libkvm: start adding basic tests for kvm(3)

- kvm_close: add a testcase to verify support for errno = EINVAL / -1
  (see D10065) when kd == NULL is provided to the libcall.
- kvm_geterr:
-- Add a negative testcase for kd == NULL returning "" (see D10022).
-- Add two positive testcases:
--- test the error case using kvm_write on a O_RDONLY descriptor.
--- test the "no error" case using kvm_read(3) and kvm_nlist(3) as
    helper routines and by injecting a bogus error message via
    _kvm_err (an internal API) _kvm_err was used as there isn't a
    formalized way to clear the error output, and because
    kvm_nlist always returns ENOENT with the NULL terminator today.
- kvm_open, kvm_open2:
-- Add some basic negative tests for kvm_open(3) and kvm_open2(3).
   Testing positive cases with a specific
   `corefile`/`execfile`/`resolver` requires more work and would require
   user intervention today in order to reliably test this out.

7 years agoMFC r318546:
ngie [Sat, 27 May 2017 22:59:23 +0000 (22:59 +0000)]
MFC r318546:

sys/fs/tmpfs/vnd_test: make md(4) allocation dynamic

The previous logic was flawed in the sense that it assumed that /dev/md3
was always available. This was a caveat I noted in r306038, that I hadn't
gotten around to solving before now.

Cache the device for the mountpoint after executing mdmfs, then use the
cached value in basic_cleanup(..) when unmounting/disconnecting the md(4)
device.

Apply sed expressions to use reuse logic in the NetBSD code that could
also be applied to FreeBSD, just with different tools.

7 years agoMFC r317288,r317289:
ngie [Sat, 27 May 2017 22:57:10 +0000 (22:57 +0000)]
MFC r317288,r317289:

r317288:

libgeom(3): apply minor polish

- Use .Dv when mentioning NULL per mdoc(7).
- Reword `g_device_path`, `g_open_by_ident`, and `g_providername`'s descriptions
  so they're less wordy.
- Fix a typo in `g_device_path` (can not -> cannot).

Tested with: igor, make manlint

r317289:

libgeom(3): note that stdio.h is required when referencing gctl_dump(3)

gctl_dump(3) is only exposed when stdio.h is #include'd first, per its
addition in r112510. The reasoning noted for the conditional "exposure"
of the function was to "limit #include pollution".

This addresses an issue I found with the documentation when looking at
bug 218809, which in turn addresses a -Wimplicit-function-declaration
compiler warning in `tools/regression/geom_gpt/test.c` (it uses
gctl_dump(3)).

7 years agoMFC r318900:
bapt [Sat, 27 May 2017 11:12:11 +0000 (11:12 +0000)]
MFC r318900:

update pci_vendors to 2017.05.25

7 years agoMFC r318820:
hselasky [Sat, 27 May 2017 08:25:08 +0000 (08:25 +0000)]
MFC r318820:
Increase the allowed maximum number of audio channels from 31 to 127
in the PCM feeder mixer. Without this change a value of 32 channels is
treated like zero, due to using a mask of 0x1f, causing a kernel
assert when trying to playback bitperfect 32-channel audio. Also
update the AWK script which is generating the division tables to
handle more than 18 channels. This commit complements r282650.

7 years agoMFC r318353:
hselasky [Sat, 27 May 2017 07:47:52 +0000 (07:47 +0000)]
MFC r318353:
Avoid use of contiguous memory allocations in busdma when possible.

This patch improves the boundary checks in busdma to allow more cases
using the regular page based kernel memory allocator. Especially in
the case of having a non-zero boundary in the parent DMA tag. For
example AMD64 based platforms set the PCI DMA tag boundary to
PCI_DMA_BOUNDARY, 4GB, which before this patch caused contiguous
memory allocations to be preferred when allocating more than PAGE_SIZE
bytes. Even if the required alignment was less than PAGE_SIZE bytes.

This patch also fixes the nsegments check for using kmem_alloc_attr()
when the maximum segment size is less than PAGE_SIZE bytes.

Updated some comments describing the code in question.

Differential Revision: https://reviews.freebsd.org/D10645
Reviewed by: kib, jhb, gallatin, scottl
Sponsored by: Mellanox Technologies

7 years agoMFC r312599 (cem): Add remaining ELF compression definitions and structs
emaste [Sat, 27 May 2017 01:35:59 +0000 (01:35 +0000)]
MFC r312599 (cem): Add remaining ELF compression definitions and structs

PR: 219417

7 years agoMFC r318794, r318795:
gjb [Sat, 27 May 2017 00:30:51 +0000 (00:30 +0000)]
MFC r318794, r318795:
 Update the "first appeared in" version in several manual pages.

Sponsored by: The FreeBSD Foundation

7 years agoMFC 317729:
n_hibma [Fri, 26 May 2017 19:19:47 +0000 (19:19 +0000)]
MFC 317729:

Silence sysctl in startup scripts.

This makes 'stop' behave consistently with 'start' in the script.
Also use $SYSCTL instead of sysctl for consistency within that script.

7 years agoMFC r314935 (thompsa):
gjb [Fri, 26 May 2017 19:02:46 +0000 (19:02 +0000)]
MFC r314935 (thompsa):
 Change ec2.conf to use the pkg tool from a chroot rather than trying
 to bootstrap it and fail from the livecd readonly filesystem.

Sponsored by: The FreeBSD Foundation

7 years agoMFC 315335,315336,315496,315497,315500,315502,315504,315509,315523,315524,
jhb [Fri, 26 May 2017 17:11:27 +0000 (17:11 +0000)]
MFC 315335,315336,315496,315497,315500,315502,315504,315509,315523,315524,
315525: Decode more system call arguments in truss.

315335:
Remove duplicate argument from linux_stat64() decoding.

315336:
Automate the handling of QUAD_ALIGN and QUAD_SLOTS.

Previously, the offset in a system call description specified the
array index of the start of a system call argument.  For most system
call arguments this was the same as the index of the argument in the
function signature.  64-bit arguments (off_t and id_t values) passed
on 32-bit platforms use two slots in the array however.  This was
handled by adding (QUAD_SLOTS - 1) to the slot indicies of any
subsequent arguments after a 64-bit argument (though written as ("{
Quad, 1 }, { Int, 1 + QUAD_SLOTS }" rather than "{ Quad, 1 }, { Int, 2
+ QUAD_SLOTS - 1 }").  If a system call contained multiple 64-bit
arguments (such as posix_fadvise()), then additional arguments would
need to use 'QUAD_SLOTS * 2' but remember to subtract 2 from the
initial number, etc.  In addition, 32-bit powerpc requires 64-bit
arguments to be 64-bit aligned, so if the effective index in the array
of a 64-bit argument is odd, it needs QUAD_ALIGN added to the current
and any subsequent slots.  However, if the effective index in the
array of a 64-bit argument was even, QUAD_ALIGN was omitted.

This approach was messy and error prone.  This commit replaces it with
automated pre-processing of the system call table to do fixups for
64-bit argument offsets.  The offset in a system call description now
indicates the index of an argument in the associated function call's
signature.  A fixup function is run against each decoded system call
description during startup on 32-bit platforms.  The fixup function
maintains an 'offset' value which holds an offset to be added to each
remaining system call argument's index.  Initially offset is 0.  When
a 64-bit system call argument is encountered, the offset is first
aligned to a 64-bit boundary (only on powerpc) and then incremented to
account for the second argument slot used by the argument.  This
modified 'offset' is then applied to any remaining arguments.  This
approach does require a few things that were not previously required:

1) Each system call description must now list arguments in ascending
   order (existing ones all do) without using duplicate slots in the
   register array.  A new assert() should catch any future
   descriptions which violate this rule.

2) A system call description is still permitted to omit arguments
   (though none currently do), but if the call accepts 64-bit
   arguments those cannot be omitted or incorrect results will be
   displated on 32-bit systems.

315496:
Decode the arguments passed to cap_fcntls_get() and cap_fcntls_limit().

315497:
Decode arguments passed to posix_fadvise().

315500:
Decode file flags passed to *chflags*().

While here, decode arguments passed to fchflags() and chflagsat().

315502:
Decode flock() operation.

315504:
Decode arguments passed to getfsstat().

Note that this does not yet decode the statfs structures returned by
getfsstat().

315509:
Decode arguments passed to kldsym() and kldunloadf().

This does not currently decode the kld_sym_lookup structure passed to
kldsym().

315523:
Add a Sizet type for 'size_t' values and use it instead of Int.

Various size_t arguments were previously decoded as Int values instead
which would have truncated values above 2^31 on 64-bit systems.

315524:
Decode arguments to madvise().

315525:
Improve decoding of last arguments to ioctl() and sendto().

Decode the last argument to ioctl() as a pointer rather than an int.
Eventually this could use 'int' for the _IOWINT() case and pointers for
all others.

The last argument to sendto() is a socklen_t value, not a pointer.

7 years agoMFC r318755: Extend libblacklist support with new action types
lidl [Fri, 26 May 2017 15:13:46 +0000 (15:13 +0000)]
MFC r318755: Extend libblacklist support with new action types

The original blacklist library supported two notification types:
 - failed auth attempt, which incremented the failed login count
   by one for the remote address
 - successful auth attempt, which reset the failed login count
   to zero for that remote address

When the failed login count reached the limit in the configuration
file, the remote address would be blocked by a packet filter.

This patch implements a new notification type, "abusive behavior",
and accepts, but does not act on an additional type, "bad username".
It is envisioned that a system administrator will configure a small
list of "known bad usernames" that should be blocked immediately.

Sponsored by: The FreeBSD Foundation

7 years agoMFC r318748:
gjb [Fri, 26 May 2017 13:06:13 +0000 (13:06 +0000)]
MFC r318748:
 Honor WITHOUT_TFTP for check-old* and delete-old* targets.

PR: 217949
Sponsored by: The FreeBSD Foundation

7 years agoMFC r318523, r318631:
royger [Fri, 26 May 2017 08:59:16 +0000 (08:59 +0000)]
MFC r318523, r318631:

xen/netfront: don't drop the ring RX lock with inconsistent ring state
xen/netfront: don't drop the RX lock in xn_rxeof

7 years agoMFC r318520:
royger [Fri, 26 May 2017 08:57:00 +0000 (08:57 +0000)]
MFC r318520:

xen/blkfront: correctly detach a disk with active users

7 years agoMFC r318516: Fix time handling in cv_timedwait_hires().
mav [Fri, 26 May 2017 00:25:08 +0000 (00:25 +0000)]
MFC r318516: Fix time handling in cv_timedwait_hires().

pthread_cond_timedwait() receives absolute time, not relative.  Passing
wrong time there caused two threads of zdb to spin in a tight loop.

7 years agoMFC r318527
truckman [Thu, 25 May 2017 22:39:48 +0000 (22:39 +0000)]
MFC r318527

Fix the queue delay estimation in PIE/FQ-PIE when the timestamp
(TS) method is used.  When packet timestamp is used, the "current_qdelay"
keeps storing the last queue delay value calculated in the dequeue
function.  Therefore, when a burst of packets arrives followed by
a pause, the "current_qdelay" will store a high value caused by the
burst and stick to that value during the pause because the queue
delay measurement is done inside the dequeue function.  This causes
the drop probability calculation function to calculate high drop
probability value instead of zero and prevents the burst allowance
mechanism from working properly.  Fix this problem by resetting
"current_qdelay" inside the drop probability calculation function
when the queue length is zero and TS option is used.

Submitted by: Rasool Al-Saadi <ralsaadi@swin.edu.au>

7 years agoMFC r318314
stevek [Thu, 25 May 2017 18:55:10 +0000 (18:55 +0000)]
MFC r318314

Add information to open(2) man page about the O_VERIFY flag.

PR: 219262
Reviewed by: bjk wblock
Approved by: sjg (mentor)
Obtained from: Juniper Networks, Inc.

7 years agoMFC r318511
truckman [Thu, 25 May 2017 17:22:13 +0000 (17:22 +0000)]
MFC r318511

The result of right shifting a negative signed value is implementation
defined.  On machines without arithmetic shift instructions, zero bits
may be shifted in from the left, giving a large positive result instead
of the desired divide-by power-of-2.  Fix this by operating on the
absolute value and compensating for the possible negation later.

Reverse the order of the underflow/overflow tests and the exponential
decay calculation to avoid the possibility of an erroneous overflow
detection if p is a sufficiently small non-negative value.  Also
check for negative values of prob before doing the exponential decay
to avoid another instance of of right shifting a negative value.

Tested by: Rasool Al-Saadi <ralsaadi@swin.edu.au>