Commit Graph

278555 Commits

Author SHA1 Message Date
Mark Johnston
bdd101c4d4 dtrace: Add a "regs" variable
This allows invop-based providers (i.e., fbt and kinst) to expose the
register file of the CPU at the point where the probe fired.  It does
not work for SDT providers because their probes are implemented as plain
function calls and so don't save registers.  It's not clear what
semantics "regs" should have for them anyway.

This is akin to "uregs", which nominally provides access to the
userspace registers.  In fact, DIF already had a DIF_VAR_REGS variable
defined, it was simply unimplemented.

Usage example: print the contents of %rdi upon each call to
amd64_syscall():

    fbt::amd64_syscall:entry {printf("%x", regs[R_RDI]);}

Note that the R_* constants are defined in /usr/lib/dtrace/regs_x86.d.
Currently there are no similar definitions for non-x86 platforms.

Reviewed by:	christos
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36799
2022-10-04 13:05:54 -04:00
Mark Johnston
cba2fa7c5b makefs: Add a cast to placate static analyzers
"prefixlen" will always be smaller than 32 but adding a cast is
harmless.

Reported by:	Coverity
2022-10-04 13:05:54 -04:00
Mark Johnston
d5dc278eec riscv: Apply 8d7ee2047c to the riscv pmap
Reviewed by:	alc
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36840
2022-10-04 13:05:54 -04:00
Mark Johnston
d7eec79b70 makefs: Plug a memory leak
nvlist_find_string() would return a copy of the found value, but callers
assumed they would have to make their own copy.  It's simpler to change
nvlist_find_string() than it is to change callers, so do that.

Reported by:	Coverity
2022-10-04 13:05:54 -04:00
Andrew Turner
47218e711e Include opt_platform.h to ensure FDT is defined
We need to include opt_platform.h as it's where FDT will be defined.

Sponsored by:	The FreeBSD Foundation
2022-10-04 17:38:56 +01:00
Andrew Turner
89a9a13c1a Remove unneeded FDT checks from phydev and regdev
They are only ever built when FDT is enabled so there is no need to
check for it in the files.

Sponsored by:	The FreeBSD Foundation
2022-10-04 17:37:37 +01:00
Andrew Turner
a0a4f5cf17 Clear the indirect flag in the GICv3 ITS driver
Summary:
The indirect flag tells the hardware to use a flat or two level table.
As we only support using the flat table ensure the flag that marks
which is in use is set correctly.

We can't rely on this being set correctly as some firmware may set the
indirect flag, e.g. booting from LinuxBoot.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36873
2022-10-04 17:14:16 +01:00
Ed Maste
9515313b26 libc: Fix size range check in setvbuf
From enh at google.com via openbsd-tech mailing list via pfg@:

The existing test is wrong for LP64, where size_t has twice as many
relevant bits as int, not just one. (Found by inspection by
rprichard.)
2022-10-04 12:03:56 -04:00
Hans Petter Selasky
89e5ef8917 Fix kernel build after 754cb545b6 .
By adding missing include file for powerpc64, QORIQ64.

Differential Revision:	https://reviews.freebsd.org/D36565
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-10-04 17:13:17 +02:00
Alexander Motin
a58536b91a pci: Disable Electromechanical Interlock.
Add sysctl/tunable to control Electromechanical Interlock support.
Disable it by default since Linux does not do it either and it seems
the number of systems having it broken is higher than having working.

This fixes NVMe backplane operation on ASUS RS500A-E11-RS12U server
with AMD EPYC 7402 CPU, where attempts to control reported interlock
for some reason end up in PCIe link loss, while interlock status does
not change (it is not really there).

MFC after:	2 weeks
2022-10-04 10:34:15 -04:00
Hans Petter Selasky
1d41a05557 Fix kernel build after fcb3f813f3 .
By adding missing ifdefs for INET and INET6 when building LINT-NOIP .

Differential Revision:	https://reviews.freebsd.org/D36731
Sponsored by:	NVIDIA Networking
2022-10-04 16:08:39 +02:00
Hans Petter Selasky
c2a808b977 Fix kernel build after fcb3f813f3 .
By adding missing ifdefs for INET6 .

Differential Revision:	https://reviews.freebsd.org/D36731
Sponsored by:	NVIDIA Networking
2022-10-04 15:55:36 +02:00
Hans Petter Selasky
9f69c0b87d Fix kernel build after fcb3f813f3 .
By updating function arguments for ipsec_kmod_ctlinput() which is used
when loading IPSEC support via kernel modules.

Differential Revision:	https://reviews.freebsd.org/D36731
Sponsored by:	NVIDIA Networking
2022-10-04 15:42:51 +02:00
Hans Petter Selasky
d97ecf714e time(3): Increase precision of time conversion functions by using gcd.
When converting times to and from units which have many leading zeros,
it pays off to compute the greatest common divisor first, and then do the
scaling product. This way all time unit conversion comes down to scaling a
signed or unsigned 64-bit value by a fraction represented by two signed
or unsigned 32-bit integers.

SBT_1S is defined as 2^32 . When scaling using powers of 10 above 1,
the gcd of SBT_1S and 10^N is always greater than or equal to 4,
when N is greater or equal to 2.

Scaling a sbt value to milliseconds is then done by multiplying by
(1000 / 8) and dividing by (2^32 / 8).

This trick allows for higher precision at very little additional CPU cost.

It shall also be noted that the Xtosbt() functions prior to this patch,
sometimes were off-by-one:

For example when converting 1 / 8 of a second to sbt as 125ms the old sbt
conversion function would compute 0x20000001 while the new function computes
0x20000000 which multiplied by 8 becomes SBT_1S, which is the correct value.

Reviewed by:	kib@
Differential Revision:	https://reviews.freebsd.org/D36857
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-10-04 13:51:06 +02:00
Hans Petter Selasky
2ae0861242 cuse(3): Cosmetic change about testing boolean values.
No functional change intended.

Differential Revision:	https://reviews.freebsd.org/D36633
Suggested by:	jrtc27@ and avg@
MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-10-04 13:51:06 +02:00
Hans Petter Selasky
1024bb2633 qdivrem: Predict division by zero as false.
Division by zero triggers an arithmetic exception and should not be very
common. Predict this.

No functional change intended.

MFC after:	1 week
Sponsored by:	NVIDIA Networking
2022-10-04 13:51:06 +02:00
Randall Stewart
cd84e78f09 tcp idle reduce does not work for a server.
TCP has an idle-reduce feature that allows a connection to reduce its
cwnd after it has been idle more than an RTT. This feature only works
for a sending side connection. It does this by at output checking the
idle time (t_rcvtime vs ticks) to see if its more than the RTO timeout.

The problem comes if you are a web server. You get a request and
then send out all the data.. then go idle. The next time you would
send is in response to a request from the peer asking for more data.
But the thing is you updated t_rcvtime when the request came in so
you never reduce.

The fix is to do the idle reduce check also on inbound.

Reviewed by: tuexen, rscheff
Sponsored by: Netflix Inc
Differential Revision: https://reviews.freebsd.org/D36721
2022-10-04 07:09:01 -04:00
Gleb Smirnoff
77198a945a tcp_timers: provide tcp_timer_drop() and tcp_timer_close()
Two functions to call tcp_drop() and tcp_close() from a callout context.
Garbage collect tcp_inpinfo_lock_del(), it has a single use now.

Differential revision:	https://reviews.freebsd.org/D36397
2022-10-03 22:21:55 -07:00
Gleb Smirnoff
775e20c159 tcp: make tcp_drop_syn_sent() static 2022-10-03 21:11:17 -07:00
Gleb Smirnoff
fcb3f813f3 netinet*: remove PRC_ constants and streamline ICMP processing
In the original design of the network stack from the protocol control
input method pr_ctlinput was used notify the protocols about two very
different kinds of events: internal system events and receival of an
ICMP messages from outside.  These events were coded with PRC_ codes.
Today these methods are removed from the protosw(9) and are isolated
to IPv4 and IPv6 stacks and are called only from icmp*_input().  The
PRC_ codes now just create a shim layer between ICMP codes and errors
or actions taken by protocols.

- Change ipproto_ctlinput_t to pass just pointer to ICMP header.  This
  allows protocols to not deduct it from the internal IP header.
- Change ip6proto_ctlinput_t to pass just struct ip6ctlparam pointer.
  It has all the information needed to the protocols.  In the structure,
  change ip6c_finaldst fields to sockaddr_in6.  The reason is that
  icmp6_input() already has this address wrapped in sockaddr, and the
  protocols want this address as sockaddr.
- For UDP tunneling control input, as well as for IPSEC control input,
  change the prototypes to accept a transparent union of either ICMP
  header pointer or struct ip6ctlparam pointer.
- In icmp_input() and icmp6_input() do only validation of ICMP header and
  count bad packets.  The translation of ICMP codes to errors/actions is
  done by protocols.
- Provide icmp_errmap() and icmp6_errmap() as substitute to inetctlerrmap,
  inet6ctlerrmap arrays.
- In protocol ctlinput methods either trust what icmp_errmap() recommend,
  or do our own logic based on the ICMP header.

Differential revision:	https://reviews.freebsd.org/D36731
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
809fef2913 netipsec: move specific ipsecmethods declarations to ipsec_support.h
where struct ipsec_methods is defined.  Not a functional change.
Allows further modification of method prototypes without breaking
compilation of other ipsec compilation units.

Differential revision:	https://reviews.freebsd.org/D36730
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
c0fc81e913 netinet*: remove dead code from TCP, UDP, SCTP control input
Now these functions are called only from icmp*_input().  The pointer
to the ICMP data is never NULL and cmd has a limited set of values.

In the past the functions were demultiplexing control messages from
ICMP layer, as well as internally generated events.  In the latter
case the the pointer to IP would be NULL.

Differential revision:	https://reviews.freebsd.org/D36729
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
7f3b00a87a netinet: filter out invalid ICMP responses in ip_icmp()
instead of doing that in every ipproto_ctlinput_t method.

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36728
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
53807a8a27 netinet*: use sparse C99 initializer for inetctlerrmap
and mark those PRC_* codes, that are used.  The rest are dead code.
This is not a functional change, but illustrative to make easier
review of following changes.
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
43d39ca7e5 netinet*: de-void control input IP protocol methods
After decoupling of protosw(9) and IP wire protocols in 78b1fc05b2 for
IPv4 we got vector ip_ctlprotox[] that is executed only and only from
icmp_input() and respectively for IPv6 we got ip6_ctlprotox[] executed
only and only from icmp6_input().  This allows to use protocol specific
argument types in these methods instead of struct sockaddr and void.

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36727
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
46ddeb6be8 netinet6: retire ip6protosw.h
The netinet/ipprotosw.h and netinet6/ip6protosw.h were KAME relics, with
the former removed in f0ffb944d2 in 2001 and the latter survived until
today.  It has been reduced down to only one useful declaration that
moves to ip6_var.h

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36726
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
0ab46f28dc tcp: remove unnecessary include of tcp6_var.h
Reviewed by:		rscheff, melifaro
Differential revision:	https://reviews.freebsd.org/D36725
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
bb77f0c204 udp: typedef udp tunneling functions to functions, not pointers
With this change one can make a forward declaration of a function
that is of UDP tunneling type.

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36724
2022-10-03 20:53:04 -07:00
Gleb Smirnoff
24b96f35b9 netinet*: move ipproto_register() and co to ip_var.h and ip6_var.h
This is a FreeBSD KPI and belongs to private header not netinet/in.h.

Reviewed by:		melifaro
Differential revision:	https://reviews.freebsd.org/D36723
2022-10-03 20:53:04 -07:00
John Baldwin
ab9293239c qsort_b_test: Only build on clang.
GCC doesn't support -fblocks.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D36809
2022-10-03 16:14:39 -07:00
John Baldwin
2fb81691b0 bhyve: Don't free an invalid pointer.
The netmap-specific data stored at be->opaque is freed by the caller
on error as part of freeing be.

Reviewed by:	markj
Reported by:	GCC -Wfree-nonheap-object
Differential Revision:	https://reviews.freebsd.org/D36828
2022-10-03 16:10:44 -07:00
John Baldwin
1187e46d1b nvmecontrol wdc: Don't pass a bogus pointer to free().
wdc_get_dui_log_size allocates a buffer and then advances the
returned pointer.  Passing this advanced pointer to free() is UB,
so save the original pointer to pass to free() instead.

Reviewed by:	imp
Reported by:	GCC 12 -Wfree-nonheap-object
Differential Revision:	https://reviews.freebsd.org/D36827
2022-10-03 16:10:44 -07:00
John Baldwin
d30a1689f5 libefivar: Fix a buffer overread.
DevPathToTextUsbWWID allocates a separate copy of the SerialNumber
string to append a null terminator if the original string is not
null terminated.  However, by using AllocateCopyPool, it tries to
copy 'Length + 1' words from the existing string containing 'Length'
characters into the target string.  Split the copy out to only
copy 'Length' characters instead.

Reviewed by:	imp, emaste
Reported by:	GCC 12 -Wstringop-overread
Differential Revision:	https://reviews.freebsd.org/D36826
2022-10-03 16:10:44 -07:00
John Baldwin
611cf39267 libfetch: Use memcpy in place of an odd strncpy.
The length passed to strncpy is the length of the source string, not
the destination buffer.  This triggers a non-fatal warning in GCC 12.
Hoewver, the code is also odd.  It is really just a memcpy of the
string without its nul terminator.  For that use case, memcpy is
clearer.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D36824
2022-10-03 16:10:43 -07:00
John Baldwin
3736b2dd32 diff: Fix a use after free as well as a memory leak in change().
When -B or -I are used, change() evaluates the lines in a hunk to
determine if it is a hunk that should be ignored.  It does this by
reading each candidate line into a mallocated buffer via preadline()
and then calling ignoreline().  Previously the buffer was freed as a
side effect of ignoreline_pattern() called from ignoreline().
However, if only -B was specified, then ignoreline_pattern() was not
called and the lines were leaked.  If both options were specified,
then ignoreline_pattern() was called before checking for a blank line
so that the second check was a use after free.

To fix, pull the free() out of ignoreline_pattern() and instead do it
up in change() so that is paired with preadline().

While here, simplify ignoreline() by checking for the -B and -I cases
individually without a separate clause for when both are set.  Also,
do the cheaper check (-B) first, and remove a false comment (this
function is only called if at least one of -I or -B are specified).

Reviewed by:	emaste
Reported by:	GCC 12 -Wuse-after-free
Differential Revision:	https://reviews.freebsd.org/D36822
2022-10-03 16:10:43 -07:00
John Baldwin
8f27c9d14a libiconv VIQR: Fix a use after free.
Use TAILQ_FOREACH_SAFE to walk to list of children mnemonics to free
them instead of TAILQ_FOREACH.

Reviewed by:	emaste
Reported by:	GCC 12 -Wuse-after-free
Differential Revision:	https://reviews.freebsd.org/D36821
2022-10-03 16:10:43 -07:00
John Baldwin
7973f26ad6 libedit: Disable -Wuse-after-free for chartype.c.
GCC 12 thinks ct_visual_string can reuse a pointer after it has been
reallocated, but in this case the warning appears false.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D36820
2022-10-03 16:10:43 -07:00
John Baldwin
996ee96597 libbegemot: Disable -Wuse-after-free.
The _xrealloc() function prints pointer values for internal assertion
failures and in one case does so after it has freed the pointer.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D36819
2022-10-03 16:10:43 -07:00
John Baldwin
e67b246734 libzpool: Disable -Wuse-after-free for dbuf.c.
The debug traces for reference counting in ZFS use the pointer of the
owning object as a "tag" for references to check that when an object
drops a reference it had actually held one.  In a couple of places ZFS
drops references after freeing the owning object.  In userland GCC
realizes this is a use after free.  However, since only the value of
the pointer is used, and it isn't indirected, the use is harmless.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D36818
2022-10-03 16:10:43 -07:00
John Baldwin
67b0751249 bsd.sys.mk: Add NO_WUSE_AFTER_FREE helper variable.
This variable expands to -Wno-use-after-free on GCC 12+.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D36817
2022-10-03 16:10:42 -07:00
John Baldwin
3b887005b4 rpc.lockd: Explicitly cast enum nlm_stats values to enum nlm4_stats.
NLM 4 status values are a superset of the older NLM protocol so these
casts are safe while pacifying -Wenum-conversion warnings from GCC.

Reviewed by:	rmacklem
Differential Revision:	https://reviews.freebsd.org/D36816
2022-10-03 16:10:42 -07:00
John Baldwin
db695788fc fortune: Unindent a debug printf in get_fort().
The debug printf is intended to execute after the loop has ended to
log the selected file.

Reviewed by:	imp, emaste
Reported by:	GCC
Differential Revision:	https://reviews.freebsd.org/D36815
2022-10-03 16:10:42 -07:00
John Baldwin
d81082a7ad nvmecontrol wdc: Remove unused but set variable.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D36812
2022-10-03 16:10:42 -07:00
John Baldwin
5e4854cbf8 rescue: Link libzutil after libzfs.
libzfs depends on symbols defined in libzutil.  For static linking
ld.bfd is less forgiving than lld, so rescue was failing to link when
using ld.bfd due to unresolved symbols from libzutil used by libzfs.

Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D36811
2022-10-03 16:10:42 -07:00
John Baldwin
c2e561a38f tail: Fix misleading indentation in ARG() macro.
Reviewed by:	imp, emaste
Reported by:	GCC
Differential Revision:	https://reviews.freebsd.org/D36810
2022-10-03 16:10:42 -07:00
John Baldwin
c3a3d1fd6c libirdma: Drop clang-specific -ferror-limit.
This could use -fmax-errors on GCC, but tweaking the error limit is
unusual in the tree anyway.  Just remove it.

Reviewed by:	erj, imp, emaste
Differential Revision:	https://reviews.freebsd.org/D36808
2022-10-03 16:10:42 -07:00
John Baldwin
c41b161812 ypldap: Fix mismatch in array bounds for ldapclient().
Reviewed by:	emaste
Reported by:	GCC -Warray-parameter
Differential Revision:	https://reviews.freebsd.org/D36807
2022-10-03 16:10:41 -07:00
John Baldwin
d74024a490 pfctl: Fix mismatch in array bounds for pfr_next_token().
Reviewed by:	kp, emaste
Differential Revision:	https://reviews.freebsd.org/D36806
2022-10-03 16:10:41 -07:00
John Baldwin
e0df0dce71 powerpc_nvram: Fix a bug in the adler32 checksum.
The Adler32 digest consists of two 16-bit words whose values are
calculated modulo 65521 (largest prime < 2^16).  To avoid two division
instructions per byte, this version copies an optimization found in
zlib which defers the modulus until close to the point that the
intermediate sums can overflow 2^32.  (zlib uses NMAX == 5552 for
this, this version uses 5000)

The bug is that in the deferred modulus case, the modulus was
only applied to the high word (and twice at that) but not to
the low word.  The fix is to apply it to both words.

Reviewed by:	jhibbits
Reported by:	Miod Vallat <miod@openbsd.org>
Differential Revision:	https://reviews.freebsd.org/D36798
2022-10-03 16:10:41 -07:00
John Baldwin
a9fca3b987 Fix various places which cast a pointer to a vm_paddr_t or vice versa.
GCC warns about the mismatched sizes on i386 where vm_paddr_t is 64
bits.

Reviewed by:	imp, markj
Differential Revision:	https://reviews.freebsd.org/D36750
2022-10-03 16:10:41 -07:00