HardenedBSD/src 47c48c3sys/netinet in_pcb.c tcp_usrreq.c, usr.sbin/bluetooth/iwmbtfw iwmbt_hw.c iwmbt_fw.c

Merge remote-tracking branch 'origin/hardened/current/master' into hardened/current/cross-dso-cfi
DeltaFile
+213-139sys/netinet/in_pcb.c
+93-151sys/netinet/tcp_usrreq.c
+47-103usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.c
+24-96sys/netinet/raw_ip.c
+105-0usr.sbin/bluetooth/iwmbtfw/iwmbt_fw.c
+50-44sys/netinet/in_pcb.h
+532-53341 files not shown
+904-87647 files

HardenedBSD/src e7398a4sys/netinet in_pcb.c tcp_usrreq.c, usr.sbin/bluetooth/iwmbtfw iwmbt_hw.c iwmbt_fw.c

Merge branch 'freebsd/current/main' into hardened/current/master
DeltaFile
+213-139sys/netinet/in_pcb.c
+93-151sys/netinet/tcp_usrreq.c
+47-103usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.c
+24-96sys/netinet/raw_ip.c
+105-0usr.sbin/bluetooth/iwmbtfw/iwmbt_fw.c
+50-44sys/netinet/in_pcb.h
+532-53341 files not shown
+904-87647 files

HardenedBSD/src dff0b5c. Makefile.inc1, release/packages generate-ucl.sh create-sets.sh

Merge branch 'freebsd/15-stable/main' into hardened/15-stable/main
DeltaFile
+33-30usr.bin/lockf/lockf.1
+19-20Makefile.inc1
+2-1usr.sbin/mfiutil/mfiutil.8
+1-1release/packages/generate-ucl.sh
+1-1release/packages/create-sets.sh
+0-2tools/build/Makefile
+56-556 files

HardenedBSD/src 151a1easys/netinet tcp_usrreq.c

tcp: fix !INVARIANTS build

Fixes:  40dbb06fa73cac37d57563c07e55efd0cabbd488
DeltaFile
+1-2sys/netinet/tcp_usrreq.c
+1-21 files

HardenedBSD/src 411c28bsys/kern subr_hash.c

hash(9): fix my stupid off-by-one

Fixes:  abf68d1cf02550c3c0341f5bb90be0d34f655a15
DeltaFile
+1-1sys/kern/subr_hash.c
+1-11 files

HardenedBSD/src 6604989lib/libsys fork.2

fork.2: note that all methods to pre-resolve symbols have consequences

Reviewed by:    imp
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D56362
DeltaFile
+2-0lib/libsys/fork.2
+2-01 files

HardenedBSD/src f286933include unistd.h

unistd.h: _Fork(2) is required by POSIX 2024

Reviewed by:    imp
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D56362
DeltaFile
+4-1include/unistd.h
+4-11 files

HardenedBSD/src 75aedactools/build Makefile

tools/build/Makefile: Always add md4.h to SYSINCS

Since libmd was added to the bootstrap, building main on stable/14
fails because of an incompatibility in its old md4.h.  Fix this by
always including md4.h in the bootstrap headers, instead of only
doing so when building on a non-FreeBSD host.

Fixes:          50de0bf50512 ("flua: Always build as a bootstrap tool")
Reported by:    olce
Reviewed by:    olce, kevans
Sponsored by:   https://www.patreon.com/bsdivy
Differential Revision:  https://reviews.freebsd.org/D56327

(cherry picked from commit 0dd9c4abf0e56b9d4f6f7204a68b1475f2bbf1fc)
DeltaFile
+0-2tools/build/Makefile
+0-21 files

HardenedBSD/src 1ff7f55. Makefile.inc1, release/packages create-sets.sh generate-ucl.sh

packages: Always use the bootstrap flua

To avoid breaking the build due to incompatible changes in flua or lua
libraries on the host, use the bootstrap flua for the package build.

MFC after:      2 weeks
Reviewed by:    kevans, emaste
Sponsored by:   https://www.patreon.com/bsdivy
Differential Revision:  https://reviews.freebsd.org/D56271

(cherry picked from commit 359d6e31afe3d28addedf9a8f550b382a5faa478)
DeltaFile
+11-10Makefile.inc1
+1-1release/packages/create-sets.sh
+1-1release/packages/generate-ucl.sh
+13-123 files

HardenedBSD/src a42f229. Makefile.inc1

flua: Always build as a bootstrap tool

We want to use flua from the source tree (not the host) during package
build, firstly to protect us from breaking changes in lua or libucl,
and secondly to allow (in future) cross-building of packages from
Linux or macOS.

Since we don't know if the user will be building packages during the
bootstrap phase, and because flua is fairly small and generally useful,
build it as a bootstrap tool unconditionally.

MFC after:      2 weeks
Reviewed by:    kevans, emaste
Sponsored by:   https://www.patreon.com/bsdivy
Differential Revision:  https://reviews.freebsd.org/D56270

(cherry picked from commit 50de0bf50512aa98d18f21ac1347941396596944)
DeltaFile
+8-10Makefile.inc1
+8-101 files

HardenedBSD/src 1ed6854usr.bin/lockf lockf.1

lockf.1: Organize and provide error numbers

Add error numbers to the exit codes so that readers can decode them
without having to use a separate utility. Organize exits by error code.
Mark up the error constants with the error constant macro, even though
this is really not very helpful because people will search for the error
code, the macro is explicitly for the constants and not the codes.

While where, align and alphabetize the options list as well, fix
misaligned padding in an example, and a one-sentance-per-line error.

MFC after:              3 days
Reported by:            Antranig Vartanian <antranigv at freebsd.am>
Differential Revision:  https://reviews.freebsd.org/D48470

(cherry picked from commit dd201e407e48ba59bdfa1f71d41acfdac1a9c562)
DeltaFile
+33-30usr.bin/lockf/lockf.1
+33-301 files

HardenedBSD/src 46bd227usr.sbin/mfiutil mfiutil.8

mfiutil.8: Fix typo - missing macro for dev node

MFC after: 3 days

(cherry picked from commit 2bcdab574598e729273f7ddc7d898ffdb43b63b9)
DeltaFile
+2-1usr.sbin/mfiutil/mfiutil.8
+2-11 files

HardenedBSD/src ece716csys/netinet raw_ip.c in_pcb.c

raw ip: move hash table manipulation to inpcb layer

The SOCK_RAW socket is a multiple receiver socket by its definition.  An
incoming packet may be copied to multiple sockets.  Thus, incoming packet
handling is expensive.  Systems with many thousands of raw sockets usually
have them connect(2)-ed to different destinations.  This allows for some
improvement of the input handling, which was introduced by 9ed324c9a588
back in 2008.  This optimization was made specifically for L2TP/PPTP VPN
concentrators based on ports/net/mpd5.

This change generalizes the idea of 9ed324c9a588, so that it potentially
can be used with IPv6 raw sockets.  This also eliminates last use of the
pcbinfo hash lock outside of in_pcb.c.

While here make a speculative design decision: put into the hash table
sockets that did only connect(2).  Previously, we were indexing only
sockets that were protocol bound, did bind(2) and did connect(2).  My
speculation is that only the remote IP provides some real entropy into the
hash and local address and proto are expected to be the same for majority

    [4 lines not shown]
DeltaFile
+23-95sys/netinet/raw_ip.c
+36-0sys/netinet/in_pcb.c
+10-0sys/netinet/in_pcb.h
+0-3sys/netinet/in_pcb_var.h
+69-984 files

HardenedBSD/src edece33sys/netinet udp_usrreq.c in_pcb.c, sys/netinet6 udp6_usrreq.c in6_pcb.c

inpcb: move local address assignment out of in_pcbdisconnect()

The logic of clearing local address at the protocol level makes sense.  It
is feature of UDP, not of any protocol, that local address is cleared on
disconnect.  This code can be tracked down to pre-FreeBSD times.

For example, for TCP we want a disconnected socket to return previously
used local address with getsockname(2).  The TCP has successfully evaded
that by not calling in_pcbdisconnect() and calling in_pcbdetach() in the
very old code and in_pcbdrop() later.   After D55661 TCP again has this
potential bug masked.  Better make it right than rely on such
unintentional evasions.

The raw IP sockets don't use in_pcbdisconnect(), but they are going to in
the near future.  If in_pcbdisconnect() clears local address for them,
that would be a larger bug than just getsockname().  A raw socket may be
bound with bind(2) and then connect(2)ed, and then disconnected, e.g.
connect(INADDR_ANY).  And when we run raw IP socket through
in_pcbdisconnect() we don't want to lose local address.

    [6 lines not shown]
DeltaFile
+3-0sys/netinet6/udp6_usrreq.c
+3-0sys/netinet/udp_usrreq.c
+0-1sys/netinet/in_pcb.c
+0-1sys/netinet6/in6_pcb.c
+6-24 files

HardenedBSD/src 1d0ea3dsys/netinet raw_ip.c

raw ip: remove extra argument to rip_dodisconnect()

No functional change.
DeltaFile
+7-7sys/netinet/raw_ip.c
+7-71 files

HardenedBSD/src acb79b5sys/netinet in_pcb.c udp_usrreq.c

udp: make in_pcbbind_setup() acquire the hash lock internally

Reviewed by:            pouria, rrs, markj
Differential Revision:  https://reviews.freebsd.org/D55973
DeltaFile
+56-43sys/netinet/in_pcb.c
+0-4sys/netinet/udp_usrreq.c
+56-472 files

HardenedBSD/src d7c4091sys/netinet6 in6_pcb.c udp6_usrreq.c

inpcb: make in6_pcbsetport() acquire the hash lock internally

Reviewed by:            pouria, rrs, markj
Differential Revision:  https://reviews.freebsd.org/D55972
DeltaFile
+18-7sys/netinet6/in6_pcb.c
+0-5sys/netinet6/udp6_usrreq.c
+18-122 files

HardenedBSD/src 2c48736sys/netinet in_pcb.c udp_usrreq.c, sys/netinet6 in6_pcb.c udp6_usrreq.c

inpcb: make in_pcbconnect() acquire the hash lock internally

Reviewed by:            pouria, rrs, markj
Differential Revision:  https://reviews.freebsd.org/D55971
DeltaFile
+12-5sys/netinet/in_pcb.c
+11-4sys/netinet6/in6_pcb.c
+0-6sys/netinet6/udp6_usrreq.c
+0-4sys/netinet/udp_usrreq.c
+0-4sys/netinet/tcp_usrreq.c
+0-4sys/netinet/tcp_syncache.c
+23-276 files

HardenedBSD/src 8b4d0besys/netinet tcp_usrreq.c in_pcb.c, sys/netinet6 in6_pcb.c udp6_usrreq.c

inpcb: make in_pcbbind() acquire the hash lock internally

Reviewed by:            markj
Differential Revision:  https://reviews.freebsd.org/D55970
DeltaFile
+11-4sys/netinet6/in6_pcb.c
+0-10sys/netinet/tcp_usrreq.c
+7-2sys/netinet/in_pcb.c
+0-6sys/netinet/udp_usrreq.c
+0-4sys/netinet6/udp6_usrreq.c
+18-265 files

HardenedBSD/src 40dbb06sys/dev/cxgbe/iw_cxgbe qp.c, sys/dev/cxgbe/nvmf nvmf_che.c

inpcb: retire INP_DROPPED and in_pcbdrop()

The inpcb flag INP_DROPPED served two purposes.

It was used by TCP and subsystems running on top of TCP as a flag that
marks a connection that is now in TCPS_CLOSED, but was in some other state
before (not a new-born connection). Create a new TCP flag TF_DISCONNECTED
for this purpose.

The in_pcbdrop() was a TCP's version of in_pcbdisconnect() that also sets
INP_DROPPED.  Use in_pcbdisconnect() instead.

Second purpose of INP_DROPPED was a negative lookup mask in
inp_smr_lock(), as SMR-protected lookup may see inpcbs that had been
removed from the hash.  We already have had INP_INHASHLIST that marks
inpcb that is in hash.  Convert it into INP_UNCONNECTED with the opposite
meaning.  This allows to combine it with INP_FREED for the negative lookup
mask.


    [7 lines not shown]
DeltaFile
+74-124sys/netinet/tcp_usrreq.c
+26-48sys/netinet/in_pcb.c
+20-51sys/kern/uipc_ktls.c
+21-23sys/dev/cxgbe/tom/t4_cpl_io.c
+11-13sys/dev/cxgbe/iw_cxgbe/qp.c
+13-10sys/dev/cxgbe/nvmf/nvmf_che.c
+165-26923 files not shown
+258-36329 files

HardenedBSD/src ce283e1sys/netinet6 ip6_output.c

netinet6: remove INP_DROPPED checks from setsockopt(2)

The INP_DROPPED is going to become an internal flag for inpcb.  As of now
it means a TCP pcb that is in TCPS_CLOSED.  There is nothing wrong with
calling setsockopt(2) on such socket, although has no practical use.

This deletes a piece of code from 56713d16a06c5 / D16201.  There is no
description of the panic fixed, but I will speculate that the panic was
about in6p->in6p_outputopts being NULL as the inpcb already went through
in_pcbfree_deferred().  This also can be related to compressed TIME-WAIT,
that is also gone now.

With current locking this shouldn't be possible.  An inpcb goes through
in_pcbfree() only with pr_detach method, which is called from sofree(),
and the latter is called on losing the very last socket reference.  So, at
the point when in_pcbfree() is called, the socket has lost its file
descriptor reference and there can not be any running setsockopt() on it.

Leave the call to ip6_pcbopt() still embraced with INP_WLOCK(), since we

    [9 lines not shown]
DeltaFile
+0-17sys/netinet6/ip6_output.c
+0-171 files

HardenedBSD/src 0ba87desys/netinet udp_usrreq.c in_pcb.c, sys/netinet6 udp6_usrreq.c in6_pcb.c

inpcb: make in_pcbdisconnect() acquire the hash lock internally

Should be no functional change.

Reviewed by:            pouria, markj
Differential Revision:  https://reviews.freebsd.org/D55968
DeltaFile
+0-12sys/netinet6/udp6_usrreq.c
+0-12sys/netinet/udp_usrreq.c
+2-1sys/netinet6/in6_pcb.c
+2-1sys/netinet/in_pcb.c
+4-264 files

HardenedBSD/src ac5b962sys/netinet in_pcb.c in_pcb.h, sys/netinet6 in6_pcb.c

inpcb: retire the inpcb global list

The iteration over all pcbs is possible without the global list. The
newborn inpcbs are put on a global list of unconnected inpcbs, then after
connect(2) or bind(2) they move to respective hash slot list.

This adds a bit of complexity to inp_next(), but the storage scheme is
actually simplified.

One potential problem before this change was that a couple of pcbs fall
into the same hash slot and are linked A->B there, but they also sit next
to each other in the global list, linked as B->A.  This can deadlock of
course.  The problem was never observed in the wild, but I was able to
instrument it with lots of effort: just few pcbs in the system, hash size
reduced down to 2 and a lot of repetitive calls into two kinds of
iterators.

However the main motivation is not the above problem, but make a step
towards splitting the big hash lock into per-slot locks.

    [2 lines not shown]
DeltaFile
+80-45sys/netinet/in_pcb.c
+32-17sys/netinet/in_pcb.h
+18-11sys/netinet/tcp_usrreq.c
+3-1sys/netinet6/in6_pcb.c
+1-1sys/netinet/in_pcb_var.h
+134-755 files

HardenedBSD/src 2cfe626sys/netinet in_pcb.h in_pcb.c

inpcb: retire the inpcbinfo list lock

With the SMR locking of inpcbs the use of this lock reduced down to the
global list and generation number.  It was used only on an inpcb creation
and destruction.  Use the inpcbinfo hash lock for this purpose.

Reviewed by:            pouria, rrs, markj
Differential Revision:  https://reviews.freebsd.org/D55966
DeltaFile
+5-23sys/netinet/in_pcb.h
+5-7sys/netinet/in_pcb.c
+2-2sys/netinet/udp_usrreq.c
+1-1sys/netinet/tcp_subr.c
+1-1sys/netinet/raw_ip.c
+14-345 files

HardenedBSD/src 2023709sys/netinet in_pcb.c, sys/netinet6 in6_pcb.c

inpcb: apply smr_advance(9)/smr_wait(9) trick only to reusable sockets

The protocols marked with PR_CONNREQUIRED can never go through pr_connect
after being disconnected.  This is a tiny improvement of fdb987bebddf0.

While here push clearing of the addresses under the same condition.
Although this clearing originates from pre-FreeBSD times, it actually
makes sense only for protocols that can reconnect.

Reviewed by:            pouria, markj
Differential Revision:  https://reviews.freebsd.org/D55661
DeltaFile
+8-7sys/netinet6/in6_pcb.c
+7-5sys/netinet/in_pcb.c
+15-122 files

HardenedBSD/src 817e699sys/dev/usb/input wsp.c

wsp(4): Make evdev interface operational if sysmouse one is not opened

Before this change evdev interface sent only copy of data sent through
the sysmouse interface. It worked as /dev/wsp0 device node was
automatcaly opened by devd(8) with starting of moused(8).
Starting with 15.0 moused(8) does not open sysmouse interface by default
thus making wsp(4) device dysfunctional.
Fix it with adding extra checks of interfaces state.

MFC after:      1 week
DeltaFile
+10-1sys/dev/usb/input/wsp.c
+10-11 files

HardenedBSD/src dc5a949sys/dev/usb/input wsp.c

wsp(4): Do not handle pressure on non-ForceTouch devices

They always report it value as zero breaking pressure-driven drivers
like moused(8) and xf86-input-synaptics.

MFC after:      1 week
DeltaFile
+4-2sys/dev/usb/input/wsp.c
+4-21 files

HardenedBSD/src 9d0404csys/dev/hid bcm5974.c

bcm5974(4): Do not handle pressure on non-ForceTouch devices

They always report it value as zero breaking pressure-driven drivers
like moused(8) and xf86-input-synaptics.

MFC after:      1 week
DeltaFile
+5-3sys/dev/hid/bcm5974.c
+5-31 files

HardenedBSD/src d6477cdsys/dev/hid bcm5974.c

bcm5974(4): Fix pre-2015 Apple touchpad support

These devices appeared to stop sending reports via mouse USB interface
after switching to RAW mode. Fix it with changing Usage of Top Level
Collection to one found in HID report descriptor of proper interface.

MFC after:      1 week
DeltaFile
+38-34sys/dev/hid/bcm5974.c
+38-341 files

HardenedBSD/src 2ba6ce5sys/dev/hid hid.h

hid: Change Usage Page names to match documentation

According to "HID Usage Tables FOR Universal Serial Bus (USB)"
Usage Page ID range 0x93-0xF1CF is "Reserved" and Usage Page ID range
0xFF00-0xFFFF is "Vendor-defined".

MFC after:      1 week
DeltaFile
+7-3sys/dev/hid/hid.h
+7-31 files